目录
此内容是否有帮助?

# Unity SDK User Guide

TIP

Before accessing, please read the preparation before accessing .

You can get the Unity SDK source code in GitHub (opens new window).

Unity SDK Supported Platforms: iOS、Android、Unity Editor、Windows、Mac、WebGL、Switch

Minimum compatible Unity 5.4.0 version, size about 320 KB

**The latest version is: **v2.2.5 .

**Updated: **202 2 - 0 1-1 7

Download address (opens new window)

**Unity SDK v2.0.0 has a big change from the historical version, modifying the policy of automatic collection and removing the delayed reporting logic. If you are currently using a historical version, please refer to the **historical version Unity SDK usage guide

# I. Initialize SDK

# 1.1 Integrated SDK

  1. Download the Unity SDK (opens new window)resource file and import the resource file into your project: Assets > Import Package > Custom Package, select the file you just downloaded
  2. Add ThinkingAnalytics presets and set SDK configuration

The configurations in the above figure are:

Configuration

  • **Start Manually **: Whether to turn on manual initialization. If turned on, you need to call StartThinkingAnalyticsto manually initialize the SDK; if not turned on, the SDK will be automatically initialized when the ThinkingAnalyticspreset is loaded. Refer to " Initialize TA instance manually ".
  • **Enable Log **: Whether to open the log . If so, the report will be printed to facilitate your debugging. You can also verify that events are reported correctly in Editor mode. For unqualified attributes, a warninglog will be displayed in the console.
  • **Network Type **: Set the network conditions for reporting data to the server. The default is DEFAULT. The following are all options and corresponding instructions:
    • **DEFAULT **: Reporting data in 2G, 3G, 4G, 5G and WIFI environments
    • **WIFI **: only report data in WIFI environment
    • **ALL **: Reporting data in 2G, 3G, 4G, 5G and WIFI environments

Tokens

Each Token identifies an instance. If you need to report data to multiple projects, you can click the '+' sign in the lower right corner to increase the project configuration. For multi-project precautions, please refer to the ' Multi-Project Support ' section at the end of the section. You can add multiple Token configurations with different APP IDs.

  • **APP ID **: Need to be configured, the APP_ID of your project will be given when you apply for the project, please fill in here.
  • **SERVER URL **: Need to be configured for the URL of the data receiving end:
    • If you are using Cloud as a Service, enter the following URL:
      • https://receiver.ta.thinkingdata.cn
    • If you are using the version of private deployment, enter the following URL:
      • https://Data acquisition address
  • **MODE **: SDK instance running mode, build environment must use NORMAL mode. Please refer to SDK mode for details.
  • **TimeZone **: Supported since v1.4.3, the default alignment time zone for data. If you specify an alignment time zone, the time of the data and the DateTime type in the property are aligned to the time zone you specify.

    Note: Since some devices prohibit plaintext transmission by default, it is strongly recommended that you use the receiving end address in HTTPS format.

# Manually Initialize TA Instances

  • Loaded ThinkingAnalyticspreset
// Manual Initialization(Loaded ThinkingAnalytics Preset)
ThinkingAnalyticsAPI.StartThinkingAnalytics();
  • Dynamic mount of ThinkingAnalytics APIscripts
// Manual Initialization(Dynamic mount ThinkingAnalyticsAPI Script)
gameObject.AddComponent(typeof(ThinkingAnalyticsAPI));

// Set instance parameters
string appId = "YOUR_APP_ID";
string serverUrl = "YOUR_SERVER_ID";
ThinkingAnalyticsAPI.StartThinkingAnalytics(appId, serverUrl);

// Personalize Instance Parameters
string appId = "YOUR_APP_ID";
string serverUrl = "YOUR_SERVER_ID";
ThinkingAnalyticsAPI.TAMode mode = ThinkingAnalyticsAPI.TAMode.NORMAL;
ThinkingAnalyticsAPI.TATimeZone timeZone = ThinkingAnalyticsAPI.TATimeZone.Local;
ThinkingAnalyticsAPI.Token token = new ThinkingAnalyticsAPI.Token(appId, serverUrl, mode, timeZone);
ThinkingAnalyticsAPI.StartThinkingAnalytics(token);

// Multiple Project Instance Initialization
string appId_2 = "YOUR_APP_ID_2";
string serverUrl_2 = "YOUR_SERVER_ID_2";
ThinkingAnalyticsAPI.TAMode mode_2 = ThinkingAnalyticsAPI.TAMode.NORMAL;
ThinkingAnalyticsAPI.TATimeZone timeZone_2 = ThinkingAnalyticsAPI.TATimeZone.Local;
ThinkingAnalyticsAPI.Token token_2 = new ThinkingAnalyticsAPI.Token(appId_2, serverUrl_2, mode_2, timeZone_2);

