2.0.1 • Published 5 years ago

es6-tracking-helper v2.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

ES6 Tracking Helper

licence tests coverage tag

A tracking helper built in ES6 with Google Analytics and Google Tag Manager Support built in.

Usage

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'})

API

constructor

ParameterTypeDescription
optionsObjectOptions object
options.debugBoolean (false)Enables debugging in the console
options.initBoolean (true)Initiate click event listener
options.contextNode (document)Context for event listener
options.availableTrackerObjectTracker Classes
options.pageNameString | Boolean (false)Will be prepended to event/pageview names in built in tracker
options.categoryString (Global)Global Category
options.actionString (Global)Global Action
options.datasetObjectData attributes for event listener
options.dataset.typeString (trackingType)Data attribute for type
options.dataset.categoryString (trackingCategory)Data attribute for category
options.dataset.actionString (trackingAction)Data attribute for action
options.dataset.nameString (trackingName)Data attribute for name
options.dataset.nonInteractionString (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

ParameterTypeDescription
typeStringtracking method type used to identify type in data attributes

Returns: TrackingHelper - This tracking helper instance

remove(type) ⇨ TrackingHelper

Removes a tracking type

ParameterTypeDescription
typeStringtracking 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 - web developer behind this and other projects.

2.0.1

5 years ago

2.0.0

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.0

6 years ago