An open API service indexing awesome lists of open source software.

https://github.com/springload/tagman-watcher

Tiny (1kb) utility for effiently watching browser events and sending them to Google Tag Manager
https://github.com/springload/tagman-watcher

google-tag-manager gtm

Last synced: 11 months ago
JSON representation

Tiny (1kb) utility for effiently watching browser events and sending them to Google Tag Manager

Awesome Lists containing this project

README

          

# TagMan Watcher

Utility for sending browser events to Google Tag Manager.

These Events can be triggered by DOM events or manually triggered.

Usage:

tagmanWatch(DOMEvent, selectors, [customFields]);

Example:



// listen for change events on inputs and selects
window.tagmanWatch('change', 'input,select');

// Also listen for blur events on selects
window.tagmanWatch('blur', 'select');

This could also be written more concisely as,



window.tagmanWatch(['change', 'input,select'], ['blur', 'select']);

And you can set additional data to be sent when the event fires by passing a third argument:

window.tagmanWatch(['change', 'input,select', {'event':'override', color:'red'}], ['blur', 'select']);

This lets you override the event from 'change' to the Tag Manager Event that you want.

Within your app you can also trigger custom events:

var domElement = document.querySelector("input");

window.tagmanWatch.trigger("my-custom-event", {value: domElement.value, customKey:"foobar"});

All events must be preregistered with Tag Manager for them to received by Google Tag Manager.

## Requirements

This utility requires a global variable `dataLayer` from Tag Manager.