Comprehensive tracking implementation with mixpanel on Rails and Backbone

My client wants to create a sophisticated mixpanel tracking system in his Rails 3.2 application that contains the extensive functionality of backbone.js.

I want to abstract the functionality of mixpanel in some kind of module (as opposed to the fact that calls are strewn with the entire existing code base).

One of the requirements is that mixpanel calls do not start until successful, so I don’t think I can attach mixpanel calls to DOM elements.

My additional thought was to create some kind of mediator object in javascript that subscribes to various main events that need to be tracked. However, only about half of the events I need to track are in the spine, which makes me feel like I don’t think I can use mixpanel in js at all.

Maybe the lib class that listens for rail models?

Any thoughts or tips?

Thanks!

+4
source share
2 answers

We encountered this problem about six months ago and decided to create an open source javascript library that will abstract the Mixpanel functionality in all analytics services that we use, including KISSmetrics, Google Analytics, Chartbeat, etc.

You can check it out at http://segmentio.github.com/analytics.js

The result is a simple API where you can call analytics.track () or analytics.identify () in one line of code and send data to all the different providers.

The library also has helper functions such as analytics.trackLink () and analytics.trackForm () to make it easier to track outbound clicks and form submissions, which usually results in a page reload before events can be sent. These functions introduce slight delays for events to exit.

+7
source

You could use one of the Ruby libraries in an ActiveRecord or Observer callback by doing identify() with the user id to associate it with them.

Another option is to perform actions through AJAX on the client, and then fire the mixpanel event in the success callback. If you need to send them to another page, you can set window.location after a timeout.

+1
source

Source: https://habr.com/ru/post/1440844/


All Articles