ThinkingAnalyticsAPI.Token[] tokens = new ThinkingAnalyticsAPI.Token[2];
tokens[0] = token;
tokens[1] = token_2;
ThinkingAnalyticsAPI.StartThinkingAnalytics(tokens);

# Multiple Project Support

When configuring the SDK, you can add multiple APP IDs, and then when calling the API, finally attach a parameter to specify the APP ID. Take the Identify ()interface as an example:

// Set the guest ID for the APP ID instance with the APP ID of "debug-appid"
ThinkingAnalyticsAPI.Identify("unity_debug_id", "debug-appid");

Note: Visitor IDs, account IDs, public attributes, etc. are not shared among multiple projects, and need to be set separately for each APP ID instance.

If no APP ID parameter is attached, the first APP ID instance in the list is used by default (the instance identified by default after the Token ID). You can adjust the default APP ID instance by dragging the list items to adjust the list order.

You can also call setDefaultAppidto modify your default APP ID as follows:

// Set another APP ID as the default project ID
ThinkingAnalyticsAPI.setDefaultAppid("debug-appid-2");
// Call the trace event, at which point event data will be reported by default to the <debug-appid-2>project if no specific APP ID is passed in
ThinkingAnalyticsAPI.track("test_event");

# 1.2 Use SDK

Once you've configured the SDK, you can start uploading events using the SDK, and we've provided Samples for your reference.

using ThinkingAnalytics;

// Report test event, unity_ Start is the event name
ThinkingAnalyticsAPI.Track("unity_start");

# II. Set User ID

After using the Unity SDK, the SDK will use random UUID as the guest ID of each user by default, and this ID will be used as the user's identification ID when the user is not logged in. It should be noted that the default guest ID will change when the user reinstates the game and changes the device.

# 2.1 Set Visitor ID (optional)

If your game has its own guest ID management system for each user, you can call Identifyto set the guest ID:

ThinkingAnalyticsAPI.Identify("unity_id");

If you need to get a guest ID, you can call GetDistinctIdto get:

ThinkingAnalyticsAPI.GetDistinctId();

# 2.2 Set and Clear account ID

When the user logs in, you can call Loginto set the user's account ID. After setting the account ID, the account ID will be used as the user identification ID, and the set account ID will be called LogoutIt has been retained until:

// Sett Account ID
ThinkingAnalyticsAPI.Login("unity_user");

// Clear Account ID
ThinkingAnalyticsAPI.Logout();

Note: This method does not upload user login, user login and other events.

# III. Upload Events

The ThinkingAnalytics API. Track ()allows you to report events and their properties. In general, you may need to upload a dozen to hundreds of different events. If you are using TA background for the first time, we recommend that you upload a few key events first.

We also support several automatic collection events, including game start, close, exception, installation and other events. You can choose whether to turn on automatic capture events according to your business needs.

# 3.1 Upload Events

It is recommended that you set the properties of the event and the conditions for sending information according to the previously combed doc. Event type is a stringtype that can only start with a letter and can contain numbers, letters and an underscore " _ " , up to 50 characters in length, and is not case sensitive to letters.

Dictionary<string, object> properties = new Dictionary<string, object>()
    {
        {"KEY_DateTime", DateTime.Now.AddDays(1)},
        {"KEY_STRING", "B1"},
        {"KEY_BOOL", true},
        {"KEY_NUMBER", 50.65}
    };
ThinkingAnalyticsAPI.Track("TEST_EVENT", properties);
  • The event attribute is of type Dictionary < string, object >, where each element represents an attribute;
  • Event property Keyis the property name, for the stringtype, the provisions can only start with letters, including numbers, letters and underscores " _ " , the maximum length of 50 characters, not sensitive to letter case;
  • Property values support five types: string, numeric, bool, DateTime, List ``< string >, Dictionary < string, object >, List < Dictionary < string, object >type.

    Note: List type is supported in versions after v1.4.0, and its elements will be converted to string for storage.

