Awesome Open Source
Awesome Open Source

ganalytics Build Status

A tiny (312B) client-side module for tracking with Google Analytics

This module exposes three module definitions:

  • ES Module: dist/ganalytics.mjs
  • CommonJS: dist/ganalytics.js
  • UMD: dist/ganalytics.min.js

Please see Releases for changelog!


$ npm install --save ganalytics


const GAnalytics = require('ganalytics');

const ga = new GAnalytics('UA-XXXXXXXX-X', { aid:1 });
// or
const ga = GAnalytics('UA-XXXXXXXX-X', { aid:1 });

ga.send('pageview', { dt:'Foobar', dp:'/foo' });

ga.send('event', { ec:'Video', ea:'Play', el:'Home Hero' });


GAnalytics(trackerID, options, toWait)


Type: String

Your Google Analytics tracker ID; eg UA-XXXXXXXX-X


Type: Object

Any common, general options that this instance should hold onto.

Note: Any option key can be redefined or overwritten within a send() call.


Type: Integer
Default: 0

Anonymize the sender's IP address. See Anonymize IP.

Type: String

Specifies the application's name. See Application Name.


Type: String

Specifies the application identifier. See Application ID.


Type: String

Specifies the application installer identifier. See Application Installer ID.


Type: String

Specifies the application verison. See Application Version.


Type: String

Anonymously identify a particular user, device, or browser instance. This should be persisted so that repetitive session use the same identifier. See Client ID.

Important This is required when options.uid is not defined.


Type: String

An identifier for a known user, if possible. This value should never be persisted. See User ID.

Important This is required when options.cid is not defined.


Type: String

Indicates the data source type of the hit; eg web or app. See Data Source.


Type: Boolean
Default: false

When truthy, a pageview event will not be sent immediately upon initialization.

ga.send(type, params)


Type: String

The type of hit to send. Must be one of these: pageview, screenview, event, transaction, item, social, exception, or timing.


Type: Object

The parameters to send based on the type of hit.

Please follow the links for each available parameter set:

For pageview hits only, if no params are provided, then the document.title and location.href values will be auto-filled. This allows you to send valid requests by writing:

// is the same as:
//=> ga.send('pageview', { dt:document.title, dl:location.href })


MIT Luke Edwards

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,511,655
Analytics (2,209
Lightweight (1,347
Google Analytics (552
Related Projects