目录
此内容是否有帮助?

# iOS-Advanced

# 1. Managing User Identity

SDK instances would use deviceID_Installs as the default distinct ID of each user by default, which would be used as the identity identification ID of users under an unlogged-in state. It should be noted that the distinct ID would change after the user reinstalled the App or use the APP with a new device.

# 1.1. Identify

::: Tips

Generally speaking, you do not need to customize a distinct ID. Please ensure that you understand User Identification Rules (opens new window)before setting a distinct ID.

If you need to change the distinct ID, please call the api immediately after SDK is initialized. To avoid the generation of useless accounts, please do not call such a process multiple times.

:::

If your App has its own distinct ID management system for each user, you can call identify to set the distinct ID:

If you need to get the current distinct ID, please call getDistinctId:

# 1.2 Login

When the users log in, login could be called to set the account ID of the user. TE would use the account ID as the identity identification ID, and the account ID that has been set would be saved before logout is called. The previous account ID would be covered if login is called multiple times.

Login events wouldn't be uploaded in this method.

# 1.3 Logout

After the user logs out, logout could be called to eliminate the account ID. The distinct ID would be used as the identity identification ID before the next time login is called.

It is recommended that you call logout upon explicit logout event. For example, call logout when the user commits the behavior of canceling an account; do not call such a process when the App is closed.

Logout events wouldn't be uploaded in this method.

# Sending Events

After SDK is initialized, you can track user behaviour data. In general, ordinary events could meet business requirements. You can also use the first/updatable event based on your own service scenario.

# 2.1 Ordinary Events

You can call track to upload events. It is suggested that you set event properties based on the data tracking plan drafted previously. Here is an example of a user buying an item:

# 2.2 First Events

The First Event refers to events that would only be recorded once for the ID of a certain device or other dimensions. For example, under certain scenarios, you may want to record the activation event on a certain device. In this case, you can perform data tracking with the first event.

If you want to judge whether an event is the first event from other dimensions, you can define a first_check_id for the First Event:

Note: Since the server has to check whether the event is the first event, the first event will be put in storage one hour later by default.

# 2.3 Updatable Events

You can meet the requirements for event data modification under specific scenarios through updatable events. The ID of updatable events should be specified and uploaded when the objects of updatable events are created. TE would determine the data to be updated according to the event name and event ID.

# 2.4 Overwritable Events

Despite the similarity with updatable events, overwritable events would replace all historical data with the latest data. Looking from the perspective of effect, such a process is equivalent to the behavior of deleting the previous data while putting the latest data in storage. TE would determine the data to be updated according to the event name and event ID.

# 2.5 Super Properties

Super Properties refer to properties that would be uploaded by each event. Super Properties could be divided into static super properties and dynamic super propertiesbased on the update frequency. You can select different methods for super property setting according to business requirements; we recommend that you set Super Properties first before sending events. In the same event, when the keys of Super Properties, self-defined event properties, and preset properties are the same, we would assign value according to the following priority: self-defined properties>dynamic super properties>static super properties>preset properties.

# 2.5.1 Static Super Properties

Static Super Properties are properties that all events might have and would change with a low frequency, for example, the user membership class. After setting Static Super Properties through setSuperProperties, SDK would use the preset Super Properties as the event properties when tracking events.

Static Super Properties would be saved in local storage, and should not be called every time the App is closed. If such properties already exist, the reset properties would replace the original properties. If such properties do not exist, properties would be newly created. In addition to property setting, we also provide other APIs to set and manage Static Super Properties and meet general business requirements.

# 2.5.2 Dynamic Super Properties

Dynamic Super Properties that all events might have and would change with a high frequency, for example, the quantity of the gold coins the user possesses. After setting dynamic Super Properties through registerDynamicSuperProperties, SDK would get the properties during event tracking automatically, and add such properties to the event triggered.

# 2.6 Timing Events

If you need to record the duration of a certain event, you can call timeEvent . Configure the name of the event you want to record. When you upload the event, #duration would be added to your event property automatically to record the duration of the event (Unit: second). It should be noted that only one task can be timed with the same event name.

