HomeDocumentationAPI Reference
Getting StartedAPI ReferenceBug ReportingCrash ReportingAPMHelp Center

User Attributes

Attributes are collected by default by the Instabug SDK. These attributes contain information related to the users. You can add custom attributes using these APIs. Attributes can be added, retrieved, and removed.

Adding

Attach custom attributes to your user by passing two strings to the set attribute API. Much like a dictionary or map, the two strings are the value and key of the attribute.

Retrieving

You can retrieve all attributes related to a user using the retrieve API. This API returns an NSDictionary for iOS and a HashMap for Android.

Removing

Attributes can be removed from a user by passing the key of the attribute you'd like to remove to the removal API.

Adding Attributes

Instabug.setUserAttribute("True", withKey: "Logged in")
Instabug.setUserAttribute("False", withKey: "Completed IAP")
[Instabug setUserAttribute:@"True" withKey:@"Logged in"];
[Instabug setUserAttribute:@"18" withKey:@"Age"];
Instabug.setUserAttribute("Age", "18");
Instabug.setUserAttribute("LoggedIn", "True");
Instabug.setUserAttribute("Age", "18");
Instabug.setUserAttribute("Logged", "True");
//Android only
cordova.plugins.instabug.setUserAttribute(
    'Logged_out',
  	'true',
    function () {
        console.log('Success');
    },
    function (error) {
        console.log(error);
    }
);
//iOS
Instabug.SetUserAttribute("18", "Age");
Instabug.SetUserAttribute("True", "LoggedIn");

//Android 
Instabug.SetUserAttribute("Age", "18");
Instabug.SetUserAttribute("LoggedIn", "True");
Instabug.setUserAttributeWithKey(String value, String key)

//Examples
Instabug.setUserAttributeWithKey("18", "Age");
Instabug.setUserAttributeWithKey("True", "Logged In");
Retrieving Attributes

//Retrieving
let loggedIn = Instabug.userAttribute(forKey: "Logged in")
//Retrieve all
let allUserAttributes = Instabug.userAttributes()
//Retrieve one
NSString *loggedIn = [Instabug userAttributeForKey:@"Logged in"];
//Retrieve all
NSDictionary *allUserAttributes = [Instabug userAttributes];
//Get map of user attributes
HashMap<String, String> userAttrs = Instabug.getAllUserAttributes();
// Getting attribute
Instabug.getUserAttribute("Logged in", function(attribute) {
  // `attribute` is the return value
});

// Loading all attributes
Instabug.getAllUserAttributes(function (allAttributes) {
  // `allAttributes` Object containing all keys and attributes
});
//Android only
//Get the value of a ceratin user attribute
cordova.plugins.instabug.getUserAttribute(
    'Logged_out',
    function (userAttribute) {
        console.log('Logged out: ' + userAttribute);
    },
    function (error) {
        console.log(error);
    }
);

//Get all user attributes
cordova.plugins.instabug.getAllUserAttributes(
    function (userAttributes) {
        console.log('Keys: ' + Object.keys(userAttributes));
      	console.log('Logged out: ' + userAttributes.Logged_out);
    },
    function (error) {
        console.log(error);
    }
);
//iOS
//Get all the created user attributes
Instabug.UserAttributes();
//Get the value of a ceratin user attribute
Instabug.UserAttributeForKey("Age");

//Android
//Get the value of a ceratin user attribute
String value = Instabug.GetUserAttribute("Age");
//Retrieving
Instabug.getUserAttributeForKey("Logged in");
//Retrieve all
Instabug.getUserAttributes();
Removing Attributes

Instabug.removeUserAttribute(forKey: "Logged in")
[Instabug removeUserAttributeForKey:@"Logged in"];
//remove a user attribute
Instabug.removeUserAttribute("KEY");

//remove all user attributes 
Instabug.clearAllUserAttributes();
Instabug.removeUserAttribute("Completed IAP");
//Android only
//Remove a user attribute
cordova.plugins.instabug.removeUserAttribute(
    'Logged_out',
    function () {
        console.log('Success');
    },
    function (error) {
        console.log(error);
    }
);
//iOS
//Remove a user attribute
Instabug.RemoveUserAttributeForKey("Age");

//Android
//Remove a user attribute
Instabug.RemoveUserAttribute("Age");
//Remote all user attributes 
Instabug.ClearAllUserAttributes();
Instabug.removeUserAttributeForKey("Logged In");