1. User association

The purpose of user association is to uniquely identify users and improve the accuracy of user behavior analysis. At present, we provide simple user association and global user association to support different business scenarios.

2. User attribute

  • For the difference between event properties and user properties, seedata model
  • For naming restrictions on user attributes, seedata format

2.1. Set User Attributes

Use setProfile() method set user attributes. This method will overwrite existing data if you set the attributes again.

// 设定用户的 "AdSource" 属性值为 "XXX Store" sensors.setProfile({ AdSource: "XXX Store"	})
CODE

2.2. Records the user properties that were set for the first time

We can use properties that are only valid when first setsetOnceProfile() to record these attributes. Different from setProfile()method, If the set user property already exists, the record is ignored without overwriting existing data, and is automatically created if the property does not exist. Therefore,setOnceProfile() This parameter is applicable to setting the first activation time and first registration time. For example:

// 设定用户的 "AdSource" 属性值为 "XXX Store" sensors.setOnceProfile({ AdSource: "XXX Store"	}) // 再次设定用户渠道,设定无效, "AdSource" 属性值仍然是 "XXX Store" sensors.setOnceProfile({ AdSource : "Email" })
CODE

2.3. Attributes of a numeric type

For numeric user properties, you can use incrementProfile() to add the property values. It is often used to record attributes such as the number of user payments, payment amount, and points. For example:

// 将用户游戏次数属性增加一次 sensors.incrementProfile("GamePlayed", 1);
CODE

2.4. Properties of a list type

For the user's favorite movies, restaurants reviewed by the user and other attributes, you can record the column phenotype attributes, such as:

// 设定用户观影列表属性,设定后属性 "Movies" 为: ["Sicario", "Love Letter"] sensors.appendProfile('Movies', ['Sicario','Love Letter']);
CODE

Note that the element in the column phenotype attribute must be String type. See column phenotypic restrictionsdata import.

2.5. Delete user attributes

If you need to delete a user attribute that has been set, you can call unsetProfile() to delete it:

sensors.unsetProfile("age");
CODE

2.6. Delete a user

Delete the current user and all his properties.

//删除当前这个用户及他的所有属性 sensors.deleteProfile();
CODE

3. Buried point event acquisition

After SDK initialization is complete, you can bury data through the following interface.

3.1. Code bury trace event

After SDK initialization, you can use track() method to track user behavior events and adds custom properties to events.

//触发一条 BuyProduct 事件,同时设置商品 ID、商品类别属性 sensors.track('BuyProduct', { ProductID: 123456, ProductCatalog:'Laptop Computer'})
CODE


For the format specifications of event names and event attributes, seedata format.

3.2. Buried event collection duration attribute

You can count the duration of an event with a timer. First, it is called at the beginning of the eventtrackTimerStart("Event") , this method does not actually send the event; At the end of the event, call trackTimerEnd("Event", properties),SDK will trigger"Event" event, and automatically records the event duration in the event properties "$event_duration" . For example, record the time users spend browsing product pages:

sensors.trackTimerStart('ViewProduct'); // 调用 track,记录 ViewProduct 事件,并在属性 event_duration 中记录用户浏览商品的时间 sensors.trackTimerEnd('ViewProduct', {product_id:'PRODUCT_ID'}); 
CODE

When multiple call trackTimerStart("Event"), The start time of "Event" is based on the last call.Note It is important to ensure that the trackTimerStart and trackTimerEnd interfaces are used together. Calling trackTimerEnd multiple times will trigger an eternally-buried event.

Statistical event duration supports pause and recovery by calling trackTimerPause(String eventName) and trackTimerResume(String eventName) to pause and resume, respectively. Called if the recorded duration event needs to be cleared clearTrackTimer() interface.

3.3. Activation event acquisition

You can call trackAppInstall() method to record activation events. Calling this method multiple times will only trigger the activation event on the first call.Support Android and amp only; The iOS terminal.

sensors.trackAppInstall({propA:'valueA'}); 
CODE


  1. If the original activation event name is not $AppInstall, this parameter is requiredCustom Eventsto combine the original activation event and $AppInstall to analyze the data, and consult technical support for details.
  2. For more information on channel tracking, please refer toChannel tracking.


4. Event attribute

When tracking buried events, you can define buried event attributes as required. Currently, the SDK provides public attributes for adding attributes to each buried event. Public properties are used to set properties that update less frequently. When a property of the same Key appears in the same event, the SDK overrides the priority: preset property < Static public attribute < Custom properties.

4.1. Public attribute

Public attributes refer to the attributes that need to be added for all events. After initializing the SDK, you can register the attributes as public attributes through the register method. The setting method is as follows:

