目录
此内容是否有帮助?

# Multi-Instance

# 1. Introduction of Multi-instance

The Multi-Appid feature could create multiple SDK instances to perform data tracking based on their own Appid. That is, you can report data to multiple Appids.

In the iOS SDK version 2.1.0, a new Light-instance feature is added, which can support the generate of multiple sub-light instances of the same Appid. The Light-instance is consistent with the Appid of the parent instance, but the account number and other information are inconsistent.

# 2. How to Create Multiple SDK Instances

Since 1.2.0 , Multiple SDK instances can be created by uploading different APP IDs to complete SDK initialization


  // initialize SDK
  ThinkingAnalyticsSDK *instance = [ThinkingAnalyticsSDK startWithAppId:APP_ID withUrl:SERVER_URL];

  [instance track:@"event_name" properties:eventProperties];
  // [[ThinkingAnalyticsSDK sharedInstanceWithAppid:APP_ID] track:@"event_name" properties:eventProperties];

  // before 1.2.0
  // [[ThinkingAnalyticsSDK sharedInstance] track:@"event_name" properties:eventProperties];
  //ThinkingAnalyticsSDK *instance2 = [ThinkingAnalyticsSDK startWithAppId:APP_ID2 withUrl:SERVER_URL2];

It should be noted that the Appid of multiple SDK instances must be different. Most data between multiple instances is not the same. For detailed information, please refer to section "Data and Setting Sharing between Multiple Instances".

# 3. Create a Light-instance

Since 1.2.0 , You can create multiple instances under the same Appid by creating light-instance


  //create an SDK instance first
  ThinkingAnalyticsSDK *instance = [ThinkingAnalyticsSDK startWithAppId:APP_ID withUrl:SERVER_URL];

//call createLightInstance through previously-created instances to generate lightweight instances
  ThinkingAnalyticsSDK *lightInstance  = [instance createLightInstance];

  [lightInstance login:@"123ABCabc@thinkingdata.cn"];
  [lightInstance track:@"some_event" properties:eventProperties];

The Appid, receiver URL, and some settings of sub-light instances are the same as that of the parent instances, without sharing the other information. For detailed information, please refer to section 4 "Data and settings Sharing among Multiple Instances".

# 4. Data and Setting Sharing among Multiple Instances

Since most API are called by instance objects, a majority of data and settings are not shared between Multi-appid instances, Parent-instances, and Light-instances. However, some data and settings will become valid for all instances. The detailed description of whether all data and settings are shared among multiple instances is as follows

  1. Account information
  • The distinct ID #distinct_id generated by the system by default: shared
  • The distinct ID #distinct_id set by calling identify: not shared
  • The distinct ID #account_id set by calling login: not shared
  1. Event tracking track and user property track user_setuser_setOnceuser_adduser_delete : not shared
  2. Super property setSuperProperties and dynamic super property set setDynamicSuperPropertiesTracker: not shared
  3. Whether SDK configuration information is shared among multiple instances:
  • Tracking policy related (i.e. the time interval of data tracking and the volume of each batch of data): shared, decided by the project data corresponding to the first instantiated Appid
  • Upload network condition setNetworkType: shared
  • Print uploaded data Log EnableTrackLogging: shared
  1. Auto-tracking event
  • It is suggested that Auto-Tracking be enabled on only one instance
  • Support reporting auto-tracking events to multiple APP IDs
  • The setting of auto-tracking events can only be worked for a single APPID instance, please refer to Automatic Event Tracking
  1. Record event duration timeEvent: not shared