- Google Analytics is good for website metrics, but not event tracking and cohort reports. Also it doesn’t support named user tracking very well.
- KISSmetrics is very good but also expensive and somewhat a bit pushy on their marketing side which always puts us off.
- Mixpanel is very good at event tracking and has a decent free tier which always helps. Their JS library is very good but their Rails support is not comprehensive as they rely on a couple of outsider projects to have RoR support.
After choosing Mixpanel as our analytics provider of choice, we tried
using their native JS library to track the events. But some of the
events we would like to track for CloudQuartz, our job scheduling and
automation products, are not achievable by the JS library. For example,
we would like to know how many CloudQuartz Agents are registered per day
by OS. This means integrating Mixpanel events in our API endpoints.
We decided to integrate Mixpanel event tracking into our Rails
application. For that, we looked at Mixpanel’s suggested Rails
solutions for this
but none were good enough.
- Use outside controller
- Use Resque for async tracking
- Allow full user identification at any level (work with Deviseor Warden)
The Mixpanel Gem does a good job
at integrating the JS into the page but the samples for integrating it
with Resque don’t work, can’t be
used outside of the controller and doesn’t do user tracking except for
the IP address.
Here is how we built our own Mixpanel RoR solution using some of
Mixpanel gem’s code and integrated with Resque.
Our solution works with Resque for async event logging and can be used
outside the controller.
To track page views and users, use the native Mixpanel solution
here. Just simply include the Mixpanel script on your layout. Make sure you get the
API token from your YAML file so you can separate the events based
Here is an example:
This goes right before the \