{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"Track an Event","type":"fn","slug":"track-event","excerpt":"Tracks an event for the current user","body":"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.\n\nEvent tracks are non-blocking JavaScript calls.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"bt('track', eventType, properties, settings={});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThe `track` call has the following fields:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Field\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"`eventType`\",\n    \"0-1\": \"String\",\n    \"0-2\": \"The name of the event, e.g. \\\"viewed\\\", \\\"liked\\\", \\\"shared\\\".\",\n    \"1-0\": \"`properties`\",\n    \"1-1\": \"Object\",\n    \"1-2\": \"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.\",\n    \"2-0\": \"`settings` **optional**\",\n    \"2-1\": \"Object\",\n    \"2-2\": \"Settings specific to this event. Currently supports specification of `onComplete`, `onSuccess`, and `onFailure` callback functions. See Settings below for more information.\",\n    \"h-1\": \"Type\"\n  },\n  \"cols\": 3,\n  \"rows\": 3\n}\n[/block]\n#Automatically-Populated Properties\nThe following properties will be populated automatically with each event, but may be overridden with values that you specify.\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Property\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-2\": \"By default uses the current page as the viewed resource.\",\n    \"0-0\": \"`id`\",\n    \"0-1\": \"String\",\n    \"1-0\": \"`resourceType`\",\n    \"1-2\": \"By default uses the resource type of the current page as the viewed resource's type.\",\n    \"2-2\": \"By default uses the current page's URL.\",\n    \"3-2\": \"By default uses the current page's modification date. If provided, must be an ISO-8601 timestamp or the epoch time.\",\n    \"3-1\": \"ISO-8601 Timestamp String or Epoch Time in seconds or milliseconds\",\n    \"2-0\": \"`url`\",\n    \"3-0\": \"`modDate`\",\n    \"2-1\": \"String\",\n    \"1-1\": \"String\"\n  },\n  \"cols\": 3,\n  \"rows\": 4\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Event Types\"\n}\n[/block]\nWhile 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:\n\n#Viewing a Page or Resource\n**eventType:** `viewed`\n\nIndicates a user has viewed a page. Automatically triggered on page load when `autoTrack` is on (as it is by default). See [Getting Started](doc:p13njs-getting-started) for full details.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"bt('track', 'viewed', {});\",\n      \"language\": \"javascript\",\n      \"name\": \"Viewing Current Page\"\n    },\n    {\n      \"code\": \"bt('track', \\n   'viewed', \\n   {id: 'yourId', resourceType: 'yourResourceType', url: 'https://example.com'}\\n  );\",\n      \"language\": \"javascript\",\n      \"name\": \"Viewing a Resource (Not Current Page)\"\n    }\n  ]\n}\n[/block]\n#Completing a Purchase\n**eventType:** `purchased`\n\nIndicates completion of a transaction in which the user has purchased one or more products.\n\n`purchased` events **must** contain a top-level property called `shoppingCartItems`.  This property must be formatted as an array of JSON objects representing purchased items. \n\nEach element of `shoppingCartItems` must have the following properties:\n\n`id`: A string representing the ID of the item being purchased.\n`resourceType`:  A string representing the resource type for this item.\n`price`: A number representing the price of this item.\n`quantity`: A number representing the quantity of this item purchased.\n\nNote that `shoppingCartItems` may contain other properties with any additional JSON data as well.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"bt('track', \\n   'purchased', \\n   {\\n  \\tshoppingCartItems: [ \\n     {id: 1234, resourceType: 'myProduct', price: 1.25, quantity: 2}, \\n     {id: 2345, resourceType: 'myProduct', price: 2.8, quantity: 1, sale_discount: 0.90}\\n   \\t], \\n    promoCode: 'StRSiTb'\\n   }\\n  );\",\n      \"language\": \"javascript\",\n      \"name\": \"Completing a Purchase\"\n    }\n  ]\n}\n[/block]\n#Updating a Shopping Cart\n**eventType:** `updated_cart`\n\nIndicates the user has made a change to an item or a set of items in their shopping cart.\n\n`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. \n\nEach element of `shoppingCartItems` must have the following properties:\n\n`id`: A string representing the ID of the item.\n`resourceType`:  A string representing the resource type for the item.\n`price`: A number representing the price of this item.\n`quantity`: A number representing the quantity of this item now in the cart.\n\nNote that `shoppingCartItems` may contain other properties with any additional JSON data as well.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"bt('track', \\n   'updated_cart', \\n   {\\n  \\tshoppingCartItems: [ \\n     {id: 1234, resourceType: 'myProduct', price: 1.25, quantity: 2}, \\n     {id: 2345, resourceType: 'myProduct', price: 2.8, quantity: 1, sale_discount: 0.90}\\n    ], \\n  \\tpromoCode: 'StRSiTb'\\n\\t }\\n  );\",\n      \"language\": \"json\",\n      \"name\": \"Updating a Shopping Cart\"\n    }\n  ]\n}\n[/block]\n#Signing Up\n**eventType:** `signed_up`\nTracks that the user has signed up for an email newsletter, signed up for an account, or any other event that signifies a \"new\" user.\n\nThis track type will automatically execute an `updateUser` call with each of the given properties _before_ tracking the event. See [Update a User](doc:update-user) for more details).\n\nAt least one of the two following properties *must* be provided:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Property\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"`email`\",\n    \"1-0\": \"`user_id`\",\n    \"0-1\": \"String\",\n    \"1-1\": \"String\",\n    \"0-2\": \"A string representing the new user's email address.\",\n    \"1-2\": \"A string representing a consistent primary identifier for this user.\"\n  },\n  \"cols\": 3,\n  \"rows\": 2\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"bt('track', \\n   'signed_up', \\n   {user_id: 'sample-user'}\\n  );\",\n      \"language\": \"javascript\",\n      \"name\": \"Signing Up with User ID\"\n    },\n    {\n      \"code\": \"bt('track', \\n   'signed_up', \\n   {\\n  \\temail: 'user:::at:::example.com',\\n    newsletter: 'My Newsletter',\\n    frequency: 'Weekly',\\n    first_name: 'John',\\n    last_name: 'Smith'\\n\\t },\\n  );\",\n      \"language\": \"json\",\n      \"name\": \"Signing Up with Additional User Attributes\"\n    },\n    {\n      \"code\": \"bt('track', \\n   'signed_up', \\n   {email: '[email protected]'}\\n  );\",\n      \"language\": \"json\",\n      \"name\": \"Signing Up with Email\"\n    }\n  ]\n}\n[/block]\n#Executing a Search\n**eventType**: `searched`\n\nTracks that the user has executed a search on your website.\n\nThe following properties should be provided in a `searched` event when available:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Property\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"`query`\",\n    \"0-1\": \"String\",\n    \"0-2\": \"A string representing what the user searched for in a search text field.\"\n  },\n  \"cols\": 3,\n  \"rows\": 1\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"bt('track', \\n   'searched', \\n   {query: 'iPhone X'}\\n\\t);\",\n      \"language\": \"json\",\n      \"name\": \"Executing a Search\"\n    }\n  ]\n}\n[/block]\n#Liking or Rating a Page or Resource\n**eventType:**`liked`\n\nIndicates an explicit preference or rating for the specified page/resource by the user.\n\nThe following properties should be provided in a `liked` event when available:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Property\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-2\": \"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`.\",\n    \"0-1\": \"Number\",\n    \"0-0\": \"`score`\",\n    \"1-0\": \"`minScore`\",\n    \"2-0\": \"`maxScore`\",\n    \"1-1\": \"Number\",\n    \"2-1\": \"Number\",\n    \"1-2\": \"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`.\",\n    \"2-2\": \"When the event indicates a rating on a multi-point scale, provide an integer that represents the maximum rating possible.\",\n    \"3-0\": \"`to`\",\n    \"3-1\": \"String\",\n    \"3-2\": \"A string representing the service or external destination of the share, for example, \\\"facebook\\\" or \\\"twitter\\\"\"\n  },\n  \"cols\": 3,\n  \"rows\": 4\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"bt('track',\\n   'liked',\\n   {}\\n);\",\n      \"language\": \"javascript\",\n      \"name\": \"Liking Current Page\"\n    },\n    {\n      \"code\": \"bt('track', \\n   'liked', \\n   {id: 'your_id', resourceType: 'article', url: 'https://example.com'}\\n  );\",\n      \"language\": \"javascript\",\n      \"name\": \"Liking a Specific Resource\"\n    },\n    {\n      \"code\": \"bt('track',\\n   'liked',\\n   {'score': -1}\\n);\",\n      \"language\": \"javascript\",\n      \"name\": \"Disliking Current Page\"\n    },\n    {\n      \"code\": \"bt('track',\\n   'liked',\\n   {'score': 3, 'minScore': 1, 'maxScore': 5}\\n);\",\n      \"language\": \"json\",\n      \"name\": \"Rating Current Page as 3 out of 5\"\n    },\n    {\n      \"code\": \"bt('track',\\n   'liked',\\n   {to: 'facebook'}\\n);\",\n      \"language\": \"json\",\n      \"name\": \"Liking the Current Page on Facebook\"\n    }\n  ]\n}\n[/block]\n#Sharing a Page or Resource\n**eventType:**`shared`\n\nIndicates a user has shared the specified page/resource with another user.\n\nThe following properties should be provided in a `shared` event when available:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Property\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"`target_user_ids`\",\n    \"0-1\": \"Array\",\n    \"0-2\": \"A list of Strings representing the User IDs of the target users for the share.\",\n    \"1-0\": \"`to`\",\n    \"1-1\": \"String\",\n    \"1-2\": \"A string representing the service or external destination of the share, for example, \\\"facebook\\\" or \\\"twitter\\\"\"\n  },\n  \"cols\": 3,\n  \"rows\": 2\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"bt('track',\\n   'shared',\\n   {}\\n  );\",\n      \"language\": \"javascript\",\n      \"name\": \"Sharing Current Page\"\n    },\n    {\n      \"code\": \"bt('track', \\n   'shared', \\n   {id: 'yourId', resourceType: 'yourResourceType', url: 'https://example.com'}\\n  );\",\n      \"language\": \"json\",\n      \"name\": \"Sharing a Specified Resource\"\n    },\n    {\n      \"code\": \"bt('track',\\n   'shared',\\n   {'target_user_ids': ['sample-target-user-1', 'sample-target-user-2']}\\n  );\",\n      \"language\": \"json\",\n      \"name\": \"Sharing Current Page to Specific Users\"\n    },\n    {\n      \"code\": \"bt('track',\\n   'shared',\\n   {'target_user_ids': ['sample-target-user-1', 'sample-target-user-2']},\\n   {id: 'yourId', resourceType: 'yourResourceType', url: 'https://example.com'}\\n  );\",\n      \"language\": \"json\",\n      \"name\": \"Sharing a Specified Resource to Specific Users\"\n    },\n    {\n      \"code\": \"bt('track',\\n   'shared',\\n   {to: 'facebook'}\\n  );\",\n      \"language\": \"json\",\n      \"name\": \"Sharing the Current Page to Facebook\"\n    }\n  ]\n}\n[/block]\n#Commenting on a Page or Resource\n**eventType:**`commented`\n\nIndicates a user has commented on the specified page/resource.\n\nThe following properties should be provided in a `commented` event when available:\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Property\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"`commentText`\",\n    \"0-1\": \"String\",\n    \"0-2\": \"The text of the comment\"\n  },\n  \"cols\": 3,\n  \"rows\": 1\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"bt('track',\\n   'commented',\\n   {'commentText': 'This is my comment.' }\\n  );\",\n      \"language\": \"json\",\n      \"name\": \"Commenting on the Current Page\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Properties\"\n}\n[/block]\nProvided properties will be added as metadata on the tracked event.\n\nWhile properties can have any form, the following property names are reserved and may not be used:\n\n`enriched`, `event_id`, `geolocation`, `http_method`, `identified`, `identity`, `is_bot`, `is_test`, `properties`, `referer`, `status`, `user_agent`, `href`, `bsin`\n\nIf an event is tracked with any of these property names specified, the specified property may be discarded.\n[block:api-header]\n{\n  \"title\": \"Settings\"\n}\n[/block]\nThe `settings` object is used for configuring the `track` call.\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Object\",\n    \"h-1\": \"Description\",\n    \"0-0\": \"`onComplete`\",\n    \"1-0\": \"`onFailure(error)`\",\n    \"2-0\": \"`onSuccess`\",\n    \"0-1\": \"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).\",\n    \"1-1\": \"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.\",\n    \"2-1\": \"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).\"\n  },\n  \"cols\": 2,\n  \"rows\": 3\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"bt('track', \\n   'viewed', \\n   {id: 'abcde123', resourceType: 'article'}, \\n   {onComplete: function() \\n   { console.log('Track Call Completed!'); }\\n   }\\n  );\",\n      \"language\": \"javascript\",\n      \"name\": \"onComplete Example\"\n    },\n    {\n      \"code\": \"bt('track', \\n   'viewed', \\n   {id: 'abcde123', resourceType: 'article'}, \\n   {onFailure: function(err) \\n   { console.log('Track Call Failed!: ' + err); }\\n   }\\n  );\",\n      \"language\": \"javascript\",\n      \"name\": \"onFailure Example\"\n    },\n    {\n      \"code\": \"bt('track', \\n   'viewed', \\n   {id: 'abcde123', resourceType: 'article'}, \\n   {onSuccess: function() \\n   { console.log('Track Call Succeeded!'); }\\n   }\\n  );\",\n      \"language\": \"javascript\",\n      \"name\": \"onSuccess Example\"\n    }\n  ]\n}\n[/block]","updates":[],"order":1,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5a9052757e447d0032d25946","project":"56aff08c3a5b810d00745d99","version":{"version":"1","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["56aff08d3a5b810d00745d9d","56aff24f3a5b810d00745da0","56aff25dbc304a0d00ace207","56aff287e0b1e40d00c53798","56aff2b260a37a0d00ed8883","56aff2b8e0b1e40d00c53799","56aff2bd5b1f01170014dc7b","56aff2c9d21e9c0d00b62993","56aff493aef9a21700da0e67","56aff4ce1486990d009c0f64","56aff4da5b1f01170014dc7d","56aff4dfe0b1e40d00c537a2","56aff4e59d32e30d0006d3e9","56aff4e91486990d009c0f65","56aff4f93a5b810d00745da2","56aff4fe9d32e30d0006d3ea","56b91c7ab1e03e0d001057c5","56c4f51aba4a540d0091b9a2","56cd09488c4a331d002c1e44","56d4ec4773dcd20b00fb8769","56e79bc515f96b2200878e54","56ec25c538ff1d2200d56cc2","56ec3a6f36bc8e0e00f190c8","56ec3e308ea7ce0e00a3d8b0","5724d8fe4255580e005938b2","5724dc842ad0bc1700122803","5776ef2a04f7500e0095dc37","57ab9f70b5e8742000e17eb9","57d7117646dcc30e007dd21f","58e6abd5b1eece19008b7d31","59288c65e2653627003e1221","5a8f4797a44f8600128e75ee","5bbf8833eb416300039a2c14","5ea811617bf4b5007328a0af"],"_id":"56aff08c3a5b810d00745d9c","project":"56aff08c3a5b810d00745d99","releaseDate":"2016-02-01T23:55:56.544Z","__v":34,"createdAt":"2016-02-01T23:55:56.544Z"},"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Zeta JavaScript Library","slug":"zetahub-javascript-library","order":1,"from_sync":false,"reference":false,"_id":"5a8f4797a44f8600128e75ee","project":"56aff08c3a5b810d00745d99","version":"56aff08c3a5b810d00745d9c","createdAt":"2018-02-22T22:43:35.027Z","__v":0},"user":"566887ff8639090d00759415","createdAt":"2018-02-23T17:42:13.022Z","githubsync":"","__v":0,"parentDoc":null}

