Enhance tracking with custom events in dataLayer

Business Benefits

Improve your organization’s data collection.

Add the custom events and parameters your site or organization needs to collect data on to a spreadsheet to use as a reference when creating the data layer specification for developers.

Typical must-collect custom events include:

  • User login or authentication.
  • Ecommerce events.
  • Calls to action.

Use the same parameter names whenever possible.

Add lower priority events your site could collect to your spreadsheet.

For example:

  • Page timing measurements.
  • Scroll and/or engagement.
  • Outbound clicks.

Write the specification for the dataLayer events, including a code example of the dataLayer.push(), which parameters are required and optional, and at what point the dataLayer.push() should happen within the custom event and submit it to your developers.

The following example is a sample specification for an add_to_cart custom event:

Create all the necessary items, like tags, triggers, and variables, in Google Tag Manager before the specification is deployed.

For example, the specification example from the previous step could include these items:

  • A Custom Event Trigger for event name add_to_cart.
  • A Data Layer Variable for variable name items.
  • An Event tag for the add_to_cart event, which sends the Data Layer variable for {{items}} as a custom parameter named items to Google Analytics.

Test the setup in Google Tag Manager’s Preview mode to ensure that all specification components are pushed into the dataLayer and your tags fire with all the necessary information.

Pay extra attention to required keys – are they included in the pushed object in all permutations of the action?

If you see nothing in Preview mode, it’s likely that either the dataLayer.push() is missing altogether or it has encountered an error. Run the test again together with the developer who deployed the update to make sure that you can find and fix all possible mistakes as quickly as possible.

Last edited by @hesh_fekry 2023-11-14T11:10:45Z