Creates an instance of the DataLayer class.
An array representing the initial data layer (e.g. window.samhubData).
Removes a specific listener for the given event name.
The name of the event for which the listener should be removed.
The event listener function to be removed.
Registers an event listener for a specific event.
The name of the event to listen for.
The callback function to be executed when the event is triggered.
Processes all existing events in the dataLayer array.
For each event, if the first element is an array and contains at least one item,
it extracts the event name and parameters, then triggers the corresponding listeners.
The
DataLayerclass provides a mechanism to manage and interact with a data layer array, commonly used for tracking events in analytics or similar systems. It allows for registering event listeners, processing existing events, and intercepting new events pushed to the data layer.Example
Remarks
dataLayerarray is expected to follow a specific structure where each event is an array, with the first element being the event name and subsequent elements being the event parameters.DataLayerclass overrides thepushmethod of the provided array to intercept and process events.Template: EventName
The type representing the event names.
Template: EventListener
The type representing the event listener functions.