SolarEngine provides multiple methods for reporting user properties. You can use these methods to add or modify user properties.
It is recommended for you to select properties that change infrequently or hold significant value, for example, age, game level, location, first payment time and total payment amount. Other properties with higher change frequency can be reported and recorded through events.
User property settings can be set by calling userUpdate, userInit, userAdd, userUnset, userAppend, or userDelete.
Note:
If you want to upload a batch of user attributes, among which the existing user attributes will not update their values, and the non-existing attributes will be created and saved, you can call userInit to set them.
Sample Code
[[SolarEngineSDK sharedInstance] userInit:@{ @"name" : @"Tom", @"city" : @"Beijing", @"age" : @(18)}];
For general user attributes, you can call userUpdate to set them. The attributes uploaded in this way will overwrite the original attribute values. If the user attribute does not exist before, it will be created, and the data type will follow the value passed in.
Sample Code
[[SolarEngineSDK sharedInstance] userUpdate:@{ @"city" : @"Shenzhen" }];
// At this time, "city" equals "Shenzhen".
If you want to report a numeric attribute and accumulate its values, you can call userAdd. If the attribute has not been set, it will be assigned a value of 0 and then calculated. You can pass in a negative value, which is equivalent to a subtraction operation.
Here is the cumulative payment amount as an example:
[[SolarEngineSDK sharedInstance] userAdd:@{ @"totalRevenue" : @(30) }];
// At this time, "totalRevenue" equals 30.
[[SolarEngineSDK sharedInstance] userAdd:@{ @"totalRevenue" : @(648) }];
// At this time, "totalRevenue" equals 638.
The value called by userAdd only allows NSNumber type.
When you want to clear the user attribute values of a user, you can call userUnset to clear the specified attributes (string array). If the attribute has not been created in the array, the attribute will not be created.
Sample Code
[[SolarEngineSDK sharedInstance] userUnset:@[@"age"]];
The parameter passed in by userUnset is the attribute name of the user attribute, and the type is a string array.
You can call userAppend to append user attributes of array type. If the attribute does not exist, it will be created.
Sample Code
// Call userAppend to appends an element to the user attribute "name". If it doesn't exist, it will be created.
[[SolarEngineSDK sharedInstance] userAppend:@{ @"name" : @"sum"}];
You can call userDelete to delete users. After a user is deleted, you will no longer be able to query the user's user attributes, but the events generated by the user can still be queried.
Parameter Name | Parameter Meaning | Parameter Type | Mandatory |
---|---|---|---|
deleteType | how to delete a user | SEUserDeleteType, e.g. SEUserDeleteTypeByAccountId: Delete a user by Account Id SEUserDeleteTypeByVisitorId: Delete a user by Visitor Id | yes |
Sample Code
[[SolarEngineSDK sharedInstance] userDelete:SEUserDeleteTypeByAccountId];