When you call Track (), the SDK will take the current system time as the time when the event occurred. If you need to specify the event time, you can pass in DateTimetype parameters to set the event trigger time. Since the v1.3.0 version, the SDK supports uploading the time offset of the event according to the DataTimeKind(corresponding to the preset attribute #zone_offset), but if the incoming DateTime's Kindattribute is DataTimeKind. Unspecified, the time offset will not be reported:

DateTime dateTime = DateTime.Now.AddDays(-1);
ThinkingAnalyticsAPI.Track("TEST_EVENT", properties, dateTime);

Since v1.4.3, you can configure the default time zone for an SDK instance. If you configure a non-Local time zone, all event times will be aligned to that time zone, and the Kindproperty of the DateTimeyou pass in will be ignored.

Since v2.0.0, the SDK has provided a time calibration interface that allows SDK time to be calibrated using server time. Please refer to the Calibration Time section.

Note: Although the trigger time can be set for the event, the receiving end will make the following restrictions: only the data from the first 10 days to the last 3 days of the relative server time will be received, and the data exceeding the time limit will be regarded as abnormal data, and the whole data cannot be stored.

# 3.2 Set Static Public Properties

For some important attributes, such as the player's zone suit and channel, these attributes need to be set in each event. At this time, you can set these attributes as public event attributes. The public event property refers to the property that each event will carry. You can call SetSuperPropertiesto set the public event property. We recommend that you set the public event property before sending the event.

Dictionary<string, object> superProperties = new Dictionary<string, object>()
    {
        {"SERVER", 0},
        {"CHANNEL", "A3"}
    };
ThinkingAnalyticsAPI.SetSuperProperties(superProperties);

The public event properties will be saved to the cache and need not be called every time the app is started. If you call SetSuperPropertiesto upload a previously set public event property, the previous property is overwritten. If the public event property and the Keyof a property uploaded by Track ()duplicate, the property of the event overrides the public event property.

If you need to delete a public event property, you can call UnsetSuperProperty ()to clear one of the public event properties; if you want to empty all public event properties, you can call ClearSuperProperties (); if you want to get all public event properties, you can call GetSuperProperties;

// Clear public property named CHANNEL
ThinkingAnalyticsAPI.UnsetSuperProperty("CHANNEL");

// Clear all public attributes
ThinkingAnalyticsAPI.ClearSuperProperties();

// Get all public attributes
ThinkingAnalyticsAPI.GetSuperProperties();

# 3.3 Set Dynamic Public Properties

If the value of the public property is not constant, you can do it by setting the dynamic public property. The dynamic public property is also added to all events, and the actual reported value is dynamically obtained when the event is reported.

To set dynamic public properties, you need to create a new dynamic public property class and implement the IDynamicSuperProperties interface, overwrite the public Dictionary < string, object > GetDynamicSuperProperties ()method, and the return value of this method is the dynamic public property that needs to be set. Then call SetDynamicSuperPropertiesto pass in the dynamic public property object, the sample is as follows:

using ThinkingAnalytics;

// Define the implementation of dynamic common attributes, for example, to set dynamic common attributes for UTC time
public class DynamicProp : IDynamicSuperProperties
{
    public Dictionary<string, object> GetDynamicSuperProperties()
    {
        return new Dictionary<string, object>() {
            {"KEY_UTCTime", DateTime.UtcNow}
        };
    }
}

ThinkingAnalyticsAPI.SetDynamicSuperProperties(new DynamicProp());

Note: If the event property has a duplicate name, the dynamic public property has a higher priority than the public event property and is less than the event property set in Track.

# 3.4 Time to Record Events

If you need to record the duration of an event, you can call TimeEvent ()to start timing, configure the event type you want to time, and when you upload the event, you will automatically add #durationto your event attribute to indicate the duration of the recording, in seconds.

// Call TimeEvent to open for TIME_ Timing of EVENT events
ThinkingAnalyticsAPI.TimeEvent("TIME_EVENT");

// do some thing...

// Upload TIME_via Track When an EVENT event occurs, the #duration attribute is added to the attribute
ThinkingAnalyticsAPI.Track("TIME_EVENT");

# IV. User Attributes

TA platform currently supports the user feature setting interface for UserSet, UserSetOnce, UserAdd, UserUnset, UserDelete, UserAppend.

# 4.1 UserSet

For general user features, you can call the UserSetto set it. Attributes uploaded using this interface will overwrite the original attribute values. If the user feature does not exist before, the user feature will be created.

ThinkingAnalyticsAPI.UserSet(new Dictionary<string, object>()
    {
        {"USER_PROP_NUM", 0},
        {"USER_PROP_STRING", "A3"}
    });

Similar to event properties:

  • The user feature is a Dictionary < string, object >type, where each element represents an attribute;
  • User feature Keyis the attribute name, for the stringtype, the provisions can only start with letters, including numbers, letters and underscore "_", the maximum length of 50 characters, not sensitive to letter case;
  • User feature values support four types: string, numeric class, bool, DateTime, and List.

    Note: List type is supported in versions after v1.4.0, and its elements will be converted to string for storage.

# 4.2 UserSetOnce

If the user feature you want to upload only needs to be set once, you can call UserSetOnceto set it. When the attribute already has a value before, this information will be ignored:

ThinkingAnalyticsAPI.UserSetOnce(new Dictionary<string, object>()
    {
        {"USER_PROP_NUM", -50},
        {"USER_PROP_STRING", "A3"}
    });

Note: The user feature type and restrictions set by UserSetOnce are consistent with UserSet.

# 4.3 UserAdd

When you want to upload a numeric attribute, you can call UserAddto accumulate the attribute. If the attribute has not been set, it will be assigned a value of 0and then evaluated. Negative values can be passed in, which is equivalent to subtraction operations.

ThinkingAnalyticsAPI.UserAdd(new Dictionary<string, object>()
    {
        {"USER_PROP_NUM", -100.9},
        {"USER_PROP_NUM2", 10.0}
    });

Note: The restrictions on attribute types and key values in UserAdd are consistent with UserSet, but Value only allows numeric type attributes to be reported.

# 4.4 UserUnset

If you need to reset a user attribute, you can call UserUnsetto empty the value of the user feature specified by the user. This interface supports passing in parameters of string or list type:

// Delete individual user attributes
ThinkingAnalyticsAPI.UserUnset("userPropertyName");

// Delete multiple user attributes
List<string> listProps = new List<string>();
listProps.Add("aaa");
listProps.Add("bbb");
listProps.Add("ccc");

ThinkingAnalyticsAPI.UserUnset(listProps);

# 4.5 UserDelete

If you want to delete a user, you can call UserDeleteto delete the user. You will no longer be able to query the user features of the user, but the events generated by the user can still be queried.

ThinkingAnalyticsAPI.UserDelete();

# 4.6 UserAppend

Starting with v1.4.0, you can call UserAppendto append elements to a user feature of type List:

List<string> stringList = new List<string>();
stringList.Add("apple");
stringList.Add("ball");
stringList.Add("cat");

// Name property USER_ LIST adds 3 elements to its user attributes
ThinkingAnalyticsAPI.UserAppend(new Dictionary<string, object>
    {
        {"USER_LIST", stringList }
    });

# V. Automatic Acquisition Events

# 5.1 Start the Collection of Automatic Collection Events

Since v2.0.0, you can turn on auto-capture for specified events by calling the EnableAutoTrackincoming AUTO_TRACK_EVENTS.

// Automatic Acquisition Event Type
[Flags]
public enum AUTO_TRACK_EVENTS
{
    NONE = 0,
    APP_START = 1 << 0,
    APP_END = 1 << 1,
    APP_CRASH = 1 << 4,
    APP_INSTALL = 1 << 5,
    ALL = APP_START | APP_END | APP_INSTALL | APP_CRASH
}

The description of the automatic acquisition event is as follows:

  • APP_START: When the game enters the foreground, it will trigger the report ta_app_start, the preset attribute #resume_from_backgroundindicates whether this startup is a reboot.
  • APP_END: When the game enters the background, it will trigger the report ta_app_end, the preset attribute #durationfield indicates the duration of the game in the foreground, in seconds.
  • APP_CRASH: When there is an uncaught exception, it will trigger the report ta_app_crash. Currently, the Android platform will handle the uncaught exception of the virtual machine. iOS platform handles Unix signal exceptions and NSException exceptions.
  • APP_INSTALL: Trigger report when the application is opened after the first installation ta_app_install. It does not distinguish whether it is uninstallation and reinstallation. This time will only be reported once after installation, and subsequent updates will not be reported again.

You can turn on all currently supported autocapture events by passing in AUTO_TRACK_EVENTS. ALL, or you can turn on some autocapture events according to the needs of your project.

// Turn on all automatic acquisition events
ThinkingAnalyticsAPI.EnableAutoTrack(AUTO_TRACK_EVENTS.ALL);

// Automatic collection of start-up and close events
ThinkingAnalyticsAPI.EnableAutoTrack(AUTO_TRACK_EVENTS.APP_START | AUTO_TRACK_EVENTS.APP_END);

Note: If you need to set custom guest IDs, or public event properties, you need to do so before turning on AutoCollect events. Dynamic public properties are not currently supported for AutoCollect events.

# 5.2 Set Custom Properties for Automatic Acquisition Events

Since v2.2.4, you can call EnableAutoTrackto enable automatic collection and pass in custom attributes that need to be collected.

// Turn on automatic collection event and set self-defined attributes
ThinkingAnalyticsAPI.EnableAutoTrack(AUTO_TRACK_EVENTS.ALL, new Dictionary<string, object>() {
    {"custom_key", "custom_value"}
});

You can also call SetAutoTrackPropertiesto specify custom properties for a specific autocapture event.

Note: SetAutoTrackPropertieswill not open the collection of automatic collection events, which needs to be used with the EnableAutoTrackmethod.

// Settings refer to custom attributes for a single automatic acquisition event
ThinkingAnalyticsAPI.SetAutoTrackProperties(AUTO_TRACK_EVENTS.APP_START, new Dictionary<string, object>()
{
    {"start_key", "start_value"}
});

// Settings refer to custom attributes for multiple automatic acquisition events
ThinkingAnalyticsAPI.SetAutoTrackProperties(AUTO_TRACK_EVENTS.APP_INSTALL | AUTO_TRACK_EVENTS.APP_CRASH, new Dictionary<string, object>()
{
    {"install_crash_key", "install_crash_value"}
});

// Turn on all automatic acquisition events
ThinkingAnalyticsAPI.EnableAutoTrack(AUTO_TRACK_EVENTS.ALL);

# VI. Other Configuration Options

# 6.1 Get the Device ID

After the SDK is initialized, the device ID will be automatically generated and recorded in the local cache. For the same application/game, the device ID of a device is unchanged. You can call GetDeviceId ()to obtain the device ID:

ThinkingAnalyticsAPI.GetDeviceId();

// Use Device ID as Visitor ID
// ThinkingAnalyticsAPI.Identify(ThinkingAnalyticsAPI.GetDeviceId());

# 6.2 Pause/stop data reporting

In v2.1.0 version, the function of stopping SDK reporting data has been added. There are two types of interfaces to stop SDK reporting:

  1. Suspend SDK reporting (EnableTracking)

You may want to temporarily stop SDK data collection and reporting in some scenarios, such as the user is in a test environment, or the user logged in to a test account. At this time, you can call the following interfaces to temporarily stop SDK reporting.

You can call EnableTrackingthrough an instance (including the main instance and the light instance), pass in falseto suspend the reporting of the SDK, and the #distinct_id, #account_id, public attributes already set by the instance will be retained; the data that has been collected but has not been successfully reported by the instance will continue to try to report; the subsequent instance cannot collect and report any new data, and cannot set visitor ID, account ID, and public attributes, etc., but can read the public attributes and Device ID, guest ID, account ID and other information.

The stop state of the instance will be saved in the local cache until EnableTrackingis called and trueis passed in. The SDK instance will resume data collection and reporting. It should be noted that the light instance is not cached, so every time you open the APP, The paused state of the light instance will not be retained, and the reporting will be reopened.

// Pause reporting of default instances, cached data and information that has been set are not cleared
ThinkingAnalyticsAPI.EnableTracking(false);

// Restore reporting of default instances
ThinkingAnalyticsAPI.EnableTracking(true);
  1. Stop SDK reporting (OptOutTracking)

In some special situations, you may need to completely stop the functions of the SDK. For example, in areas where GDPR is applicable, users choose not to provide data collection permissions, you can call the following interface to completely turn off the functions of the SDK.

OptOutTrackingcan only be called through the primary instance, and the biggest difference with EnableTrackingis that it will empty the local cache of this instance, including the guest ID, account ID, public attributes, and unreported data queues of this instance. Then turn off the collection and reporting functions of this instance.

// Stop reporting default instances and empty local caches
ThinkingAnalyticsAPI.OptOutTracking();

If you want to delete the user's user data in the TA cluster while turning off the SDK function, you can call OptOutTrackingAndDeleteUser, which will report a piece of UserDeletedata before stopping the function of the SDK instance to delete the user's user data.

// Stop reporting the default instance and send user_ Del
ThinkingAnalyticsAPI.OptOutTrackingAndDeleteUser();

The stopped state of the instance will also be saved in the local cache until OptInTrackingis called, and subsequent reports can continue, but this is equivalent to a completely new instance

// Re-start reporting
ThinkingAnalyticsAPI.OptInTracking();

# 6.3 Creating Light Instances

You can create multiple instances under the same APP ID by light instances

// Create a light instance and return the token of the light instance (similar to APP ID)
string lightToken = ThinkingAnalyticsAPI.CreateLightInstance();

// Set Account ID for Light Instance
ThinkingAnalyticsAPI.Login("anotherAccount", lightToken);

// Report Events via Light Instance
ThinkingAnalyticsAPI.Track("TEST_EVENT", lightToken);

Note: The APP ID, reporting address and some settings of the child lightweight instance are consistent with the parent instance, but other information is not shared

# 6.4 SDK Operation Mode

Since v1.4.0, the SDK supports running in three modes:

  • NORMAL: Normal mode, data will be stored in the cache and reported according to a certain cache policy
  • DEBUG: Debug mode, data is reported one by one. When problems occur, users will be prompted with logs and exceptions
  • DEBUG_ONLY: Debug Only mode, only check the data, not into the library

    Note: DEBUG mode is only used for integration phase data validation and should not be used in production mode.

In order to prevent Debug mode from going live in the production environment, it is stipulated that only specified devices can turn on Debug mode. Debug mode can only be enabled on the client side, and the device ID is configured in the 'Debug Data' section of the 'event tracking management' page in the TA background.

The device ID can be obtained in three ways:

  • #device_id attribute in event data in TA platform
  • Client side log: The device DeviceId is printed after the SDK initialization is completed
  • Called through the instance interface: get device ID

# 6.5 Calibration Time

The SDK will use the native time as the event occurrence time by default. If the user manually modifies the device time, it will affect your business analysis. Starting from version v2.0.0, you can use the current timestamp obtained from the server level to calibrate the SDK's time. After that, all calls that do not specify a time, including event data and user feature setting operations, use the calibrated time as the time of occurrence.

// 1585633785954 is the current UNIX time stamp in milliseconds corresponding to Beijing Time 2020-03-31 13:49:45
ThinkingAnalyticsAPI.calibrateTime(1585633785954);

We also provide the ability to get time-to-SDK calibration from NTP. You need to pass in an NTP server address that your users can access. The SDK then attempts to obtain the current time from the incoming NTP service address and calibrate the SDK time. If the correct return result is not obtained within the default timeout time (3 seconds), the data will be reported using the local time later.

// Time Calibration Using Apple NTP Service
ThinkingAnalyticsAPI.calibrateTimeWithNtp("time.apple.com");

Note:

  • You need to choose your NTP server address carefully to ensure that when the network is in good condition, the user equipment can get the server time quickly.
  • There is some uncertainty in using the NTP service for time calibration. It is recommended that you give priority to using timestamp calibration.

In addition to the above calibration time interface, v2.0.0 provides time function overloading for all user feature interfaces. When you call the user feature related interface, you pass in the DateTime object, and the system will use the incoming DateTime object to set the data #timefield.

# VII. Relevant Preset Attributes

# 7.1 Get Preset Properties

V2.2.0 and later can call the ThinkingAnalytics API. GetPresetProperties ()method to obtain preset properties.

When server level event tracking requires some preset properties of the App side, you can obtain the preset properties of the App side through this method and then pass them to the server level.

//Get Attribute Object
TDPresetProperties presetProperties = ThinkingAnalyticsAPI.GetPresetProperties();

//Generate event preset properties
Dictionary<string, object> eventPresetProperties = presetProperties.ToEventPresetProperties();
/*
   {
	"#carrier": "China Telecom",
	"#os": "iOS",
	"#device_id": "A8B1C00B-A6AC-4856-8538-0FBC642C1BAD",
	"#screen_height": 2264,
	"#bundle_id": "com.sw.thinkingdatademo",
 	"#app_version": "0.1",
	"#manufacturer": "Apple",
	"#device_model": "iPhone7",
	"#screen_width": 1080,
	"#system_language": "zh",
	"#os_version": "10",
	"#network_type": "WIFI",
	"#zone_offset": 8
    }
*/


//Get a preset property
string bundleId = presetProperties.BundleId;//Name
string appVersion = presetProperties.AppVersion;//App Version Number
string os = presetProperties.OS;//OS types, such as Android, iOS
string systemLanguage = presetProperties.SystemLanguage;//Cell phone system language type
int screenWidth = presetProperties.ScreenWidth;//Screen width
int screenHeight = presetProperties.ScreenHeight;//Screen height
string deviceModel = presetProperties.DeviceModel;//Device Model
string deviceId = presetProperties.DeviceId;//Unique Identification of Device
string carrier = presetProperties.Carrier;//Mobile SIM Card Operator Information, Dual Card Dual Standby, Master Card Operator Information
string manufacture = presetProperties.Manufacturer;//Mobile phone manufacturers such as Huawei and Apple
string networkType = presetProperties.NetworkType;//Network Type
string osVersion = presetProperties.OSVersion;//System Version Number
double zoneOffset = presetProperties.ZoneOffset;//Time zone offset value

IP, country and city information are generated by server level resolution, and the client side does not provide an interface to obtain these attributes

# VIII. Advanced Functions

Starting with v2.1.0, the Unity SDK supports the reporting of three special types of events: first-time events, updatable events, and rewritable events. These three events need to be used in conjunction with TA system 2.8 and later versions. Since special events are only applicable in certain specific scenarios, please use special events to report data with the help of Count Technology's customer success and analysts.

# 8.1 First Incident

First-time events are events that are recorded only once for a device or another dimension ID. For example, in some scenarios, you may want to record the first event on a device, you can use first-time events to report data.

// Instance:Report device first event, assuming event name is DEVICE_ FIRST
Dictionary<string, object> properties = new Dictionary<string, object>()
{
    {"KEY_STRING", "B1"},
    {"KEY_BOOL", true},
    {"KEY_NUMBER", 50.65},
};

ThinkingAnalyticsAPI.Track(new TDFirstEvent("DEVICE_FIRST", properties));

If you want to determine whether it is the first time in a dimension other than the device, you can set FIRST_CHECK_ID for the first event. For example, if you need to record the first event of an account, you can set the account ID to the FIRST_CHECK_ID of the first event:

// Instance: First event to report a user account, assuming the event name is USER_ FIRST
TDFirstEvent firstEvent = new TDFirstEvent("USER_FIRST", properties);
firstEvent.SetFirstCheckId("YOUR_ACCOUNT_ID");

ThinkingAnalyticsAPI.Track(firstEvent);

Note: Due to the completion of the verification of whether it is the first time at the server level, the first event will be delayed by 1 hour by default.

# 8.2 Updatable Events

You can implement the need to modify event data in a specific scenario through updatable events. Updatable events need to specify an ID that identifies the event and pass it in when you create an updatable event object. The TA background will determine the data that needs to be updated based on the event name and event ID.

// Instance: Report an event that can be updated, assuming the event name is UPDATABLE_ EVENT
TDUpdatableEvent updatableEvent = new TDUpdatableEvent("UPDATABLE_EVENT", new Dictionary<string, object>{
    {"status", 3},
    {"price", 100}
}, "test_event_id");

// Event attributes after reporting are status 3 and price 100
ThinkingAnalyticsAPI.Track(updatableEvent);


TDUpdatableEvent updatableEvent_new = new TDUpdatableEvent("UPDATABLE_EVENT", new Dictionary<string, object>{
    {"status", 5}
}, "test_event_id");

// Event attributes status is updated to 5 after reporting, price remains unchanged
ThinkingAnalyticsAPI.Track(updatableEvent_new);

Updatable events will update the event time of historical data by default using the current time of the device. If you want to specify the event time, you can specify the event time when reporting the updatable event:

TDUpdatableEvent updatableEvent = new TDUpdatableEvent("UPDATABLE_EVENT", properties_new, "test_event_id");

// Specify event time for updatable events
updatableEvent.EventTime = DateTime.Now;

# 8.3 Rewritable Events

Rewritable events are similar to updatable events, except that rewritable events will completely cover historical data with the latest data, which is equivalent to deleting the previous data and storing the latest data in effect. The TA background will determine the data that needs to be updated based on the event name and event ID.

// Instance: Report an event that can be overridden, assuming the event name is OVERWRITABLE_ EVENT
TDOverWritableEvent overWritableEvent = new TDOverWritableEvent("OVERWRITABLE_EVENT", new Dictionary<string, object>{
    {"status", 3},
    {"price", 100}
}, "test_event_id");

// Event attributes after reporting are status 3 and price 100
ThinkingAnalyticsAPI.Track(overWritableEvent);

TDOverWritableEvent overWritableEvent_new = new TDOverWritableEvent("OVERWRITABLE_EVENT", new Dictionary<string, object>{
    {"status", 5}
}, "test_event_id");

// Event attributes status is updated to 5 and price attributes are deleted after reporting
ThinkingAnalyticsAPI.Track(overWritableEvent_new);

Rewritable events will rewrite the event time of historical data by default using the current time of the device. If you want to specify the event time, you can specify the event time when reporting the rewritable event:

TDOverWritableEvent overWritableEvent = new TDOverWritableEvent("OVERWRITABLE_EVENT", new Dictionary<string, object>{
    {"status", 3},
    {"price", 100}
}, "test_event_id");

// Specifies the event time for a rewritable event
overWritableEvent.EventTime = DateTime.Now;

# Release Note

# v2.2.5 2022/01/17

  • Add preset properties #app_version
  • Supports platforms such as Switch, and releases restrictions on supported platforms
  • Simplify the initialization process and let go of the limitations of the Unity preset
  • Optimize code

# v2.2.4 2021/11/15

  • Support complex data type transfer
  • Automatic collection of events supports custom properties
  • Support WebGL
  • Optimize code

    Note: If you upgrade from a lower version to v2.2.4, or manually initialize and do not load the ThinkingAnalyticspreset body, note that there are two scripts to mount on the GameObject: ThinkingAnalytics APIand ThinkingSDKTask.

# v2.2.2 2021/09/15

  • Support manual initialization
  • Support event blacklist
  • Optimize code

# v2.2.1 2021/07/21

  • Optimize code

# v2.2.0 2021/06/16

  • Support preset attribute acquisition
  • Added C #anomaly collection
  • Compatible with Bitcode
  • Optimize support for lower version Unity
  • 更新 Android SDK (v2.7.0)、iOS SDK (v2.7.0)
  • Code optimization

# v2.1.5 2021/04/19

  • Compatible with lower version .net
  • Code optimization

# v2.1.4 2021/03/15

  • Adaptation iOS 14
  • Adapt to Android 11
  • Added preset property #bundle_id (apply unique identification)
  • Optimizing network signal acquisition logic

# v2.1.3 2021/01/04

  • Support data reporting in UnityEditor
  • Support PC games (Windows, MacOS)
  • Multi-instance scenario, support code setting default instance

# v2.1.2 2020/10/29

  • Adapt iOS 5G network
  • Optimize install, start event reporting logic
  • Optimized data transfer format
  • Default network reporting policy adjusted to 2G/3G/4G/5G/WIFI

# v2.1.1 2020/08/25

  • Fix an issue where special events do not set timeZone, resulting in an incorrect #zone_offset.

# v2.1.0 2020/08/24

  • Supports first-time events, allowing custom ID checks to be passed in to verify whether it is reported for the first time
  • Supports updatable, rewritable events
  • Optimize the #lib/#lib_version field for Unity SDK information
  • Upgrade native SDK version to v2.6.0

# v2.0.8 2020/06/28

  • Update native Android SDK to avoid null pointer exceptions in extreme cases

# v2.0.7 2020/06/23

  • Added preset property #system_language
  • Update native SDK version number: Android v2.5.5, iOS v2.5.5
  • Android no longer introduces ThinkingAnalytics SDK dependencies by modifying gradle configuration

# v2.0.6 2020/06/17

  • Solve the problem of long overflow iOS 32-bit models

# v2.0.5 2020/05/19

  • Fix the problem that the 2018.04 version cannot use the ntp calibration time

# v2.0.4 2020/05/15

  • Update the native iOS SDK to v2.5.2 to solve the Debug mode problem in the previous version

# v2.0.3 2020/05/14

  • Update the native SDK version to adapt TA background event tracking management functions
  • Optimize code to avoid exceptions (which may cause conflicts with other crash collection SDKs)

# v2.0.2 2020/04/17

  • Fix double type formatting error in custom CultureInfo scenario

# v2.0.1 2020/04/14

  • Fix the bug of reporting events in DEBUG mode on Android platform

# v2.0.0 2020/04/03

  • Modify the automatic collection logic to support four types of automatic collection events: start, close, crash, install
  • Support SDK time calibration function, support timestamp calibration and NTP server calibration
  • Allow specified time for user feature related settings interface incoming

# v1.4.3 2020/03/19

  • Supports default time zone setting for data #time property
  • Update the native SDK version

# v1.4.2 2020/02/21

  • Update iOS plugin to fix bugs introduced in older versions of iOS systems

# v1.4.1 2020/02/14

  • Adapt to Unity 2019.3.1f1

# v1.4.0 2020/02/11

  • Property values support List/Array types
  • Add UserAppend interface
  • Support Debug mode data validation
  • Support to configure the receiving end address separately for each instance
  • Remove local data format validation

# v1.3.1 2019/12/25

  • Fix Android 4.3 Exit Timeout
  • Fix an error when iOS development environment is not included

# v1.2.0 2019/09/02

  • Support to turn off/on data reporting
  • Support pause/continue data reporting
  • Supports lightweight instances
  • Fix 2019.2.1f version setting network type failure
  • Fix timeEvent inaccuracy problem
  • Android/iOS SDK upgrade to 2.1.0

# v1.1.0 2019/08/09

  • Support for getting device ID
  • Support dynamic public attributes
  • Support installation event collection
  • Embedded Android SDK upgraded to 2.0.2
  • Embedded iOS SDK upgraded to 2.0.1
  • Support the report caching option, users can choose to actively call StartTrack ()to start reporting

# v1.0.0 2019/06/20

  • Supports settings for Visitor ID and User Account
  • Support event and user feature reporting
  • Supports automatic reporting of ta_app_startand ta_app_endevents
  • Support public attribute interface
  • Support timeEventinterface
  • Support multi-project reporting