Skip to content

Repository files navigation

NPM versionNPM version

google-ua

Google Universal Analytics tracking snippet

Installation

$ npm install -S google-ua

API

Activate Google Analytics on the page and track page

require('google-ua')("UA-XXXX-X");

Alternatively you can define ua property ID as a data attribute of document body

<bodydata-ua-property-id="UA-XXXX-X">

Check test/index.html for example.

Optional fields parameter lets you set general tracker fields before the pageview event is sent.

require('google-ua')("UA-XXXX-X",{anonymizeIP: true,forceSSL: true,userId: 'as8eknlll'});// set fields, retrieve property ID from data attribute of document bodyrequire('google-ua')({anonymizeIP: true,forceSSL: true,userId: 'as8eknlll'});

You can prevent snippet from sending pageview event automatically by setting the first parameter to false

// initilize tracker, do not send `pageview` eventrequire('google-ua')(false,"UA-XXXX-X")// initialize tracker, do not send `pageview` event, retrieve property ID from data attribute of document bodyrequire('google-ua')(false);

License

MIT

About

Google Universal Analytics snippet

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages