1. SDK Initialization Parameters

If using automatic code generation, parameters usually do not need to be modified manually.

ParameterDefault ValueMeaningRemarks
sdk_urlNoneThe address of the sensorsdata.min.js file.Please obtain it from GitHub and place it in your website directory.
server_urlNoneThe data receiving address.
heatmap_urlNone

The address of the heatmap.min.js file. The code for click analysis and reach analysis in Sensors Analytics will be automatically generated by the code generation tool. If the version of sensorsdata.min.js in Sensors Analytics is 1.13.1 or earlier, this parameter needs to be configured. It is not required for versions higher than this.

Please obtain it from GitHub and place it in your website directory.

web_url

No

The address of the Sensors Analysis backend. The Sensors Analysis click analysis and reach analysis functions will use this address, and the code generation tool will generate it automatically. If the version of the Sensors Analysis backend and sensorsdata.min.js are both 1.10 or above, this parameter does not need to be configured.

Automatic configuration: Get it through the page URL parameters.

If you need to solve the XSS problem, you can solve it by manually setting the web_url.

Web_url usage logic: Manual configuration > URL parameters

heatmapNo

Click map configuration. The default configuration means that element click events and page stay events are not collected automatically. Configuring {} means enabling automatic collection of $WebClick and $WebStay. By default, $WebClick only collects the click events of four DOM elements: a, button, input, and textarea.


cross_subdomaintrue

Set it to true to set cookies under the root domain. For example, if you have two domains: zhidao.baidu.com and tieba.baidu.com, and a user logs in to both domains in the same browser, we will consider it as the same user. If set to false, it will be considered as two users.


show_logfalseSet it to true to display the logger in the web console, which will show the sent data. Set it to false means it will not be displayed.
source_channelNoThe default source is obtained based on ga standards such as utm_source. If you use parameters such as hmsr from Baidu Statistics, you need to add the corresponding parameters to this field. The parameters must be an array, for example: ['hmsr']. When adding custom properties with the web general channel, you need to add the corresponding custom property name to this field.
source_type
Custom search engine traffic, social traffic, search keywords.

Detailed configuration reference

max_string_length500Maximum string length, exceeding which will be truncated and discarded (strings longer than 7000 will result in excessively long URLs, preventing their transmission).
send_typeimageIndicates using beacon requests to send data, alternatively, using 'image' GET requests to send data. (Available since SensingIO system version 1.10) Supports 'ajax' and 'beacon' methods to send data, both default to POST method. The beacon method has poor compatibility.
callback_timeout200, in millisecondsSpecifies the timeout for callback functions. If the data sending exceeds callback_timeout and no result is returned, the callback function will be forcefully executed.

Supported from SDK version 1.11.6

queue_timeout300, in millisecondsSpecifies the timeout for queue sending. If the data sending time exceeds queue_timeout and no result is returned, the next data will be forcefully sent.

SDK Version 1.11.6 to 1.18.17 supported

datasend_timeout3000, in millisecondsIndicates the timeout for data sending. If the data sending exceeds datasend_timeout and no result is returned, the request will be forcibly canceled.

SDK Version 1.11.6 and later supported

preset_properties
Whether to enable $latest property collection for the most recent related events and configure $url as a global property. The default value is an object.

SDK Version 1.14.10 and later supported
Advanced Features (Web)

is_track_single_pagefalseIndicates whether to enable automatic tracking of $pageview events for single-page applications. The SDK will automatically track web page view events ($pageview) after the URL changes.

SDK Version 1.12.18 and later supported


2. Event Common Properties

2.1. Set static common properties for events

For properties that need to be added to all events, you can register them as common properties after initializing the SDK by calling registerPage() :

<script> // 注册公共属性 sensors.registerPage({ 	current_url: location.href, 	referrer: document.referrer }); </script>
JS

2.2. Set dynamic common properties for events

Version requirement

Web JS SDK 1.14.15 and later versions

When setting dynamic public properties, please use function types as attribute values. The return value of the function should be a supported type by Sensors Analytics. Please refer to the data format for more information. Otherwise, it will be filtered out.
Also, if you use ES6 syntax such as arrow functions, you need to compile and run it with a compilation tool.

