GADispatcher is a highly simplified API for sending any type of event to Google Analytics. (WIP: Any requests made with this library that fail are gracefully queued in the background to resend later.)
Calling new GADispatcher()
instantiates the GADispatcher instance.
-
trackingId
- A Google Analytics tracking ID. -
[identifier]
- An optional V4 UUID. One is generated and stored between sessions if no UUID is passed. -
[options]
- See theuniversal-analytics
documentation for available options.
-
eventType
- Kind of event to send. Currently available events arepageview
,event
,transaction
,exception
andtiming
. -
[metadata]
- Optional metadata as an object.universal-analytics
documentation for available options.
If you prefer examples, I got you.
// Set up some vars
const GA_ID = 'UA-123456-78'
const UUID = '123e4567-e89b-12d3-a456-426655440000'
const GA_OPTS = {
https: true // on by default
}
// Ready
const ga = new GADispatcher(GA_ID, UUID)
// Configure some data about an event
const recordingEvent = {
eventCategory: 'User action',
eventAction: 'Started recording'
}
// Sends an event type request to Google Analytics
ga.send('event', recordingEvent)