# 3. User Properties

User property setting APIs supported by TE include: user_set, user_setOnce ,user_add ,user_unset, user_delete,user_append,user_uniqAppend.

# 3.1 User_Set

You can call user_set to set general user properties. The original properties would be replaced if the properties uploaded via the API are used. The type of newly-created user properties must conform to that of the uploaded properties. User name setting is taken as the example here:

# 3.2 User_SetOnce

If the user property you want to upload only needs to be set once, you can call user_setOnce to set the property. If such property had been set before, this message would be ignored. Let's take the setting of the first payment time as an example:

# 3.3 User_Add

When you want to upload numeric attributes for cumulative operation, you can call user_add.

If the property has not been set, it would be given a value of 0 before computing. A negative value could be uploaded, which is equivalent to subtraction operation. Let's take the accumulative payment amount as an example:

The set attribute key is a string, and the Value is only allowed to be a numeric value.

# 3.4 User_Unset

When you need to clear the user properties of users, you can call user_unset to clear specific properties. user_unset would not create properties that have not been created in the cluster.

# 3.5 User_Delete

You can call user_delete to delete a user. After deleting the user, you would no longer be able to inquire about its user property, but could still get the events data triggered by the user.

# 3.6 User_Append

You can call user_append to add user properties of array type.

# 3.7 User_UniqAppend

Since the v2.8.0, you can call user_uniqAppend to add user properties of array type. You can delete duplicated user property by calling user_uniqAppend interface. If you call user_append API, duplicated user property might not be deleted.

# 4. Encryption

Since v2.8.0, The SDK supports data encryption using AES+RSA. The data encryption function requires the cooperation of the client and the server. For specific usage methods, please consult customer success manager.

NDConfig *config = [[TDConfig alloc]initWithAppid:APPID serverUrl:SERVER_URL];
//Enable the encryption function
config.enableEncrypt = YES; 
//set public key information
config.secretKey = [[TDSecretKey alloc] initWithVersion:1 publicKey:@"publicKey"];
[ThinkingAnalyticsSDK startWithConfig:config];

# 5. Enable H5 Connection

If you need to connect with the JavaScript SDK that tracks the data of H5, please call the following API when initializing WebView. For detailed information, please refer to H5 and APP SDK Connection

# 6. Other

# 6.1 Device ID

You can call getDeviceId to get the device ID:

[instance getDeviceId];

# 6.2 Default Timezone

SDK would use the local time as the event time by default. You can also assign a timezone by setting the default timezone API. In this way, the time of all events could be aligned according to the timezone set by you:

// get TDConfig instance
TDConfig *config = [[TDConfig alloc] init];
// set UTC as the default timezone
config.defaultTimeZone = [NSTimeZone timeZoneWithName:@"UTC"];
// initialize SDK
ThinkingAnalyticsSDK *instance = [ThinkingAnalyticsSDK startWithAppId:@"YOUR_APPID" withUrl:@"YOUR_SERVER_URL" withConfig:config];

The local timezone information of the device would be lost if a specific timezone is used to align event time. If you need to save the local timezone information of the device, please add relevant properties for the event.

# 6.3 Time Calibration

SDK would use local time as the event time by default. If the user modifies the device time manually, analysis would be affected. At this time, time calibration could be performed to ensure the accuracy of event time. We provide two time calibration methods: timestamp and NTP.

  • You can use the current timestamp got from the server to calibrate the time of SDK. Thereafter, all calling operations not assigned with a specific time would use the calibrated time as the occurrence time, including event data and user property setting.
  • You can also set the address of NTP server, after which SDK would try to get the current time from the uploaded NTP server address and calibrate the SDK time. If you failed to get the current return results within the default timeout interval (3s), local time would be used to track data.
  1. Using NTP service for time calibration would create some uncertainties. It is suggested that you use a time stamp for time calibration as the priority

  2. You should select your NTP server address carefully to ensure that the device of the user could get server time rapidly under sound network conditions

# 6.4 Flush

You can call the flush API to report data to TE immediately .