How it works
The flow of collecting user data on your website is as follows:
A user accesses your website. Treasure Data checks to see if a td_ssc_id cookie exists for the user.
If yes, activities are tracked through Treasure Data SDK that is installed on your website
If no, and consent has been granted, Treasure Data SDK creates a first party, server-side cookie for the user
Treasure Data records users consent response. In your configuration of the Treasure Data SDK, you specify where the user consent is stored. By storing the consent on the user's browser, the user is not asked for tracking permission each time they access your website and the consent record persists as specified in the cookie document on your website.
The user grants permission to track. A Treasure Data API on your webpage requests a unique ID from Treasure Data.
Treasure Data sends a unique ID back to your webpage. Server-side cookies can be set to persist for up to two years.
The td_ssc_id for the user is stored in the cookie document on your website and, if configured in in the Treasure Data SDK, tracking of activities performed by the user is recorded in your CDP account.
You complete the following steps to enable server-side tracking of first party cookies.
- Set up the NS record in your DNS to establish a definitive query response between your website server and Treasure Data
- Configure the JS SDK to collect and store first party cookies on your website, Or, alternatively, update your existing JS SDK and server-side cookie document. Also, ensure that the database table in Treasure Data, that collects cookie data, has a column for TD_SSD_ID.
- Select option for collecting and storing consent
- Basic knowledge of Treasure Data
- A subdomain (DNS) under your primary website
Setting up the NS Record in your DNS
The Treasure Data server-side tracking requires that the server that creates first party cookies under a subdomain of the primary website. You must add an NS record in your subdomain that points to the Treasure Data SSC service. The NS record points the name of the subdomain to Treasure Data name servers.
- primary website: www.example.com
- subdomain: ssc.example.com
Generally, you follow the procedures for your website configuration to add an NS record. Your Treasure Data Customer Success Representative provides the details on the Treasure Data server records that you are to use. You might specify more than one record for redundancy and to speed up the DNS lookup (you can pick the name server that’s physically closest to the browser).
Configuring the JS SDK to Collect and Store First Party Cookies
As the website server developer, you install TD JS SDK and configure function calls to fetch a Treasure Data-generated ID for each user who visits your website. The function calls are basically API requests to Treasure Data's SSC. The ID that SSC returns to your website is saved on the end-user's browser.
Parameters and Functions include:
- sscDomain: String | (String) => String | null. Top-level domain of your website.
- sscServer: String | null. The subdomain you create on your website to connect to Treasure Data.
- useServerSideCookie: Boolean
- setSignedMode() function
- trackPageview() function
- set() function
You can view a TD JS SDK overview and installation walkthrough. Also review Implementation for GDPR for a description of the TD JS SDK function that helps you to comply with privacy regulations and requirements.
You can read how about how to install TD JS SDK: Getting Started with Website Tracking. As part of the instructions, Enable Tracking Events by Individual, is key to enabling tracking of first party cookies.
Embed the JS code to call the Server Side Cookie
The JS code for ssc server sets a cookie on the given subdomain as a parameter. The unique id for each end user visitor persists for 2 years, unless the user clears their cookies.
When users re-visit the site later, they are recognized as the same user.
Ensure your Treasure Data account is set up import data from your webpage.
The following code example illustrates the parameters and functions that you configure on your website:
Modify your Existing JS SDK to Establish Connection with td-ssc
Update the existing JS SDK coding on your website, adding the required parameters and functions. Refer to the preceding code example.
Then, in Treasure Data, ensure that the database table that receives the first party cookie data, includes a column for the td_ssc_id. The column is required when events are being recorded into an existing table:
Specifying the Consent Record Location
Typically, consent is stored in the browser as a client-side cookie, for example, in document.cookie. Treasure Data provides a new location option for consent. The location is in the user's local storage.
In the JS SDK specify
When end user accepts consent, the consent is saved in the end user's local storage.