# C#
TIP
Before you begin, please read Preparation before Data Ingestion.
Latest version: 1.5.1
Update time: 2022-11-09
Resource download: source code (opens new window),dll (opens new window)
# SDK Integration
1.1 Download the SDK (opens new window), and import the files into your project.
1.2 Logbus Integration
We recommend using SDK+LogBus to track and report data on server. You can refer to the following documents to complete the installation of Logbus: LogBus User Guide
# Initialization
The following is the sample code for SDK initialization:
using ThinkingData.Analytics
ThinkingdataAnalytics te = new ThinkingdataAnalytics(new LoggerConsumer(LOG_DIRECTORY));
LOG_DIRECTORY
is the local folder path.
# Common Features
In order to ensure that the distinct ID and account ID can be bound smoothly, if your game uses the distinct ID and account ID, we strongly recommend that you upload these two IDs at the same time, otherwise the account will not match, causing users to double count. For specific ID binding rules, please refer to the chapter on User Identification Rules.
# 3.1 Sending 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:
Dictionary<string, object> properties= new Dictionary<string, object>();
properties.Add("#ip", "123.123.123.123");
properties.Add("channel", "TE");// string
properties.Add("age", 1);// number
properties.Add("is_success", true);// bool
List<string> list = new List<string>();
list.Add("value");
properties.Add("array",list);// array
Dictionary<string, Object> object = new Dictionary<string, object>();
object.Add("key", "vale");
properties.Add("object", object); // object
// object group
List<Object> object_arr = new List<Object>();
object_arr.Add(object);
properties.Add("object_arr", objet_arr);
te.Track("accountId", "distinctId", "Payment", properties);
- Key is the name of the property and refers to the string type. It must start with a character, and contain numbers, characters (insensitive to case, and upper cases would be transformed into lower cases by TE) and underscores "_", with a maximum length of 50 characters.
- Value, the value of the property, supports string, numbers, Boolean, time, object, array object, and array
The requirements for event properties and user properties are the same as that for super properties
# 3.2 User Properties
You can set general user properties by calling user_set
API. The original properties would be replaced by the properties uploaded via this API. If no user properties are set before, user properties will be newly created. The type of newly-created user properties must conform to that of the uploaded properties. User name setting is taken as the example here:
// username is TA
Dictionary<string, object> properties= new Dictionary<string, object>();
properties.Add("user_name","TA");
te.UserSet("accountId","distinctId", properties);
// userName is TE
Dictionary<string, object> newProperties= new Dictionary<string, object>();
newProperties.Add("user_name","TE");
te.UserSet("accountId","distinctId", newProperties);
# Best Practice
The following sample code covers all the above-mentioned operations. It is recommended that the codes be used in the following steps:
using ThinkingData.Analytics
// inti SDK
ThinkingdataAnalytics te = new ThinkingdataAnalytics(new LoggerConsumer(LOG_DIRECTORY));
Dictionary<string, object> properties= new Dictionary<string, object>();
properties.Add("#ip", "123.123.123.123");
properties.Add("channel", "TE");
properties.Add("age", 1);
properties.Add("is_success", true);
List<string> list = new List<string>();
list.Add("value");
properties.Add("array",list);
Dictionary<string, Object> object = new Dictionary<string, object>();
object.Add("key", "vale");
properties.Add("object", object);
List<Object> object_arr = new List<Object>();
object_arr.Add(object);
properties.Add("object_arr", objet_arr);
te.Track("accountId", "distinctId", "Payment", properties);
Dictionary<string, object> properties= new Dictionary<string, object>();
properties.Add("user_name","TE");
te.UserSet("accountId","distinctId", properties);
te.Flush();