User association
In the server-side application, the Distinct ID of the user is also required to be set for each event, which helps the analytics provide more accurate data such as retention rates. For registered users, a user ID in the system is recommended as a Distinct ID. Modified information such as the user name, Email address, and mobile phone number are not recommended.
All of the Track and Profile family of methods recommend explicitly specifying the isLoginId parameter to clearly inform the analytics user ID type.
User registration/login
When the Distinct Id of the same user changes (usually anonymous user registration behavior), can usetrackSignUp() associate the old Distinct Id with the new Distinct Id to ensure the accuracy of user analysis. For example:
// 匿名 ID 由前端传过来 String anonymousId = "9771C579-71F0-4650-8EE8-8999FA717761"; // 注册用户的真实 ID String registerId = "0012345678"; // 用户注册/登录时,将用户注册 ID 与 匿名 ID 关联 sa.TrackSignUp(registerId, anonymousId);
Note that for the same user,TrackSignUp() In general, it is recommended to call only once (usually at the userregister call), userloginIt is recommended to implement the association of the preceding and following behaviors on the business side. Called multiple times before the 1.13 version of Divine AnalysisTrackSignUp()Only the first association behavior is valid. The method for multi-device id association was provided after the 1.13 version of Sensors Analysis. Please refer to more detailed instructionsHow to accurately identify users, And contact our technical support staff if necessary.
Set user properties
In order to provide more accurate analysis services for the population, the Sensors Analytics SDK can set user attributes, such as age, gender, and so on. Users can use user attributes as filtering criteria or user attributes as dimensions for multi-dimensional analysis in retention analysis, distribution analysis and other functions.
Record user attribute
Use ProfileSet() set user attribute:
String distinctId = "ABCDEF123456789"; Dictionary<string, Object> properties = new Dictionary<string, object>(); // 设置用户等级属性(Level)为 VIP properties.Add("UserLv", "Elite VIP"); // $is_login_id 属性判断 distinct_id 是否为登录 ID,如果是则设置为 true,否则为 false,默认为 false properties.Add("$is_login_id", true); sa.ProfileSet(distinctId, properties);
For user attributes that are no longer needed, you can useProfileUnset() interface to delete the attributes.
In user attributes, the constraints on the attribute name and attribute value are the same as those on event attributes. For details, seeData format。
Records the properties that were first set
Properties that are only valid when first set we can use ProfileSetOnce() to record these properties. Different from ProfileSet(), If the set user property already exists, the record is ignored and does not overwrite existing data. , the property is automatically created if it does not exist. Therefore,profileSetOnce()applies to setting attributes such as the first activation time and first registration time. For example:
String distinctId = "ABCDEF123456789"; Dictionary<string, Object> properties = new Dictionary<string, object>(); // 设置用户渠道属性(AdSource)为 "App Store" properties.Add("AdSource", "App Store"); // $is_login_id 属性判断 distinct_id 是否为登录 ID,如果是则设置为 true,否则为 false,默认为 false properties.Add("$is_login_id", true); sa.ProfileSetOnce(distinctId,properties); // 再次设置用户渠道属性(AdSource),设定无效,属性 "AdSource" 的值仍为 "App Store" properties.Add("AdSource", "Search Engine"); sa.ProfileSetOnce(distinctId, properties);
Attributes of a numeric type
For numeric user properties, you can useProfileIncrement() add the property values. It is often used to record attributes such as the number of user payments, payment amount, and points. For example:
String distinctId = "ABCDEF123456789"; Dictionary<string, Object> properties = new Dictionary<string, object>(); // 设置用户游戏次数属性(GamePlayed),将次数累加1次 properties.Add("GamePlayed", 1); // $is_login_id 属性判断 distinct_id 是否为登录 ID,如果是则设置为 true,否则为 false,默认为 false properties.Add("$is_login_id", true); sa.ProfileIncrement(distinctId,properties );
Properties of a list type
For attributes such as the user's favorite movie and the restaurant that the user has reviewed, the column phenotype attributes can be recorded. Note that the element in the column phenotype attribute must beString type. See list type restrictions Data format 7.3 Attribute length restriction.
String distinctId = "ABCDEF123456789"; // 电影列表 List<String> movies = new List<String>(); movies.Add("Sicario"); movies.Add("Love Letter"); // 游戏列表 List<String> games = new List<String>(); games.Add("Call of Duty"); games.Add("Halo"); // 用户属性 Dictionary<string, Object> properties = new Dictionary<string, object>(); properties.Add("movies", movies); properties.Add("games", games); // 传入properties,设置用户喜欢的电影属性(movies)和喜欢的游戏属性(games) // 设置成功后,"movies" 属性值为 ["Sicario", "Love Letter"];"games" 属性值为 ["Call of Duty", "Halo"] sa.ProfileAppend(distinctId, properties); // 此方法还有一个重载方法,方便处理只有一个值的情况 // 传入属性名称和需要插入属性的值,设置用户喜欢的电影属性(movies) // 设置成功后 "movies" 属性值为 ["Dead Poets Society"] sa.ProfileAppend(distinctId, "movies", "Dead Poets Society");
track event acquisition
After the SDK initialization is completed, you can use the following interfaces to track data.
Tracking Events
When you first integrate Sensors Analytics, it is recommended to track 3 to 5 key events. With just a few lines of code, you can experience the analysis function of Sensors Analytics. For example:
- For a social media platform, you can track events such as user browsing pictures and commenting.
- For an e-commerce platform, you can track events such as user registration, browsing products, and placing orders.
After the Sensors Analytics SDK is successfully initialized, you can record events using the track() method. It must include the user ID (distinctId) and event name (eventName) as parameters. You can also pass a Dictionary<String, Object> object to add custom event properties. The custom properties should include the $is_login_id attribute to indicate whether distinct_id is a login ID. For example, for an e-commerce platform, you can track a purchase behavior like this:
// 用户的 Distinct Id String distinctId = "ABCDEF123456789"; // 用户浏览商品 Dictionary<string, Object> properties = new Dictionary<string, object>(); // '$time' 属性是系统预置属性,表示事件发生的时间,如果不填入该属性,则默认使用系统当前时间 properties.Add("$time", new Date()); // '$ip' 属性是系统预置属性,如果服务端中能获取用户 IP 地址,并填入该属性,神策分析会自动根据 IP 地址解析用户的省份、城市信息 properties.Add("$ip", "123.123.123.123"); // $is_login_id 属性判断 distinct_id 是否为登录 ID,如果是则设置为 true,否则为 false,默认为 false properties.Add("$is_login_id", true); // 商品 ID properties.Add("ProductId", "123456"); // 商品类别 properties.Add("ProductCatalog", "Laptop Computer"); // 是否加入收藏夹,Boolean 类型的属性 properties.Add("isAddedToFav", true); // 记录用户浏览商品事件 sa.Track(distinctId, "ViewProduct", properties);