1. User domain porting

User domain porting is a feature of the Sensors Analytics Web JS SDK that allows you to unify the user behavior on two different domain websites. It enables you to more effectively observe the conversion journey of relevant website users.

2. SDK Integration

2.1. Download SDK

 GitHub Download Web JS  SDK,Put sensorsdata.min.js (the JS file that integrates the cross-domain open plugin) in the folder of your current project,For detailed integration steps, seeWeb JS  SDK Integrated document.

dist ├── web ├── plugin │ ├── plugin-xx │ │ ├── index.es6.js │ │ ├── index.closure.js │ │ ├── index.js |── sensorsdata.es6.js |── sensorsdata.js |── sensorsdata.amd.js
JS

2.2. Example Code

<script charset='UTF-8' src="在 github 下载新版本的 sensorsdata.min.js "></script> <script> 	var sensors = window['sensorsDataAnalytic201505']; 	sensors.init({ 		server_url: '数据接收地址', 		is_track_single_page:true, // 单页面配置,默认开启,若页面中有锚点设计,需要将该配置删除,否则触发锚点会多触发 $pageview 事件 		use_client_time:true, 		send_type:'beacon', 		heatmap: { 			//是否开启点击图,default 表示开启,自动采集 $WebClick 事件,可以设置 'not_collect' 表示关闭。 			clickmap:'default', 			//是否开启触达图,not_collect 表示关闭,不会自动采集 $WebStay 事件,可以设置 'default' 表示开启。 			scroll_notice_map:'not_collect' 		} 	}); 	//part_url 配置 sensorsdata.cn 和 example.com 后,会在神策分析环境中实现用户统一,从而实现跨域打通 	sensors.use('SiteLinker', 	{ 			linker: [ 			{part_url: 'sensorsdata.cn', after_hash: false}, 			{part_url: 'example.com', after_hash: false} 		], 			 // 该配置设置为 true 后,如果从已登录的页面跳转过来,即使当前网页已经登录,当前网页仍然会以之前网页的登录 id 再次登录。 		 	 re_login: true 		} 	); 	sensors.quick('autoTrack'); </script>
CODE

3. Parameter Configuration

re_login, this parameter is configured in the outermost layer of the plugin parameters, as shown in the code example. When this configuration is set to true, if the current webpage is accessed from a logged-in page, even if the current webpage is already logged in, it will log in again with the login ID of the previous webpage.


part_url is configured as a part of the website URL to be ported. The configured part_url string must be a substring of the ported URL and cannot be empty. This string must be at least 'x.' where x is any letter or digit. It is recommended to configure it as the domain of the ported website.

Desired Porting DomainConfigurationSensors Analytics a tag href addressSource domain login statusa tag porting result

sensorsdata.cn

example.com

{part_url:'example.com', after_hash: false}
{part_url:'sensorsdata.cn', after_hash: false}

https://www.sensorsdata.cn/auto

YEShttps://www.sensorsdata.cn/auto?_sasdk= 'u'+distinctID
http://example.com/indexNohttp://example.com/index?_sasdk= 'a'+distinctID


after_hash , configure the _sasdk parameter to be in the hash part (i.e., after #) or in the search part (i.e., before ?) of the URL. Required property, and the attribute value must be a boolean type, either true or false (default is recommended to be false).

urlafter_hashResult
http://example.comfalsehttp://example.com?_sasdk=distinctID
truehttp://example.com#?_sasdk=distinctID
http://example.com#indexfalsehttp://example.com?_sasdk=distinctID#index
truehttp://example.com#index?_sasdk=distinctID
http://example.com?a=007#indexfalsehttp://example.com?a=007&_sasdk=distinctID#index
truehttp://example.com?a=001#index?_sasdk=distinctID
http://example.com?a=007#index?b=001falsehttp://example.com?a=007&_sasdk=distinctID#index?b=001
truehttp://example.com?a=001#index?b=001&_sasdk=distinctID

4. Connect Result

A Domain PageB Domain PageConnect Result Explanation
Anonymous IDAnonymous ID
  1. B Domain Page's Anonymous ID will be replaced by A's Anonymous ID
Login IDAnonymous ID
  1. B Domain Page's Anonymous ID will perform login with A's Login ID
Anonymous IDlogin ID
  1. The anonymous ID of the B domain page is replaced by the anonymous ID of A
  2. The login ID of B's domain page is trackSignup with the anonymous ID of A
login IDlogin ID
  1. If not configured re_login, do not process
  2. If re_login parameter is set to true, the domain name of B is used as the login ID of A

Note: Because multiple domain names are involved, multiple anonymous ids will be generated. Therefore, it is recommended to enable the many-to-one function when using this function.

5. Principle statement

By default, the Web JS SDK generates a unique Distinct ID that is permanently saved in the browser to identify the user. The Cookie is bound with the domain name, so the identification of the user ID is theoretically limited to a domain name.

Multiple domain names can be accessed by sharing Distinct ids between them. Distinct ids are saved in your browser's cookies and can only be accessed by Web pages in the same domain. If you have multiple domains and want to treat them as the same resource, you need to find a way to share Distinct ids across all domains that you want to analyze.

Use sensorsdata.min.js After multi-domain name opening, you need to manually open cross-domain opening in the page initialization SDK code, only a tag jump and the parent element is a tag jump (the parent element is a tag requires JS SDK version in v1.16.1 and above) these two cases can achieve cross-domain opening.

On the domain to be connected, set this parameter to linker part_url attribute After the value is configured, sensorsdata.min.js The link to the a tag in the URL will be checked. If found contain part_url link, will extract the domain name under Distinct IDSplice into this connection, jump to the target domain, intercept the page URL linker parameters, get and replace the current domain nameDistinct ID.

For example, to connect sensorsdata.cn and example.com across domains, you only need to integrate the JSSDK under the two domain names and configure the following code to connect the two domains.After configuration and operation, sensorsdata.min.js Automatically listens for page a TAB jumps and automatically adds linker parameters to these links just before navigation is about to begin.

When the user reaches sensorsdata.cn host, sensorsdata.min.js The URL will be automatically checked for links with a tag if found contained part_url link, will extract the domain name underDistinct ID concatenated to this connection as a linker parameter, jump to example.com host, sensorsdata.min.js The _sasdk parameter will be intercepted,and Distinct ID replace  example.com 的 Distinct ID, to achieve user unification between two domain names. For the same reason that example.com is switched to sensorsdata.cn, cross-domain access is achieved.