gadispatcher

1.0.0 • Public • Published

gadispatcher npm

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.)

⚠️ There are currently no tests for this library. ⚠️

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 the universal-analytics documentation for available options.
send(eventType, [metadata])
  • eventType - Kind of event to send. Currently available events are pageview, event, transaction, exception and timing.
  • [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)

Readme

Keywords

Package Sidebar

Install

npm i gadispatcher

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • doot0