This guide is for developers who want to set up data tracking using the default data layer events supported by the Frosmo Platform. If your site has or is getting a basic feature setup from Frosmo, see the appropriate site preparation guide instead. Basic feature setups rely on their own dedicated data layer events. |
To use the data layer on a site, the data layer module must be enabled for the site. |
For an introduction to transactions and transaction tracking in the Frosmo Platform, see Data tracking overview.
Tracking transactions with the data layer means triggering a transaction event whenever a visitor successfully completes an action that qualifies as a transaction. The data you pass in the transaction event defines the transaction.
You can trigger transaction events from:
Page code is the recommended solution. If you cannot use the data layer in your page code, use shared code.
Figure: Tracking transactions by triggering a transaction event from a page (click to enlarge)
To trigger a transaction event, call the dataLayer.push()
function with a transaction object containing the transaction data:
dataLayer.push({ transactionProducts: [{ id: 'string', name: 'string', price: 0, sku: 'string', /* Optional */ quantity: 0 }], /* Optional */ transactionId: 'string', transactionTotal: 0 }); |
The transaction object contains the data of a single transaction event.
Table: Transaction object properties
Property | Description | Type | Role | |
---|---|---|---|---|
transactionId | Unique transaction ID.
| String (36) | Optional | |
transactionProducts | List of products purchased in the transaction. For more information about the product data, see the following table. | Array of transaction product objects | Required | |
transactionTotal | Total purchase value of the transaction. | Number | Optional |
Table: Transaction product object properties
Property | Description | Type | Role | |
---|---|---|---|---|
id | Product ID. The product ID is the same value you pass in the This property is optional if
| String (128) | Required | Optional | |
name | Product name. The product name is the same value you pass in the This property is optional if | String (128) | Required | Optional | |
price | Unit price used for the product in the transaction. | Number | Required | |
quantity | Number of items purchased in the transaction. | Number | Optional | |
sku | Stock keeping unit (SKU) code for the product. This property is optional if | String (128) | Required | Optional |
dataLayer.push({ transactionId: '1010101010', transactionProducts: [{ id: '123456', name: 'Cheetah Plushy', price: 9.99, quantity: 3 }] }); |
dataLayer.push({ transactionId: '1010101011', transactionProducts: [{ id: '123456', name: 'Cheetah Plushy', price: 9.99, quantity: 3 }, { id: '123457', name: 'Lion Plushy', price: 19.99, quantity: 2 }] }); |
For instructions on how to test that transactions are correctly tracked on a site, see Testing data tracking.