Documentation Index

Fetch the complete documentation index at: https://docs.supermetrics.com/llms.txt

Use this file to discover all available pages before exploring further.

Events in the _st module

Prev Next

The _st.event module provides a simple event bus within the Data Activation tag system. Use it to publish custom events from one part of your tag setup and subscribe to them from another, without those parts needing to call each other directly.

Methods overview

Method

Description

_st.event.publish(category, eventName, data)

Clarifies the trailing slash behavior

_st.event.subscribe(category, eventName, callback)

Subscribes to an event.

Method details

_st.event.publish(category, eventName, data)

Data Activation runs the callback for every subscription where the category matches or is a parent of the published category, and the event name matches exactly (or uses a wildcard).

Parameters:

  • category (string): The event category. Use a selector delimited by /, for example checkout/cart.

  • eventName (string): The name of the event. Must match exactly for a subscription to trigger.

  • data (any): The data to pass to the subscriber's callback function.

Requires: _st.event.subscribe

Example:

_st.event.publish('checkout/cart', 'itemAdded', { productId: '1630' });

_st.event.subscribe(category, eventName, callback)

Subscribes to an event. When a matching event is published, Data Activation runs the callback function with the event's category, event name, and data.

Parameters:

  • category (string): The event category to subscribe to. Use a selector delimited by /.

  • eventName (string): The name of the event to subscribe to. Pass an empty string ("") to listen to all events published under the specified category.

  • callback (function): The function to run when a matching event is published. Receives category, eventName, and data as parameters. Note: The category string passed to your callback will always include a trailing slash (such as checkout/cart/), even if it was published without one.

Requires: _st.event.publish

Example:

// Exact event match
_st.event.subscribe('checkout', 'itemAdded', function(category, eventName, data) {
  // Receives: 'checkout/cart/', 'itemAdded', { productId: '1630' }
});

// Wildcard match (listens to all events under 'checkout')
_st.event.subscribe('checkout', '', function(category, eventName, data) {
  // Handles 'itemAdded', 'itemRemoved', 'paymentProcessed', etc.
});