Prerequisites



Treasure Data recommends that you implement any new features or functionality at your site using the Treasure Data JavaScript SDK version 3 Beta. 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.

For example, change //cdn.treasuredata.com/sdk/2.5/td.min.js to //cdn.treasuredata.com/sdk/3.0.0-beta/td.min.js.


Adding Known IDs for Website Tracking

With Treasure Data SDKs, you can add known IDs of visitors (most commonly, email, user_id, etc).


  1. td.set() function can be used to add an arbitrary number of additional information for the visitors.

<script type="text/javascript">
  // Configure an instance for your database
  var td = new Treasure({...});
  // Enable cross-domain tracking
  td.set('$global', 'td_global_id', 'td_global_id');

  // Add Known IDs to tracking information
  td.set('pageviews', {
    email: 'kazuki@treasure-data.com',
    account_id: '1024'
  });

  // Track pageview information to 'pageviews' table
  td.trackPageview('pageviews');
</script>

As Treasure Data is schema-less architecture, you can add and subtract any number of known ID columns anytime.

Encrypting KnownIDs with CryptoJS

You might want to send raw known IDs to Treasure Data. CryptoJS supports the majority of encryption algorithms including SHA-256, AES, etc.

  1. Apply encryption with CryptoJS, before sending IDs to Treasure Data.

<!-- Load CryptoJS library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>
<script type="text/javascript">
  ....
  // Add Known IDs to tracking information
  td.set('pageviews', {
    email: CryptoJS.enc.Base64.stringify(CryptoJS.SHA256('meg@tre-data.com')),
    account_id: CryptoJS.enc.Base64.stringify(CryptoJS.AES.encrypt('1024', 'secret key 1234').ciphertext)
  });
  ....
</script>
  • No labels