Generating a New Event to Fire Tags On

Another use case for data layer is to create a new event that could fire tags, as an extension of the trigger mechanism. Normally, you would be constrained to one of the predefined trigger types like page view, click or form submit. Pushing new event to data layer makes use of the remaining trigger type called event. It allows for more precise definition on what event to wait for. A good example would be to create a new event the moment user finishes watching a video on web page. Such event could in turn fire tags to show a pop-up ad etc.

To create new event you just have to push into data layer new object with the event key provided, like so:

<script>dataLayer.push({‘event’: ‘custom_event_name’});</script>

The ‘custom_event_name’ is just a name of your custom event e.g. ‘video ended’.

This feature is especially powerful when used within callbacks for button clicks or AJAX requests.