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
- Host: GitHub
- URL: https://github.com/springload/tagman-watcher
- Owner: springload
- Created: 2016-09-16T04:31:16.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-16T04:33:25.000Z (over 9 years ago)
- Last Synced: 2025-02-01T06:25:34.800Z (about 1 year ago)
- Topics: google-tag-manager, gtm
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 4
- Watchers: 23
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.