Pages

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 36 Next »

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 (meaning directly from your site source code)
  • Shared code

Page code is the recommended solution. If you cannot use the data layer in your page code, use shared code.

Tracking transactions by triggering a transaction event from a page

Figure: Tracking transactions by triggering a transaction event from a page (click to enlarge)

Triggering transaction events

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
});

Transaction object

The transaction object contains the data of a single transaction event.

Table: Transaction object properties

PropertyDescriptionTypeRole
transactionId

Unique transaction ID.

The platform registers a transaction with a given ID only once. If you trigger a transaction event with the same ID multiple times, the platform ignores all but the first event.

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 objectsRequired
transactionTotalTotal purchase value of the transaction.NumberOptional

Table: Transaction product object properties

PropertyDescriptionTypeRole
id

Product ID.

The product ID is the same value you pass in the id property of a product object when tracking products.

This property is optional if name or sku is defined. You must define at least one of the three.

If you do not use the proper product ID as the property value, the platform has no way of mapping the purchased product to the corresponding product in the Frosmo product database. For example, if you wanted to create a product recommendation based on the transactions, the recommendation engine would not be able to map the purchased products to tracked products and would therefore fail to return the product data for the transactions.

String (128)Required | Optional
name

Product name.

The product name is the same value you pass in the name property of a product object when tracking products.

This property is optional if id or sku is defined. You must define at least one of the three.

String (128)Required | Optional
priceUnit price used for the product in the transaction.NumberRequired
quantityNumber of items purchased in the transaction.NumberOptional
sku

Stock keeping unit (SKU) code for the product.

This property is optional if id or name is defined. You must define at least one of the three.

String (128)Required | Optional

Transaction examples

Example: Triggering a transaction event with one product
dataLayer.push({
    transactionId: '1010101010',
    transactionProducts: [{
        id: '123456',
        name: 'Cheetah Plushy',
        price: 9.99,
        quantity: 3
    }]
});
Example: Triggering a transaction event with two products
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
    }]
});

Testing transaction tracking

To test that transactions are correctly tracked with the data layer:

  1. Go to the site.
  2. Launch Frosmo Preview.
  3. Select Advanced > Events.

    Testing transaction tracking

  4. Go to a page where transactions are tracked. If transaction events are successfully triggered with the data layer, Frosmo Preview shows the following messages for each event:

    • conversion (contains the transaction data parsed from the transaction object)
    • product.purchase (contains the ID and price for a single purchased product item)
    • dataLayer (contains the object passed to the data layer)
    • trigger.event (contains information about the triggered event, including the object passed to the data layer)

    Testing transaction tracking

    Transaction events log a dedicated product.purchase message for each individual purchased item. For example:

    • If a transaction contains three copies of one product, the transaction event logs three product.purchase messages.
    • If a transaction contains three copies of one product and two copies of another product, the transaction event logs five product.purchase messages.
  5. To verify that the correct transaction data was sent, check the conversion message.

    Testing transaction tracking

  6. If you want more details on a data layer call, select the Advanced > Requests view in Frosmo Preview, and check the transaction request to the Optimizer API.

    Testing transaction tracking