# Android SDK Multi-Instance Guide
# I. Introduction of Multi-instance Functions
In the Android SDK version 1.3.0, the new multi-APPID feature, you can create multiple SDK instances, respectively corresponding to the respective APPID data reporting, that is, you can report data to multiple APPIDs.
In the Android SDK version 2.1.0, a new lightweight instance feature is added, which can support the generation of multiple sub-lightweight instances of the same APPID. The sub-lightweight instance is consistent with the APPID of the parent instance, but the account number and other information are inconsistent.
If you upgrade the old version (before 1.3.0) SDK to a version after 1.3.0, if there is still unreported data in the local cache of the old version SDK, it will be directly reported to the first instantiated APPID. For users who use only one APPID instance, the data has no impact.
# II. How to Create Multiple SDK instances
You can create multiple SDK instances by passing in different APP IDs to complete SDK initialization:
// Initialize SDK
ThinkingAnalyticsSDK instance1 = ThinkingAnalyticsSDK.sharedInstance(this, TA_APP_ID, TA_SERVER_URL);
ThinkingAnalyticsSDK instance2 = ThinkingAnalyticsSDK.sharedInstance(this, ANOTHER_TA_APP_ID, TA_SERVER_URL);
instance1.track("some_event",properties);
instance2.track("some_event",properties);
Please note that the APP IDs of multiple SDK instances must be different, and most of the data between multiple instances is not common. For details, please refer to Section 4, 'Data and Settings Sharing between Multiple Instances'.
# III. Create A Light Instance
In the Android SDK version 2.1.0, you can create multiple instances under the same APPID by means of light instances.
//First create an SDK instance
ThinkingAnalyticsSDK instance = ThinkingAnalyticsSDK.sharedInstance(this, TA_APP_ID, TA_SERVER_URL);
//Call createLightInstance to generate a light instance from the example created earlier
ThinkingAnalyticsSDK lightInstance = instance.createLightInstance();
lightInstance.login("anotherAccount");
lightInstance.track("some_event",properties);
The APPID, reporting address and some settings of the child lightweight instance are the same as those of the parent instance, but other information is not shared. For details, please refer to Section 4, 'Data and Settings Sharing among Multiple Instances'.
# IV. Data Sharing Among Multiple Instances
Most interfaces are called by instance objects, so most data and settings are not shared between multiple APPID instances, parent instances and lightweight instances, but some data and settings will take effect for all instances. The following is a detailed description of whether all data and settings are shared among multiple instances:
- Account related information
- System default generated visitor ID
#distinct_id
: share - Call
identify
set visitor ID#distinct_id
: not shared - Call
login
setting account ID#account_id
: not shared
- Event reporting
track
and user feature reportinguser_set
,user_setOnce
,user_add
,user_delete
: not shared - Public properties
setSuperProperties
and dynamic public propertiessetDynamicSuperPropertiesTracker
: not shared - Is SDK configuration information shared across multiple instances:
- Reporting policy related (i.e. reporting interval versus volume of data per batch): shared, determined by project data corresponding to the first instantiated APPID
- Uploaded network condition
setNetworkType
: shared - Print Upload Data Log
EnableTrackLogging
: Share
- Automatic event acquisition
- It is recommended to enable automatic collection of events on only one instance
- Support reporting automatic collection events to multiple APP IDs
- Whether the related configuration of the automatic collection event is shared in multiple instances:
- Set control ID
setViewID
: not shared - Custom control properties
setViewProperties
etc: not shared - Ignore automatic collection events of a page
ignoreAutoTrackActivity
, etc - Ignore the click event of a type control
ignoreViewType
: not shared - Ignore a control
ignoreView
: not shared - All comments: You can specify the effective instance by setting the appId parameter. If not set, all instances share the configuration, such as:
- Set control ID
@ThinkingDataIgnoreTrackAppViewScreen(appId = "debug-appid")
- Logging event
timeEvent
: not shared