Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Real-Time time Segmentation can be used to enable real-time personalization for people who are visiting your website, using the Profile API. This set up assumes that you have one or more websites where you want to track customer activity. It also assumes that you have already created a database and tables within your Treasure Data instance to store the collected information.

...

You will need to set up website tracking by installing the TD JS SDK before setting up a realtime real-time segment. 

Expand
titleSetting Up JS SDK

Our JavaScript SDK is available through GitHub. Check the repository, if necessary. The README contains the description of JavaScript SDK API. There are some additional APIs to track custom events and such.

  1. Using the TD Console, obtain your write only API Key. For example:

  2. Locate and open the HTML files of the web pages that you want to have tracked for your real-time segmentation.

  3. Add the following code to the header (<head>) of each of the pages that you want to track.

    Code Block
    languagejs
    linenumberstrue
    <script type="text/javascript">
    !function(t,e){if(void 0===e[t]){e[t]=function(){e[t].clients.push(this),this._init=[Array.prototype.slice.call(arguments)]},e[t].clients=[];for(var r=["addRecord","blockEvents","fetchServerCookie","fetchGlobalID","fetchUserSegments","resetUUID","ready","setSignedMode","setAnonymousMode","set","trackEvent","trackPageview","trackClicks","unblockEvents"],s=0;s<r.length;s++){var c=r[s];e[t].prototype[c]=function(t){return function(){return this["_"+t]=this["_"+t]||[],this["_"+t].push(Array.prototype.slice.call(arguments)),this}}(c)}var n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.treasuredata.com/sdk/3.0/td.min.js";var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(n,o)}}("Treasure",this);
    </script>


  4. Add the following code snippet to include your write only API key and indicate the Treasure Data database where you want to have information from the sites saved to. Also enable cross-domain tracking and enable tracking of page views.

    Code Block
    linenumberstrue
    <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_table>');
    </script


  5. Optionally, set custom parameters.

    Code Block
    linenumberstrue
    td.set('pageviews', {foo: 'foo', bar: 'bar'});
    td.trackPageview('pageviews');


  6. Optionally, track custom events. For example, to track a button click add the following:

    Code Block
    languagejs
    linenumberstrue
    var buttonEvent2 = function () {
      td.trackEvent('button', {
        number: 1
      });
      // doButtonEvent(1);
    };


  7. Optionally, track events by individual. Be sure to comply with all necessary data collection and privacy policies if you choose to do this.

    Code Block
    linenumberstrue
    td.trackClicks()
    
    var successConsentCallback = function (consented) {
      if (consented) {
        td.setSignedMode()
      } else {
        td.setAnonymousMode()
      }
    }
    
    var failureConsentCallback = function () {
      // error occurred, consent unknown
      td.setAnonymousMode()
    }
    
    ConsentManagementVendor.getConsent(userId, successConsentCallback, failureConsentCallback) 



...

The behavior table must be set up in the master segment for you to set up a realtime real-time segment.

Expand
titleSetting Up a Master Segment
  1. Open TD Console
  2. Select Data Workbench > Master Segments.

  3. Select New Master Segment to create a new master segment or select an existing master segment.

  4. Optionally, an Attribute table by clicking on the +. 

  5. Add the Behavior table. This is required for real-time segmentation.
    The behavior table must be the table that the event collector put the data into above. And it should include the following columns:
    td_client_id
    td_host
    td_path
    td_ip
    td_user_agent

  6. Define All columns for the Behavior table.


  7. Select Save.

Creating a

...

Real-time Segment

You can choose a behavior and specify the scope of a time window for scanning.

...