<script> // 注册公共属性 var i=0 sensors.registerPage({ prop_number: function() { return ++i; // 返回数字 }, prop_boolean: function() { return i<10 ? true : false; // 返回bool }, prop_string: function() { return ""; // 返回字符串 }, prop_date: function() { return new Date('December 17, 1995 03:24:00'); // 返回日期类型 }, prop_array: function() { return ["1","2","3"] // 返回元素是字符串的数组 } }) </script>
JS


Also, if the function returns a value in an asynchronous callback, it will also be filtered out.

<script> // 注册公共属性 var i=0 sensors.registerPage({ prop_number: function() { return ++i; // 返回数字 }, prop_boolean: function() { return i<10 ? true : false; // 返回bool }, prop_string: function() { return ""; // 返回字符串 }, prop_date: function() { return new Date('December 17, 1995 03:24:00'); // 返回日期类型 }, prop_array: function() { return ["1","2","3"] // 返回元素是字符串的数组 } }) </script>
JS


2.3. Get predefined properties

Version requirement

Web JS SDK 1.9.13 and later versions

This method can obtain the page URL, page title, referrer URL, SDK type and version, screen width and height, and the most recent relevant properties. If the server needs to use these properties, the client needs to transmit them by themselves, and these properties do not include IP and UA that require server-side parsing.

sensors.quick('isReady',function(){ 	var presetProperties = sensors.getPresetProperties(); });
JS

3. Set user properties

3.1. setProfile(properties)

Directly set the user's properties. If they already exist, they will be overridden.

properties: object, required.

sensors.setProfile({email:'xxx@xx'});
JS

3.2. setOnceProfile(properties)

If the properties do not exist, set them; otherwise, do not set them.

properties: object, required.

sensors.setOnceProfile({email:'xxx@xx'});
JS

3.3. appendProfile(properties)

Add values to array properties. The setProfile method can only change the value of the property. If the property is an array and you don't want to completely change the value, but only want to add or remove values, you can use this method.

properties: object, required.

//给 category 增加两个值 sensors.appendProfile({catrgory: ['玉米','白菜']}); //给 category 增加一个值 sensors.appendProfile({catrgory: '玉米'});
JS

3.4. incrementProfile(properties)

Increment or decrement the current user's properties.

properties:object or string, required.

// 表示 navClick 递减 sensors.incrementProfile({'navClick': -1}); // 表示 navClick 递增2 sensors.incrementProfile({'navClick': 2}); // 直接传入一个属性名,表示递增1 sensors.incrementProfile('navClick');
JS

3.5. deleteProfile()

Delete the current user and all his properties.

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

3.6. unsetProfile(property)

Delete some properties of the current user

properties:array or string, required.

//删除 email 和 location 属性 sensors.unsetProfile(['email','location']); //删除 email 属性 sensors.unsetProfile('email');
JS


4. Item metadata report

In the Sensors recommendation project, customers need to report the item metadata to carry out the subsequent development and maintenance of the recommendation business. The Web SDK provides methods for setting and deleting item metadata.

item_id(item ID ) item_type (item type) form the unique identity of an item. All item family methods must be specified simultaneouslyitem ID 及item typetwo parameters, to complete the operation of the item.

Version requirement

  • Web JS SDK 1.18.12 and later versions

4.1. setItem(item_type,item_id,properties)

Set an item directly and overwrite it if it already exists. In addition to the item ID and the item type, other item attributes need to be in properties to be defined.

In item attributes, the constraints on the attribute name and attribute value are the same as those on event attributes. For details, please refer todata import.

item_type:string, required.

item_id:string, required.

properties:object, optional.

sensors.setItem("food","2",{name:"玉米",flavour:"甜"});
JS

4.2. deleteItem(item_type,item_id)

If the item cannot be recommended and needs to go offline, just delete it, or ignore it if it does not exist.

Other item attributes are not parsed except for item ID and item type.

item_type: string, required.

item_id: string, required.

sensors.deleteItem("food","2");
JS

5. Set custom properties

Refer to the Plugin Integration (Web) document and integrate the Custom Properties Plugin

6. Page view time

Refer to the Plugin Integration (Web) document and integrate the Page Leave Plugin

7. Page load time

Refer to the Plugin Integration (Web) document and integrate the Page Load Time Plugin

  • If the browser does not support the performance API, the event_duration attribute will not be available for the page load time event.
  • The page load time calculation is for the entire page load time. Switching routes within a single page will not trigger the page load time.

8. Advanced features &amp; plugins

More features can be found in the Advanced Features (Web) document.

More plugins can be found in the Plugin Integration (Web) document.