new Listener()
Base/Abstract class for all events. When the `attach` method is called, it creates an event listener.
When the event is triggered, it pushes the event payload to the Google Tag Manager `dataLayer`.
- To create a new type of event listener, extend this class and override the `eventName` property.
- override `listen` to define how the event listener is attached. (optional)
- override `createPayload` to define how the event data is constructed. (optional)
- assign `onTrigger` to add side effects when the event is triggered. (optional)
- Source:
Members
(static) eventName :String
The name of the event that is pushed to GTM
Type:
- String
- Source:
(static) onTrigger
Adds a callback to be executed when the event is triggered.
The callback will have access to the event payload object.
- Source:
Methods
(static) attach() → {void}
Call this method to attach the event listener.
It wraps the `listen` method and handles any errors thrown.
This allows us to safely attach event listeners and monitor for failures in Sentry.
- Source:
Returns:
- Type
- void
(static) createPayload(…args) → {Payload}
Creates an object of event data to be sent to Google Tag Manager.
This is called when the event is triggered along with any arguments passed to the `trigger` method.
Subclasses should override this method.
- NOTE: Don't handle errors in this method. Allow them to fail loudly so they can be captured in the `trigger` method.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
arguments needed to create the payload |
- Source:
Returns:
- the event data to send to GTM
- Type
- Payload
(static) listen() → {void}
Should not be called directly: use `attach()` instead.
Defines the logic to trigger the event. Typically this will add an event listener or observer.
Subclasses should override this method.
- NOTE: Don't handle errors in this method. Allow them to fail loudly so they can be captured in the `attach` method.
- Source:
Returns:
- Type
- void