Logo

Data Action Listeners

How to use data action listeners to track user interactions with HTML elements directly from code in Google Analytics 4 with SlideRule Analytics.

Data Action Listeners is a feature of SlideRule Analytics' GA4 integration that allows Shopify dvelopers and designers to easily track user interactions with HTML elements directly from code using data attributes.

Features

  • Track click events on elements with data-action="click".
  • Track view events when elements with data-action="view" enter the user's browser window.
  • Collect any attributes you want to send to GA4.

Usage

Click Tracking:

  • action = "click"
  • object = "call to action"
  • index_number = "12314"
  • location = "hero"
  • text = "Shop"
  • class = "class1 class3"

View Tracking:

  • action = "view"
  • object = "introduction section"
  • text = "Welcome to the Introduction Section"

Attributes Tracked by Default

The following attributes are tracked by default for both click and view events:

  • class
  • id as element_id
  • src
  • role
  • href as url
  • innerText as text
  • target

and all aria elements

Data Attribute properties

Any data-attribute will also be tracked. For instance

data-my-label="my button"

will be tracked as

my_label = "my button"

Customizing the Event Name

You can customize the event name in two ways:

  1. add a data-object attribute. For instance, data-object="style" would result in an event name of style_click.
  2. Add an data-event-name attribute. For instance, data-event-name="style selection" would result in an event name of style_selection.

Note in both cases you still need the data-action="click" attribute.

Snake casing

Per Google Analytics 4 naming conventions all property names are snake cased.

All property values values are lower cased to avoid unintentionally duplicated values.

Collection Limits

Make sure you observe GA4 collection limits.

In particular:

  1. Length of event-parameter name: 40 characters
  2. Length of event name: 40 characters. If an event exceeds 40 characters, the event will not be reported as a conversion (if you mark the event as a conversion) because the appended "_c" will be missing.
  3. Event parameters per event: 25 event parameters

Personally Identifiable Information

Make sure you do not send personally identifiable information to GA4.