Socket
Socket
Sign inDemoInstall

universal-ga

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    universal-ga

Universal Google Analytics module for node


Version published
Weekly downloads
174
decreased by-51.93%
Maintainers
1
Install size
22.9 kB
Created
Weekly downloads
 

Readme

Source

universal-ga

Build Status Coverage Status

A Universal Google Analytics module for node.

Currently supported features:

  • Pageviews
  • Screenviews
  • Events
  • User timings
  • Exceptions
  • Custom Dimensions/Metrics

Install

$ npm install --save universal-ga

Getting Started

To initialize universal-ga, you will need to first pass in your analytics tracking id.

var analytics = require('universal-ga');
...
analytics.initialize('UA-XXXXX-YYY');

Documentation

analytics.initialize( trackingID, options )
NameDescription
trackingIDstring Your analytics tracking id, i.e. UA-XXXXX-YY.
options.debugbool (optional) If set to true, will use analytics_debug.js for some additional console logging.

Before anything else will work, you must first initialize analytics by passing an initial tracking id.

Example
analytics.initialize('UA-12345-12');

Additional options can also be sent to analytics.create by including them as additional properties on the options object.

Example
analytics.initialize('UA-12345-12', { storage: 'none' });
analytics.create( trackingID, options )
NameDescription
trackingIDstring Another analytics tracking id, i.e. UA-XXXXX-YY.
optionsobject or string (optional) additional options to pass to the tracker.

Allows you to create multiple tracking ids. If you just need to add an additional tracking id, options can just be the name of your additional tracker. This can be used in combination with the .name() method.

Example
analytics.initialize('UA-12345-1');
analytics.create('UA-12345-2', 'anotherTracker');
...
analytics.pageview('/home');
analytics.name('anotherTracker').pageview('/home');

However, if you need to combine additional options with a name, you will need to name your tracker as part of the options object.

Example
analytics.initialize('UA-12345-1');
analytics.create('UA-12345-2', {
  name: 'anotherTracker',
  clientId: generateUUID()
});

This will namespace any additional values, allowing you to specify which values to send to which tracker. The above example would send the following data to analytics:

['send', 'pageview', '/home'],
['anotherTracker.send', 'pageview', 'home']
analytics.name( name )
NameDescription
namestring Send next value for the namespaced tracking id.

Namespaces the next value that is sent to the tracker.

Example
analytics.name('anotherTracker').pageView('/home');
analytics.name('anotherTracker').timing('load', 'page', 123);

The above would send the following data to analytics:

['anotherTracker.send', 'pageview', '/home'],
['anotherTracker.send', 'timing', 'load', 'page', 123]
analytics.set( key, value )
NameDescription
keystring Key to send to analytics.
valuestring Value for the key.

Set key/value pairs for the tracker.

Example
analytics.set('page', '/about');
analytics.pageview( pagename , options )
NameDescription
pagenamestring Pagename to send to analytics.
optionsobject (optional) Additional options.

Allows you to send a pageview to analytics. Additional options for the pageview can be seen in the pages documentation.

Example
analytics.pageview('/about');
analytics.screenview( screenname, options )
NameDescription
screennamestring Screenname to send to analytics.
optionsobject (optional) Additional options.

Allows you to send a screenview to analytics. Additional options for the screenview can be seen in the app screens documentation.

Example
analytics.screenview('/about');
analytics.event( category, action, options )
NameDescription
categorystring Event category.
actionstring Event action.
optionsobject (optional) Additional options.

Allows you to track

analytics.timing( category, var, value, options )
NameDescription
categorystring Timing category.
varstring Timing variable.
valueint Timing value (in milliseconds).
optionsobject (optional) Additional options.
analytics.exception( message, isFatal )
NameDescription
messagestring Exception message.
isFatalbool Is fatal event.
analytics.custom( key, value )
NameDescription
keystring Custom dimension/metric key.
valuestring Custom dimension/metric value.

Keywords

FAQs

Last updated on 22 Oct 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc