Time-Based Filters - Attribute & Behavior
Because marketers want to define segments based on a timestamp, you might need to create attribute and behavior filters based on time when creating segments. You can use time filters in conjunction with other attributes or behaviors.
Examples of segments include:
- Profiles whose order date was in the past 3 months
- Profiles who visited the website between 1-2 years ago
- Profiles whose renewal date is within 30 days
How to Set up Time Filters
Data Type Supported
Only long type columns (Unix time) are supported as time filters. For example, your long type column might look like this:
“user_registrations”.”registered_at”
Steps to Configure Time Filter
- Determine which columns in a parent segment should contain timestamps. Communicate this information to a Customer Support representative.
- Convert any string-based timestamps to Unix Time (long type).
- Use the following API calls to configure column types.
- Use API to change column type from long to timestamp type
Perform a GET request on a parent segment where attribute
/behavior
column/s with Unix timestamp format data is present and time filter usage is intended.
curl -I -X GET \
https://api-cdp.treasuredata.com/audiences/<master segment id>
{
"id": "43356",
"name": "ms_hive2_tez",
"description": "",
"scheduleType": "none",
"scheduleOption": null,
"timezone": "UTC",
"createdAt": "2021-05-24T20:36:29.369Z",
"updatedAt": "2021-06-03T17:48:34.969Z",
"createdBy": {
"id": "23",
"name": "aaaaaaa"
},
"updatedBy": {
"id": "23",
"name": "aaaaaaa"
},
"matrixUpdatedAt": "2021-06-04T00:56:25.526Z",
"workflowHiveOnly": false,
"hiveEngineVersion": "0.13",
"hivePoolName": null,
"prestoPoolName": null,
"population": 1004,
"rootFolderId": "103977",
"master": {
"parentDatabaseName": "cdp_dashboard_test_db1",
"parentTableName": "master"
},
"attributes": [
{
"audienceId": "43356",
"id": "45709",
"name": "payment",
"type": "number",
"parentDatabaseName": "cdp_dashboard_test_db1",
"parentTableName": "purchases",
"parentColumn": "payment",
"parentKey": "td_client_id",
"foreignKey": "td_client_id",
"matrixColumnName": "payment"
},
{
"audienceId": "43356",
"id": "45710",
"name": "purchase_time", Attribute column with Unix timestamp format data
"type": "number", It will be of number datatype
"parentDatabaseName": "cdp_dashboard_test_db1",
"parentTableName": "purchases",
"parentColumn": "purchase_time",
"parentKey": "td_client_id",
"foreignKey": "td_client_id",
"matrixColumnName": "purchase_time"
}
],
"behaviors": [
{
"audienceId": "43356",
"id": "31836",
"name": "behaviors",
"parentDatabaseName": "cdp_dashboard_test_db1",
"parentTableName": "pageview_with_date_column",
"parentKey": "td_client_id",
"foreignKey": "td_client_id",
"matrixDatabaseName": "cdp_audience_43356",
"matrixTableName": "behavior_pageview_with_date_column",
"allColumns": false, Make sure on Master Segment Config user selects
each behavior individually instead of selecting all,
So they can easily update type for the behavior (for
which time filter usage is intended)
"scheduleType": "none",
"scheduleOption": null,
"schema": [
{
"name": "category",
"type": "string",
"parentColumn": "category",
"matrixColumnName": "category"
},
{
"name": "datetime_viewed", Behavior column with Unix timestamp format data
"type": "number", It will be of number datatype
"parentColumn": "datetime_viewed",
"matrixColumnName": "datetime_viewed"
},
{
"name": "product_name",
"type": "string",
"parentColumn": "product_name",
"matrixColumnName": "product_name"
},
{
"name": "td_browser",
"type": "string",
"parentColumn": "td_browser",
"matrixColumnName": "td_browser"
},
{
"name": "td_client_id",
"type": "string",
"parentColumn": "td_client_id",
"matrixColumnName": "td_client_id"
},
{
"name": "td_os",
"type": "string",
"parentColumn": "td_os",
"matrixColumnName": "td_os"
},
{
"name": "td_global_id",
"type": "string",
"parentColumn": "td_global_id",
"matrixColumnName": "td_global_id"
}
]
}
]
}
To get a time filter to use for the attribute
and behavior
highlighted above, run the GET /audiences call, then edit the response object and change the type
for the attribute
and behavior
to timestamp
. Then use the edited response object as the request object for the the PUT /audiences call.
curl -I -X PUT \
https://api-cdp.treasuredata.com/audiences/<master segment id>
{
"id": "43356",
"name": "ms_hive2_tez",
"description": "",
"scheduleType": "none",
"scheduleOption": null,
"timezone": "UTC",
"createdAt": "2021-05-24T20:36:29.369Z",
"updatedAt": "2021-06-03T17:48:34.969Z",
"createdBy": {
"id": "23",
"name": "aaaaaaa"
},
"updatedBy": {
"id": "23",
"name": "aaaaaaa"
},
"matrixUpdatedAt": "2021-06-04T00:56:25.526Z",
"workflowHiveOnly": false,
"hiveEngineVersion": "0.13",
"hivePoolName": null,
"prestoPoolName": null,
"population": 1004,
"rootFolderId": "103977",
"master": {
"parentDatabaseName": "cdp_dashboard_test_db1",
"parentTableName": "master"
},
"attributes": [
{
"audienceId": "43356",
"id": "45709",
"name": "payment",
"type": "number",
"parentDatabaseName": "cdp_dashboard_test_db1",
"parentTableName": "purchases",
"parentColumn": "payment",
"parentKey": "td_client_id",
"foreignKey": "td_client_id",
"matrixColumnName": "payment"
},
{
"audienceId": "43356",
"id": "45710",
"name": "purchase_time",
"type": "timestamp",
"parentDatabaseName": "cdp_dashboard_test_db1",
"parentTableName": "purchases",
"parentColumn": "purchase_time",
"parentKey": "td_client_id",
"foreignKey": "td_client_id",
"matrixColumnName": "purchase_time"
}
],
"behaviors": [
{
"audienceId": "43356",
"id": "31836",
"name": "behaviors",
"parentDatabaseName": "cdp_dashboard_test_db1",
"parentTableName": "pageview_with_date_column",
"parentKey": "td_client_id",
"foreignKey": "td_client_id",
"matrixDatabaseName": "cdp_audience_43356",
"matrixTableName": "behavior_pageview_with_date_column",
"allColumns": false,
"scheduleType": "none",
"scheduleOption": null,
"schema": [
{
"name": "category",
"type": "string",
"parentColumn": "category",
"matrixColumnName": "category"
},
{
"name": "datetime_viewed",
"type": "timestamp",
"parentColumn": "datetime_viewed",
"matrixColumnName": "datetime_viewed"
},
{
"name": "product_name",
"type": "string",
"parentColumn": "product_name",
"matrixColumnName": "product_name"
},
{
"name": "td_browser",
"type": "string",
"parentColumn": "td_browser",
"matrixColumnName": "td_browser"
},
{
"name": "td_client_id",
"type": "string",
"parentColumn": "td_client_id",
"matrixColumnName": "td_client_id"
},
{
"name": "td_os",
"type": "string",
"parentColumn": "td_os",
"matrixColumnName": "td_os"
},
{
"name": "td_global_id",
"type": "string",
"parentColumn": "td_global_id",
"matrixColumnName": "td_global_id"
}
]
}
]
}
Now the user should be able to use time filters on the attribute
purchase_time
and the behavior
datetime_viewed
on Audience Studio for the same parent segment (make sure the parent segment has been moved from Audience Studio Legacy).