A tracking helper built in ES6 with Google Analytics and Google Tag Manager Support built in.
import TrackingHelper, {Tracker} from 'es6-tracking-helper'
const trackingHelper = new TrackingHelper({
availableTracker: {'gtm': Tracker.GoogleTagManager}
})
Use the built in click listener
<a data-tracking-type="event" data-tracking-name="click-event">Track</a>
Or trigger the tracking via JS
trackingHelper.track({type: 'event', name: 'js-triggered-event'})
Parameter | Type | Description |
---|---|---|
options | Object |
Options object |
options.debug | Boolean (false) |
Enables debugging in the console |
options.init | Boolean (true) |
Initiate click event listener |
options.context | Node (document) |
Context for event listener |
options.availableTracker | Object |
Tracker Classes |
options.pageName | String | Boolean (false) |
Will be prepended to event/pageview names in built in tracker |
options.category | String (Global) |
Global Category |
options.action | String (Global) |
Global Action |
options.dataset | Object |
Data attributes for event listener |
options.dataset.type | String (trackingType) |
Data attribute for type |
options.dataset.category | String (trackingCategory) |
Data attribute for category |
options.dataset.action | String (trackingAction) |
Data attribute for action |
options.dataset.name | String (trackingName) |
Data attribute for name |
options.dataset.nonInteraction | String (trackingNonInteraction) |
Data attribute for non interaction flag |
Start listening for clicks on nodes with tracking data attributes
Returns: TrackingHelper
- This tracking helper instance
Stop listening for clicks on nodes with tracking data attributes
Returns: TrackingHelper
- This tracking helper instance
Click handler for nodes with tracking data attributes
Adds a tracking type
Parameter | Type | Description |
---|---|---|
type | String |
tracking method type used to identify type in data attributes |
Returns: TrackingHelper
- This tracking helper instance
Removes a tracking type
Parameter | Type | Description |
---|---|---|
type | String |
tracking method type used to identify type in data attributes |
Returns: TrackingHelper
- This tracking helper instance
Iterates over all trackers and tries to invoke the designated tracking type
Returns: TrackingHelper
- This tracking helper instance
MIT
@iantsch - web developer behind this and other projects.