Real-time segments are created using streaming behaviors and historical data (by referencing attributes). Real-time segmentation enables deeper customers insights and activations in real-time. This type of segment provides opportunities for companies to be more responsive to their customers no matter where they are in the customer journey, specifically real-time web personalization using the TD JS SDK and Profiles API.

Architecture

Real-time Segmentation provides the ability to personalize the content, ads, and pages, while your customers are visiting your website. For example, an e-Commerce company would like to show "Today's Special Camera Offer" banner ads in the page, if visitors have navigated to the Camera category multiple times while they're exploring the products.

  • Real-time segmentation is based on Segmentation Primitives that can be limited for realtime and compared to Batch-based records.
  • Real-time Segmentation makes use of the Profiles API to return user segments using JavaScript SDK.
  • Real-time segmentation is limited for use against data from websites with JavaScript SDK installed. In addition, it has limits on the segmentation logic that can be defined.

Use Cases

Realtime Segments operates against streaming data as the data arrives into Treasure Data in real-time to help you provide for the following use-cases:

  • Re-marketing

    • If visitors do some meaningful actions in the website, you can specifically target these users "instantly" through other means

  • Personalization

    • Show personalized content, banner, and ads in the website for higher engagements and conversions

  • Conversion Optimization

    • Show a chat modal dialog to help customers complete any open transactions that they may have started

  • Customer Support

    • Show help messages if customers are going back and forth with same pages

  • Use Scoring

    • Scoring users in real time, and show special offers to valuable visitors and customers

Prerequisites

Setting Up Website Tracking and Installing the Treasure Data JavaScript SDK

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

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.

    <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.

    <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.

    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:

    var buttonEvent2 = function () {
      td.trackEvent('button', {
        number: 1
      });
      // doButtonEvent(1);
    };
  7. Optionally, track events by an individual. Be sure to comply with all necessary data collection and privacy policies if you choose to do this.

    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) 


Setting Up a Parent Segment to Use for Real-time Segmentation

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

  1. Open TD Console
  2. Select Data Workbench > Master Segments (Parent Segment).

  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 Realtime Segment


1. Open TD Console.
2. Navigate to Audience Studio.

3. Using the drop-down, select the Parent Segment from which you want to create a segment.


4. Select Create New.

5.  The Create New dialog opens. Select Segment. Select Real-time for Segment Type.

6.  Name the segment and select Create.


  • No labels