User domain porting (Web)
|
Collect
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, see Web 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
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>
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 Domain | Configuration | Sensors Analytics a tag href address | Source domain login status | a tag porting result |
---|---|---|---|---|
sensorsdata.cn example.com | {part_url:'example.com', after_hash: false} | https://www.sensorsdata.cn/auto | YES | https://www.sensorsdata.cn/auto?_sasdk= 'u'+distinctID |
http://example.com/index | No | http://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).
url | after_hash | Result |
---|---|---|
http://example.com | false | http://example.com?_sasdk=distinctID |
true | http://example.com#?_sasdk=distinctID | |
http://example.com#index | false | http://example.com?_sasdk=distinctID#index |
true | http://example.com#index?_sasdk=distinctID | |
http://example.com?a=007#index | false | http://example.com?a=007&_sasdk=distinctID#index |
true | http://example.com?a=001#index?_sasdk=distinctID | |
http://example.com?a=007#index?b=001 | false | http://example.com?a=007&_sasdk=distinctID#index?b=001 |
true | http://example.com?a=001#index?b=001&_sasdk=distinctID |
4. Connect Result
A Domain Page | B Domain Page | Connect Result Explanation |
---|---|---|
Anonymous ID | Anonymous ID |
|
Login ID | Anonymous ID |
|
Anonymous ID | login ID |
|
login ID | login ID |
|
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.
Note: The content of this document is a technical document that provides details on how to use the Sensors product and does not include sales terms; the specific content of enterprise procurement products and technical services shall be subject to the commercial procurement contract.