https://github.com/iantsch/es6-tracking-helper
ES6 tracking helper
https://github.com/iantsch/es6-tracking-helper
analytics es6 google tagmanager tracking tracking-helper
Last synced: about 1 month ago
JSON representation
ES6 tracking helper
- Host: GitHub
- URL: https://github.com/iantsch/es6-tracking-helper
- Owner: iantsch
- License: mit
- Created: 2018-02-17T00:33:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-17T19:54:10.000Z (almost 6 years ago)
- Last Synced: 2025-03-16T04:47:13.884Z (2 months ago)
- Topics: analytics, es6, google, tagmanager, tracking, tracking-helper
- Language: JavaScript
- Homepage: https://npm.im/es6-tracking-helper
- Size: 127 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ES6 Tracking Helper
[]() []() []() []()
A tracking helper built in ES6 with Google Analytics and Google Tag Manager Support built in.
## Usage
```js
import TrackingHelper, {Tracker} from 'es6-tracking-helper'const trackingHelper = new TrackingHelper({
availableTracker: {'gtm': Tracker.GoogleTagManager}
})
```Use the built in click listener
```html
Track
```Or trigger the tracking via JS
```js
trackingHelper.track({type: 'event', name: 'js-triggered-event'})
```## API
#### constructor
| 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 |#### startTracking ⇨ ``TrackingHelper``
Start listening for clicks on nodes with tracking data attributes
*Returns*: ``TrackingHelper`` - This tracking helper instance
#### stopTracking ⇨ ``TrackingHelper``
Stop listening for clicks on nodes with tracking data attributes
*Returns*: ``TrackingHelper`` - This tracking helper instance
#### onClick
Click handler for nodes with tracking data attributes
#### add(type) ⇨ ``TrackingHelper``
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
#### remove(type) ⇨ ``TrackingHelper``
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
#### track ⇨ ``TrackingHelper``
Iterates over all trackers and tries to invoke the designated tracking type
*Returns*: ``TrackingHelper`` - This tracking helper instance
## License
MIT
## Credits
[@iantsch](https://twitter.com/iantsch) - [web developer](https://mbt.wien) behind this and other projects.