Event tracking in meteor.js
User tracking in Meteor

Jun 2016

After building a meteor app you'll be keen to know how many people are using it and also what they are actually doing on it. There are 2 really great packages to help you out here - okgrow:analytics and astronomerio:core.


Astronomer

This is my preferred package of the 2 and what I'm currently using on my gluten free sharing app, gluless.

Astronomer not only tracks all page views (if you're using flow router or iron router) but also every single method call. All this data is sent to the Astronomer servers and then passed on to your integrated Analytics services, like Google Analytics, Woopra, Mixpanel etc. They offer an impressive number of integrations and it's very easy to hook them up.

Astronomer dashboard
Astronomer dashboard

Once you've created an account with Astronomer, add the package to your project:

$ meteor add astronomerio:core

And include your key in your settings.json file:

"astronomer": {
  "appId": "secret key"
}

And you're good to go:

$ meteor --settings ../settings.json

If you want to track additional things that happen in your app, then you can easily do this like so:

analytics.track('Signed Up', {
  plan: 'Startup',
  source: 'Analytics Academy'
});

And if you want to turn off page view tracking or method call tracking it's easy to do so in the settings.json file:

{
  "public": {
    "astronomer": {
      "appId": "secret key",
      "disableUserTracking": false,
      "disableRouteTracking": false,
      "disableMethodTracking": false
    }
  }
}

okgrow

The okgrow package is again very easy to install and tracks all page views if you're using flow router or iron router (but it doesn't track method calls). Rather than sending tracking events to a single server, you define all your analytics services in your settings.json file and it will send the tracking events to all of them.

Install the package with:

$ meteor add okgrow:analytics

And add your keys to settings.json:

{
  "public": {
    "analyticsSettings": {
      "Google Analytics" : {"trackingId": "Your tracking ID"},
      "Amplitude"        : {"apiKey": "..."},
      "Chartbeat"        : {"uid": "..."},
      "comScore"         : {"c2": "..."},
      "HubSpot"          : {"portalId": "..."},
      "Intercom"         : {"appId": "..."},
      "Keen IO"          : {"projectId": "...", "writeKey": "..."},
      "KISSmetrics"      : {"apiKey": "..."},
      "Mixpanel"         : {"token":  "...", "people": true},
      "Quantcast"        : {"pCode": "..."},
      "Segment.io"       : {"apiKey": "..."}
    }
  }
}

Just like with Astronomer, you can track events at any time by calling .track:

analytics.track('Signed Up', {
  plan: 'Startup',
  source: 'Analytics Academy'
});

Note

Depending on your setup and analytics providers, your events might not appear on your analytics dashboards when logged from your development machine; once deployed to your live domain it should work as expected.

Bonus

Both packages use Segment's analytics.js library, so your method calls will still work if you swap packages from one to the other (just remember to modify your settings.json file appropriately).

Please enable JavaScript to view the comments powered by Disqus.