// 将应用名称作为事件公共属性,后续所有 track 类型事件都会自动带上 "AppName" 属性 sensors.register( 	{  	 AppName: 'AppName' 	} )
CODE


Use the unRegister(key:String) method to remove the specified key of the public attribute.

Use the clearRegister() method to remove all registered public attributes.

5. Data Storage and Sending

For more precise control over sensors analytics, you can set data collection functions through the following options.

5.1. Data Collection

Each time the track() and setProfile() methods are called, the Sensors Analytics SDK saves the event points in the database (this feature only works when compiled for Android and iOS, and does not support web). After meeting the sending conditions (satisfying the cache number or cache time interval and having network connection), the Sensors Analytics SDK compresses the data to be sent in gzip format and sends it in batches to Sensors Analytics.

If you pursue the timeliness of data collection, you can automatically call the flush() method to force the data to be sent to Sensors Analytics. For example:

// 记录用户登录事件 sensors.track("Pay"); // 强制发送数据 sensors.flush();
CODE

When the app enters the background state or the network switches to the networked state, the SDK calls the flush() method to send the cached data to Sensors Analytics.

Note: The login method triggers the $SignUp event when it is called, which immediately triggers sending the cached data to Sensors Analytics.

5.2. Clear Local Cached Events

You can use the deleteAll() method to delete all events stored locally by the app.

If not specifically required, do not call this method.

//删除 App 本地存储的所有事件 sensors.deleteAll();
CODE

6. Full-Track

Full-Track refers to four types of events on the APP side: $AppStart (App launch), $AppEnd (App exit), $AppViewScreen (page browsing), and $AppClick (control click). On the web side: $pageview (page browsing), $WebClick (element click), and $WebStay (page scroll) three types of events. Regarding App launch and exit, in order to cope with multi-processes, force kill, etc., Android SDK introduces a 30-second session mechanism. When the user exits the app to the background for 30 seconds, the exit event will be triggered. Launching the app again will trigger the launch event. If the user opens the app within 30 seconds, there will be no corresponding exit event and launch event. In addition, if the process is not killed within 30 seconds after exiting the app to the background, the exit event will be triggered and attempted to be reported. If the process is killed, the exit event will be replayed the next time the app is launched. Therefore, when viewing the data, the number of exit events is generally less than the number of launch events.

6.1. Enable Full-Track Configuration

The SDK can automatically collect some user behaviors, such as app launch, exit, page browsing (it is necessary to call the SDK useRouter method before initializing the SDK to enable automatic collection), and control click. When initializing the SDK, you can configure the types of Full-Track to be enabled:

sensors.init({ 	//... 其他配置     	web: {//web 初始化配置 page_view: true, // 自动采集 $pageview(页面浏览)      web_click: true, // 自动采集 $WebClick(元素点击)      web_stay: true, // 自动采集 $WebStay(页面滚动停留时长)   }, 	app: {// Android & iOS 配置 app_start: true, // 自动采集 App 启动 app_end: true, // 自动采集 App 退出 view_screen: true, // 自动采集浏览页面 view_click: true // 自动采集控件点击 	} })
CODE


If the scroller control is used as the outermost layer of the page, $WebStay cannot be automatically reported when compiled for web projects.


6.2. useRouter method

In order to automatically collect page view events ($AppViewScreen, $pgeview), you need to call the useRouter method provided by the SDK and pass in the VueRouter object of the page before initializing the SDK. Currently, only Weex applications developed with VUE are supported, and Rax is not supported.

// 步骤1: 引入模块 import sensors from 'sa-sdk-weex'   // 步骤2: 将项目中声明对 VueRouter 对象传入 Weex SDK 提供的 useRouter 方法以支持页面切换时自动采集页面浏览事件 const { router } = require('./router') sensors.useRouter(router)
CODE

6.3. Manually trigger full tracking events

Manually triggering full tracking events means that developers call the interface provided by the SDK to trigger the App page view event. The difference between manually triggered full tracking events and automatically triggered full tracking events by the SDK is that the value of lib_method for events triggered by developers calling the interface is "code", and the value for events triggered by the SDK is "autoTrack". Note that it is recommended not to mix this feature with full tracking to avoid event duplication.

6.3.1. Manually trigger page view events

You can manually trigger App page view events by using the trackViewScreen() method, and this interface is not limited by ignore conditions.

sensors.trackViewScreen(url, {title:'title'})
CODE

7. Other functions

7.1. Set data reporting address

Call the setServerUrl method to modify the data reporting address. After the call is successful, the data will be reported using the new data reporting address.

sensors.setServerUrl('数据接收地址');
CODE