Track an Event

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. [block:code] { "codes": [ { "code": "bt('track', eventType, properties, settings={});", "language": "javascript" } ] } [/block] The `track` call has the following fields: [block:parameters] { "data": { "h-0": "Field", "h-2": "Description", "0-0": "`eventType`", "0-1": "String", "0-2": "The name of the event, e.g. \"viewed\", \"liked\", \"shared\".", "1-0": "`properties`", "1-1": "Object", "1-2": "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.", "2-0": "`settings` **optional**", "2-1": "Object", "2-2": "Settings specific to this event. Currently supports specification of `onComplete`, `onSuccess`, and `onFailure` callback functions. See Settings below for more information.", "h-1": "Type" }, "cols": 3, "rows": 3 } [/block] #Automatically-Populated Properties The following properties will be populated automatically with each event, but may be overridden with values that you specify. [block:parameters] { "data": { "h-0": "Property", "h-1": "Type", "h-2": "Description", "0-2": "By default uses the current page as the viewed resource.", "0-0": "`id`", "0-1": "String", "1-0": "`resourceType`", "1-2": "By default uses the resource type of the current page as the viewed resource's type.", "2-2": "By default uses the current page's URL.", "3-2": "By default uses the current page's modification date. If provided, must be an ISO-8601 timestamp or the epoch time.", "3-1": "ISO-8601 Timestamp String or Epoch Time in seconds or milliseconds", "2-0": "`url`", "3-0": "`modDate`", "2-1": "String", "1-1": "String" }, "cols": 3, "rows": 4 } [/block] [block:api-header] { "title": "Event Types" } [/block] 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](doc:p13njs-getting-started) for full details. [block:code] { "codes": [ { "code": "bt('track', 'viewed', {});", "language": "javascript", "name": "Viewing Current Page" }, { "code": "bt('track', \n 'viewed', \n {id: 'yourId', resourceType: 'yourResourceType', url: 'https://example.com'}\n );", "language": "javascript", "name": "Viewing a Resource (Not Current Page)" } ] } [/block] #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. [block:code] { "codes": [ { "code": "bt('track', \n 'purchased', \n {\n \tshoppingCartItems: [ \n {id: 1234, resourceType: 'myProduct', price: 1.25, quantity: 2}, \n {id: 2345, resourceType: 'myProduct', price: 2.8, quantity: 1, sale_discount: 0.90}\n \t], \n promoCode: 'StRSiTb'\n }\n );", "language": "javascript", "name": "Completing a Purchase" } ] } [/block] #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. [block:code] { "codes": [ { "code": "bt('track', \n 'updated_cart', \n {\n \tshoppingCartItems: [ \n {id: 1234, resourceType: 'myProduct', price: 1.25, quantity: 2}, \n {id: 2345, resourceType: 'myProduct', price: 2.8, quantity: 1, sale_discount: 0.90}\n ], \n \tpromoCode: 'StRSiTb'\n\t }\n );", "language": "json", "name": "Updating a Shopping Cart" } ] } [/block] #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](doc:update-user) for more details). At least one of the two following properties *must* be provided: [block:parameters] { "data": { "h-0": "Property", "h-1": "Type", "h-2": "Description", "0-0": "`email`", "1-0": "`user_id`", "0-1": "String", "1-1": "String", "0-2": "A string representing the new user's email address.", "1-2": "A string representing a consistent primary identifier for this user." }, "cols": 3, "rows": 2 } [/block] [block:code] { "codes": [ { "code": "bt('track', \n 'signed_up', \n {user_id: 'sample-user'}\n );", "language": "javascript", "name": "Signing Up with User ID" }, { "code": "bt('track', \n 'signed_up', \n {\n \temail: '[email protected]',\n newsletter: 'My Newsletter',\n frequency: 'Weekly',\n first_name: 'John',\n last_name: 'Smith'\n\t },\n );", "language": "json", "name": "Signing Up with Additional User Attributes" }, { "code": "bt('track', \n 'signed_up', \n {email: '[email protected]'}\n );", "language": "json", "name": "Signing Up with Email" } ] } [/block] #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: [block:parameters] { "data": { "h-0": "Property", "h-1": "Type", "h-2": "Description", "0-0": "`query`", "0-1": "String", "0-2": "A string representing what the user searched for in a search text field." }, "cols": 3, "rows": 1 } [/block] [block:code] { "codes": [ { "code": "bt('track', \n 'searched', \n {query: 'iPhone X'}\n\t);", "language": "json", "name": "Executing a Search" } ] } [/block] #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: [block:parameters] { "data": { "h-0": "Property", "h-1": "Type", "h-2": "Description", "0-2": "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`.", "0-1": "Number", "0-0": "`score`", "1-0": "`minScore`", "2-0": "`maxScore`", "1-1": "Number", "2-1": "Number", "1-2": "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`.", "2-2": "When the event indicates a rating on a multi-point scale, provide an integer that represents the maximum rating possible.", "3-0": "`to`", "3-1": "String", "3-2": "A string representing the service or external destination of the share, for example, \"facebook\" or \"twitter\"" }, "cols": 3, "rows": 4 } [/block] [block:code] { "codes": [ { "code": "bt('track',\n 'liked',\n {}\n);", "language": "javascript", "name": "Liking Current Page" }, { "code": "bt('track', \n 'liked', \n {id: 'your_id', resourceType: 'article', url: 'https://example.com'}\n );", "language": "javascript", "name": "Liking a Specific Resource" }, { "code": "bt('track',\n 'liked',\n {'score': -1}\n);", "language": "javascript", "name": "Disliking Current Page" }, { "code": "bt('track',\n 'liked',\n {'score': 3, 'minScore': 1, 'maxScore': 5}\n);", "language": "json", "name": "Rating Current Page as 3 out of 5" }, { "code": "bt('track',\n 'liked',\n {to: 'facebook'}\n);", "language": "json", "name": "Liking the Current Page on Facebook" } ] } [/block] #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: [block:parameters] { "data": { "h-0": "Property", "h-1": "Type", "h-2": "Description", "0-0": "`target_user_ids`", "0-1": "Array", "0-2": "A list of Strings representing the User IDs of the target users for the share.", "1-0": "`to`", "1-1": "String", "1-2": "A string representing the service or external destination of the share, for example, \"facebook\" or \"twitter\"" }, "cols": 3, "rows": 2 } [/block] [block:code] { "codes": [ { "code": "bt('track',\n 'shared',\n {}\n );", "language": "javascript", "name": "Sharing Current Page" }, { "code": "bt('track', \n 'shared', \n {id: 'yourId', resourceType: 'yourResourceType', url: 'https://example.com'}\n );", "language": "json", "name": "Sharing a Specified Resource" }, { "code": "bt('track',\n 'shared',\n {'target_user_ids': ['sample-target-user-1', 'sample-target-user-2']}\n );", "language": "json", "name": "Sharing Current Page to Specific Users" }, { "code": "bt('track',\n 'shared',\n {'target_user_ids': ['sample-target-user-1', 'sample-target-user-2']},\n {id: 'yourId', resourceType: 'yourResourceType', url: 'https://example.com'}\n );", "language": "json", "name": "Sharing a Specified Resource to Specific Users" }, { "code": "bt('track',\n 'shared',\n {to: 'facebook'}\n );", "language": "json", "name": "Sharing the Current Page to Facebook" } ] } [/block] #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: [block:parameters] { "data": { "h-0": "Property", "h-1": "Type", "h-2": "Description", "0-0": "`commentText`", "0-1": "String", "0-2": "The text of the comment" }, "cols": 3, "rows": 1 } [/block] [block:code] { "codes": [ { "code": "bt('track',\n 'commented',\n {'commentText': 'This is my comment.' }\n );", "language": "json", "name": "Commenting on the Current Page" } ] } [/block] [block:api-header] { "title": "Properties" } [/block] 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. [block:api-header] { "title": "Settings" } [/block] The `settings` object is used for configuring the `track` call. [block:parameters] { "data": { "h-0": "Object", "h-1": "Description", "0-0": "`onComplete`", "1-0": "`onFailure(error)`", "2-0": "`onSuccess`", "0-1": "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).", "1-1": "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.", "2-1": "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)." }, "cols": 2, "rows": 3 } [/block] [block:code] { "codes": [ { "code": "bt('track', \n 'viewed', \n {id: 'abcde123', resourceType: 'article'}, \n {onComplete: function() \n { console.log('Track Call Completed!'); }\n }\n );", "language": "javascript", "name": "onComplete Example" }, { "code": "bt('track', \n 'viewed', \n {id: 'abcde123', resourceType: 'article'}, \n {onFailure: function(err) \n { console.log('Track Call Failed!: ' + err); }\n }\n );", "language": "javascript", "name": "onFailure Example" }, { "code": "bt('track', \n 'viewed', \n {id: 'abcde123', resourceType: 'article'}, \n {onSuccess: function() \n { console.log('Track Call Succeeded!'); }\n }\n );", "language": "javascript", "name": "onSuccess Example" } ] } [/block]