Skip to content
Last updated

Enabling Cross Domain Tracking With JavaScript SDK

Treasure AI recommends that you implement any new features or functionality at your site using the Treasure Data JavaScript SDK version 3. It manages cookies differently. Be aware when referring to most of these articles that you need to define the suggested event collectors and Treasure Data JavaScript SDK version 3 calls in your solutions.

Prerequisites

  • Basic knowledge of JavaScript and HTML

  • Basic knowledge of Treasure Data

  • Basic knowledge of Treasure Data JavaScript SDK

  • You need at least JavaScript SDK v1.7.1

  • Validate that you want to track 3rd party cookies from web browsers that allow them

Limitations

Cross-Domain Tracking relies on the 3rd party cookie mechanism. For more details, see Anonymous IDs. It doesn't work on Mobile or PC Safari, which blocks all third-party cookies by default, and it doesn't share an ID across domains on Firefox, where Total Cookie Protection isolates third-party cookies per top-level site. See About Treasure AI and Cookie Tracking for the full browser comparison.

Enabling Cross-Domain Tracking

Cross-Domain tracking must be enabled to be active for JavaScript SDK.

Call td.set('$global', 'td_global_id', 'td_global_id'); to enable the feature.

<script type="text/javascript">
  // Configure an instance for your database
  var td = new Treasure({
    host: 'in.treasuredata.com',
    writeKey: 'YOUR_WRITE_ONLY_APIKEY_IS_HERE',
    database: 'DATABASE_NAME'
  });
  // Enable cross-domain tracking
  td.set('$global', 'td_global_id', 'td_global_id');
  // Track pageview information to 'pageviews' table
  td.trackPageview('pageviews');
</script>

This line adds an additional column called td_global_id to the destination table.