Multiple instances
1. Feature overview
You can create SDK instances with multiple APP IDs, which we call multiple instances for short. With multiple instances, you can report data to different projects.
2. Create multiple instances
To create multiple SDK instances, initialize the SDK with different APP IDs:
- Java
- Kotlin
// Initialize the SDK
TDAnalytics.init(this, TA_APP_ID, TA_SERVER_URL);
TDAnalyticsAPI.track("some_event",properties, TA_APP_ID);
TDAnalytics.init(this, ANOTHER_TA_APP_ID, TA_SERVER_URL);
TDAnalyticsAPI.track("some_event",properties, ANOTHER_TA_APP_ID);
TDAnalytics.init(this, TA_APP_ID, TA_SERVER_URL, NAME);
TDAnalyticsAPI.track("some_event",properties, NAME);
TDAnalytics.init(this, TA_APP_ID, TA_SERVER_URL)
TDAnalytics.init(this, ANOTHER_TA_APP_ID, TA_SERVER_URL)
TDAnalyticsAPI.track("some_event",properties, TA_APP_ID)
TDAnalyticsAPI.track("some_event",properties, ANOTHER_TA_APP_ID)
Note that each SDK instance must have a different APP ID, and most data is not shared between instances. For details, see Section 4, Data sharing between instances.
3. Create light instances
You can use light instances to create multiple instances under the same APPID
- Java
- Kotlin
//First, create an SDK instance
TDAnalytics.init(this, TA_APP_ID, TA_SERVER_URL);
//Call lightInstance on the instance created earlier to create a light instance
String uuid = TDAnalytics.lightInstance();
TDAnalyticsAPI.login("anotherAccount",uuid);
TDAnalyticsAPI.track("some_event",properties,uuid);
//First, create an SDK instance
TDAnalytics.init(this, TA_APP_ID, TA_SERVER_URL)
//Call lightInstance on the instance created earlier to create a light instance
val uuid = TDAnalytics.lightInstance()
TDAnalyticsAPI.login("anotherAccount", uuid)
TDAnalyticsAPI.track("some_event", properties, uuid)
A child light instance has the same APPID, data receiving URL, and some settings as its parent instance, but other information is not shared. For details, see Section 4, Data sharing between instances.
4. Data sharing between instances
Most APIs are called on instance objects, so most data and settings are not shared among instances with different APPIDs, or between a parent instance and its light instances. However, some data and settings take effect for all instances. The following describes whether each type of data and setting is shared among instances:
- Account information
- Distinct ID
#distinct_idgenerated by the system by default: shared - Distinct ID
#distinct_idset by callingidentify: not shared - Account ID
#account_idset by callinglogin: not shared
- Event tracking
trackand user property operationsuser_set,user_setOnce,user_add, anduser_delete: not shared - Super properties
setSuperPropertiesand dynamic super propertiessetDynamicSuperPropertiesTracker: not shared - Whether SDK configuration is shared among instances:
- Reporting strategy (the reporting interval and the amount of data in each batch): shared, determined by the project data of the APPID that is instantiated first
- Network conditions for uploading
setNetworkType: shared - Logging of uploaded data
EnableTrackLogging: shared
- Auto-tracked events
-
We recommend enabling auto-tracked events on only one instance
-
Auto-tracked events can be reported to multiple APP IDs
-
Whether auto-tracking settings are shared among instances:
- Set the view ID
setViewID: not shared - Custom view properties
setViewProperties, etc.: not shared - Ignore auto-tracked events on a page
ignoreAutoTrackActivity, etc.: not shared - Ignore click events of a view type
ignoreViewType: not shared - Ignore a view
ignoreView: not shared - All annotations: you can set the appId parameter to specify the instance that an annotation applies to. If you don't set it, the configuration is shared by all instances. For example:
- Set the view ID
@ThinkingDataIgnoreTrackAppViewScreen(appId = "debug-appid")
- Record event duration
timeEvent: not shared

