Tracks an event for the current user
Events (also known as activities) are used to indicate that one of your site's visitors performed a particular action. These events will appear in that user's profile as recent history and can be used to create behaviors for triggers and segmentation within the Zeta Marketing Platform. As well, these events act as signals for Zeta's personalization systems to generate insights and predictive recommendations for your campaigns.
Event tracks are non-blocking JavaScript calls.
bt('track', eventType, properties, settings={});
The track
call has the following fields:
Field | Type | Description |
---|---|---|
eventType | String | The name of the event, e.g. "viewed", "liked", "shared". |
properties | Object | A JSON object containing key:value pairs indicating properties to be tracked as metadata in this event. See Properties below for more information. An empty JSON object {} should be provided if there are no properties to be tracked with the event. |
settings optional | Object | Settings specific to this event. Currently supports specification of onComplete , onSuccess , and onFailure callback functions. See Settings below for more information. |
Automatically-Populated Properties
The following properties will be populated automatically with each event, but may be overridden with values that you specify.
Property | Type | Description |
---|---|---|
id | String | By default uses the current page as the viewed resource. |
resourceType | String | By default uses the resource type of the current page as the viewed resource's type. |
url | String | By default uses the current page's URL. |
modDate | ISO-8601 Timestamp String or Epoch Time in seconds or milliseconds | By default uses the current page's modification date. If provided, must be an ISO-8601 timestamp or the epoch time. |
Event Types
While you may specify any eventType
, a few are standardized and specially handled by Zeta's systems. Also note that certain eventType
s will use properties in a special way:
Viewing a Page or Resource
eventType: viewed
Indicates a user has viewed a page. Automatically triggered on page load when autoTrack
is on (as it is by default). See Getting Started for full details.
bt('track', 'viewed', {});
bt('track',
'viewed',
{id: 'yourId', resourceType: 'yourResourceType', url: 'https://example.com'}
);
Completing a Purchase
eventType: purchased
Indicates completion of a transaction in which the user has purchased one or more products.
purchased
events must contain a top-level property called shoppingCartItems
. This property must be formatted as an array of JSON objects representing purchased items.
Each element of shoppingCartItems
must have the following properties:
id
: A string representing the ID of the item being purchased.
resourceType
: A string representing the resource type for this item.
price
: A number representing the price of this item.
quantity
: A number representing the quantity of this item purchased.
Note that shoppingCartItems
may contain other properties with any additional JSON data as well.
bt('track',
'purchased',
{
shoppingCartItems: [
{id: 1234, resourceType: 'myProduct', price: 1.25, quantity: 2},
{id: 2345, resourceType: 'myProduct', price: 2.8, quantity: 1, sale_discount: 0.90}
],
promoCode: 'StRSiTb'
}
);
Updating a Shopping Cart
eventType: updated_cart
Indicates the user has made a change to an item or a set of items in their shopping cart.
updated_cart
events must contain a top-level property called shoppingCartItems
. This property must be formatted as an array of JSON objects representing all items now in the user's cart.
Each element of shoppingCartItems
must have the following properties:
id
: A string representing the ID of the item.
resourceType
: A string representing the resource type for the item.
price
: A number representing the price of this item.
quantity
: A number representing the quantity of this item now in the cart.
Note that shoppingCartItems
may contain other properties with any additional JSON data as well.
bt('track',
'updated_cart',
{
shoppingCartItems: [
{id: 1234, resourceType: 'myProduct', price: 1.25, quantity: 2},
{id: 2345, resourceType: 'myProduct', price: 2.8, quantity: 1, sale_discount: 0.90}
],
promoCode: 'StRSiTb'
}
);
Signing Up
eventType: signed_up
Tracks that the user has signed up for an email newsletter, signed up for an account, or any other event that signifies a "new" user.
This track type will automatically execute an updateUser
call with each of the given properties before tracking the event. See Update a User for more details).
At least one of the two following properties must be provided:
Property | Type | Description |
---|---|---|
email | String | A string representing the new user's email address. |
user_id | String | A string representing a consistent primary identifier for this user. |
bt('track',
'signed_up',
{user_id: 'sample-user'}
);
bt('track',
'signed_up',
{
email: '[email protected]',
newsletter: 'My Newsletter',
frequency: 'Weekly',
first_name: 'John',
last_name: 'Smith'
},
);
bt('track',
'signed_up',
{email: '[email protected]'}
);
Executing a Search
eventType: searched
Tracks that the user has executed a search on your website.
The following properties should be provided in a searched
event when available:
Property | Type | Description |
---|---|---|
query | String | A string representing what the user searched for in a search text field. |
bt('track',
'searched',
{query: 'iPhone X'}
);
Liking or Rating a Page or Resource
eventType:liked
Indicates an explicit preference or rating for the specified page/resource by the user.
The following properties should be provided in a liked
event when available:
Property | Type | Description |
---|---|---|
score | Number | When the event indicates a rating on a multi-point scale, provide an integer representation of the value provided. If the action indicated is a "dislike" or negative preference use -1 . |
minScore | Number | When the event indicates a rating on a multi-point scale, provide an integer that represents the minimum rating possible. If not specified, minimum score is assumed to be 1 . |
maxScore | Number | When the event indicates a rating on a multi-point scale, provide an integer that represents the maximum rating possible. |
to | String | A string representing the service or external destination of the share, for example, "facebook" or "twitter" |
bt('track',
'liked',
{}
);
bt('track',
'liked',
{id: 'your_id', resourceType: 'article', url: 'https://example.com'}
);
bt('track',
'liked',
{'score': -1}
);
bt('track',
'liked',
{'score': 3, 'minScore': 1, 'maxScore': 5}
);
bt('track',
'liked',
{to: 'facebook'}
);
Sharing a Page or Resource
eventType:shared
Indicates a user has shared the specified page/resource with another user.
The following properties should be provided in a shared
event when available:
Property | Type | Description |
---|---|---|
target_user_ids | Array | A list of Strings representing the User IDs of the target users for the share. |
to | String | A string representing the service or external destination of the share, for example, "facebook" or "twitter" |
bt('track',
'shared',
{}
);
bt('track',
'shared',
{id: 'yourId', resourceType: 'yourResourceType', url: 'https://example.com'}
);
bt('track',
'shared',
{'target_user_ids': ['sample-target-user-1', 'sample-target-user-2']}
);
bt('track',
'shared',
{'target_user_ids': ['sample-target-user-1', 'sample-target-user-2']},
{id: 'yourId', resourceType: 'yourResourceType', url: 'https://example.com'}
);
bt('track',
'shared',
{to: 'facebook'}
);
Commenting on a Page or Resource
eventType:commented
Indicates a user has commented on the specified page/resource.
The following properties should be provided in a commented
event when available:
Property | Type | Description |
---|---|---|
commentText | String | The text of the comment |
bt('track',
'commented',
{'commentText': 'This is my comment.' }
);
Properties
Provided properties will be added as metadata on the tracked event.
While properties can have any form, the following property names are reserved and may not be used:
enriched
, event_id
, geolocation
, http_method
, identified
, identity
, is_bot
, is_test
, properties
, referer
, status
, user_agent
, href
, bsin
If an event is tracked with any of these property names specified, the specified property may be discarded.
Settings
The settings
object is used for configuring the track
call.
Object | Description |
---|---|
onComplete | This setting allows the caller to specify a callback function once the track function has completed. The function will be called regardless of whether the track was successful or not. The function should have no parameters (nothing will be passed to it). |
onFailure(error) | This setting allows the caller to specify a callback function if the track function has completed with an error. The error raised by the track function will be passed into this callback. |
onSuccess | This setting allows the caller to specify a callback function once the track function has completed successfully. The function should have no parameters (nothing will be passed to it). |
bt('track',
'viewed',
{id: 'abcde123', resourceType: 'article'},
{onComplete: function()
{ console.log('Track Call Completed!'); }
}
);
bt('track',
'viewed',
{id: 'abcde123', resourceType: 'article'},
{onFailure: function(err)
{ console.log('Track Call Failed!: ' + err); }
}
);
bt('track',
'viewed',
{id: 'abcde123', resourceType: 'article'},
{onSuccess: function()
{ console.log('Track Call Succeeded!'); }
}
);
Signing Up using LIVE ID Graph
Please see this page for more information regarding the LIVE ID Graph before getting started
eventType: signed_up
Tracks that the user has signed up for an email newsletter, signed up for an account, or any other event that signifies a "new" user.
This track type will automatically execute an updateUser
call with each of the given properties before tracking the event. See Update a User for more details).
At least one of the two following properties must be provided:
Property | Type | Description |
---|---|---|
email | String | A string representing the new user's email address. |
user_id | String | A string representing a consistent primary identifier for this user. |
unique_client_ids | Object | An object containing name and value . Where name will be the key for the value of the already configured identifier name, and value will be the key for the value of the identifier tied to this profile |
bt('track',
'signed_up',
{"unique_client_id":{"name":"subscriber_id", "value":"A00001"}}
);
bt('track',
'signed_up',
{"unique_client_id":
{"name":"subscriber_id", "value":"A00001"},
"newsletter": "My Newsletter",
"frequency": "Weekly",
"first_name": "John",
"last_name": "Smith"
},
);
bt('track',
'signed_up',
{"unique_client_id":
{"name":"subscriber_id", "value":"A00001"},
"email":"[email protected]"
}
);