Skip to main content

Tracking custom actions with the data layer

note

To use the data layer on a site, the data layer module must be enabled for the site.

note

You can only track basic custom actions with the data layer. To track visitor geolocation with a custom action, create the action in the Frosmo Control Panel.

For an introduction to custom actions and custom action tracking in the Frosmo Platform, see Data tracking solutions. For more information about custom actions, see Feature: Custom action.

Tracking custom actions with the data layer means triggering a custom action event whenever a visitor successfully completes an action or enters a state that qualifies as a custom action. The data you pass in the custom action event (a name and a value) defines the custom action.

You can trigger custom action events from:

  • Page code (meaning directly from the 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 custom actions by triggering a custom action event from a page
Figure: Tracking custom actions by triggering a custom action event from a page

When you trigger a custom action event:

  • If the custom action does not exist in the database, meaning a custom action with the same name does not already exist in the database, the Frosmo Platform adds the event data (name and value) as a new custom action.

  • If a custom action with the same name already exists in the database, and if that name is not already associated with the passed value, the Frosmo Platform adds the value to the existing custom action.

  • If a custom action with the same name already exists in the database, and if that name is already associated with the passed value, the Frosmo Platform merely triggers the custom action event. The platform does not add any new event data to the database.

Triggering custom action events

To trigger a custom action event, call the dataLayer.push() function with a custom action object containing the custom action data:

dataLayer.push({
frosmoEvent: 'string',
frosmoValue: 'string'
});

Custom action object

The custom action object contains the data of a custom action event.

Custom action object properties
PropertyDescriptionTypeRole

frosmoEvent

Name of the custom action. The name uniquely identifies the custom action.

info

This property maps to the Name field of a custom action in the Frosmo Control Panel.

String (128)

Required

frosmoValue

Value of the custom action. The value is case-sensitive.

info

This property maps to a Value field of a custom action in the Frosmo Control Panel.

String (128)

Required

Custom action examples

Example: Triggering a custom action event
dataLayer.push({
frosmoEvent: 'Cookie policy accepted',
frosmoValue: 'true'
});
Example: Triggering a custom action event with a dynamic value
// Set the productCategory variable

dataLayer.push({
frosmoEvent: 'Product category',
frosmoValue: productCategory
});

Testing custom action tracking

To test that custom actions are correctly tracked with the data layer:

  1. Go to the site.

  2. Launch Frosmo Preview.

  3. Select Advanced > Events.

    Testing custom action tracking
  4. Go to a page where custom actions are tracked. If custom action events are successfully triggered with the data layer, Frosmo Preview shows the following messages for each event:

    • customAction / customAction.<frosmoEvent> / customAction.<frosmoEvent>.<frosmoValue> (contains the custom action data parsed from the custom action object)

    • 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 custom action tracking
  5. To verify that the correct custom action data was sent, check the Name or Data column for the customAction messages, as both columns show the custom action name and value.

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

    Testing custom action tracking
  7. Log in to the Frosmo Control Panel, and select your site.

  8. In the sidebar, select More > Custom Actions, and check whether the tracked custom actions are listed with the passed values.

    Testing custom action tracking
    note

    If you define titles for the custom action values in the Control Panel, the custom actions overview displays the titles rather than the values.

    Testing custom action tracking