Everyone is always telling you to “track, track, track” your Web application’s users. They’ll tell you how important it is to know where they came from, what they’re doing and all sorts of other data that can, admittedly, help you improve the app’s user experience and improve your chances of success. What they don’t tell you is how much of a hassle it can be to integrate those analytics!
Enter Analytics.js, a new open source GitHub project from Segment.io that allows users to add a single set of provider-agnostic hooks to their Web applications that can route to any analytics service they choose, completely doing away with the need for third-party analytics APIs.
The Analytics.js API paves “over the small difference in all your analytics services to give you a single call.”
Users simply need to add the latest version of Analytics.js to their projects and initialize it with the analytics service(s) of their choosing. Then, they just need to add an analytics.identify() call with a userId (and an optional trait) into the footer of every application page, which is how they tie a user to their actions. Finally, the can also insert a couple of analytics.track() calls with specific events to record the actions that users perform; they can also include optional properties for the selected events.
Also, there is no need to worry if an analytics provider can’t handle a certain method (e.g. Google Analytics doesn’t have traits); Analytics.js was built so you can still call them and everything will be just fine.
The types of traits and events that you can track are pretty varied, although Analytics.js does say that “the single most important trait to record is something like memershipLevel or subscriptionType or however you break your users into different tiers.” In terms of events, you should consider what you want your users to do more or less of on your app, and then track those. For example, you can track each time a user completes a purchase, upgrades their plan, invites a friend, cancels an account or unsubscribes from a list, just to name a few possibilities.
On the Analytics.js’s GitHub page are also a reference sections that lists some special user traits and service-specific settings, which includes Google Analytics, KISSmetrics, Intercom and more.