1.0.0 • Published 7 years ago
gadispatcher v1.0.0
gadispatcher
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.)
:warning: There are currently no tests for this library. :warning:
Usage
API
GADispatcher(trackingId, identifier, options)
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.
send(eventType, metadata)
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.
Example
If you prefer examples, I got you.
Instantiating an instance:
// 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)
Sending a request:
// 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)
1.0.0
7 years ago