Real-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 real-time segment.
Using the TD Console, obtain your write only API Key. For example:
Locate and open the HTML files of the web pages that you want to have tracked for your real-time segmentation.
Add the following code to the header (<head>) of each of the pages that you want to track.
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.
Optionally, set custom parameters.
Optionally, track custom events. For example, to track a button click add the following:
Optionally, track events individually. Be sure to comply with all necessary data collection and privacy policies if you choose to do this.
Setting Up a Master Segment to Use for Realtime Segmentation
The behavior table must be set up in the master segment for you to set up a real-time segment.
- Open TD Console
Select Data Workbench > Master Segments.
Select New Master Segment to create a new master segment or select an existing master segment.
Optionally, an Attribute table by clicking on the +.
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:
Define All columns for the Behavior table.
- Select Save.
Creating a Real-time Segment
You can choose a behavior and specify the scope of a time window for scanning.
- Open TD Console.
- Navigate to Audience Studio.
Select Segments & Funnels.
- Select the master profile that you defined for real-time segmentation.
Select Create Realtime Segment.
- Select Add Attributes (optional) or Add Behaviors to open the Rule Builder.
In the Rule Builder, optionally add rules for Profile Attributes.
Attributes are limited to 5 and 1000 bytes.
Add rules for Behaviors. Time Window must contain a value higher than 0.
- Select Save.
- Name the Realtime Segment and select the folder where you want to save and select Create.
Generating a Token
1. Navigate to Profiles > Profiles API Tokens.
2. Select New Token.
3. Enter a description for this token.
4. In the Attributes drop-down list, select the column names which the Profiles API token will return.
5. Select Add Segment.
6. Select Save.
Treasure Data automatically generates the Profile API Token.
Updating Segment Data
Post data using postback to the Behavior table. Using the following code:
replace the td_api_write_key
replace the database_name and behavior_table_name
replace <xxxxxxx> with name
Segment data will be refreshed.
Getting Segment Data