perak:ganalytics

v0.3.0Published 6 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

GAnalytics: Google Analytics for Meteor

Log page views and events to Google Analytics. Forked from https://github.com/datariot/meteor-ganalytics.git and added DNT support.

NOTE: This package uses the newer analytics.js file for "Universal Analytics". This package will not work if you are not on the newer collection system.

Installing

meteor add perak:ganalytics

If you don't have a settings.json file, you need to add one and load it according to the Meteor documentation. http://docs.meteor.com/#meteor_settings

In settings.json add

1{
2  "public" : {
3    "ga": {
4      "account":"UA-XXXXXXX-Y"
5    }
6  }
7}

Usage

Example router code to log pageviews for routes:

1Meteor.Router.add({
2  '/': function() {
3    GAnalytics.pageview();
4    return 'home';}
5})

In your controller code:

1GAnalytics.pageview();
2GAnalytics.pageview("/hello");
3
4
5GAnalytics.event("account","signin");
6GAnalytics.event("account","signin","DataRiot");
7GAnalytics.event("account","signin","DataRiot", 2);

You can also provide options for the Google Analytics cookie:

1{
2  "public" : {
3    "ga": {
4      "account":"UA-XXXXXXX-Y",
5      "cookieName": "new_cookie_name",
6      "cookieDomain": "mynew.domain.com",
7      "cookieExpires": 60 * 60 * 24 * 28,  // Time in seconds.
8      "trackInterests": true,  // Enable also GA website and
9      "trackInPage": true,     // force/ignore the Google check.
10      "respectDNT": false       // If set to true and user has DNT enabled, nothing will be sent to google (and no cookies will be set by ga). Default: false (but GDPR requires this to be set to true).
11    }
12  }
13}

Debug Mode

If you pass debug: true as a setting, the package will output console logs on GAnalytics.pageview() and GAnalytics.event().