How do I track the os and browser for each event when using the mixpanel gem?

862 Views Asked by At

I am leveraging the mixpanel gem to fire off some events via Rack middleware as opposed the browser-based js constructed events. I know I can do all of this via their js API, but I have cases where it is much easier to fire the event from the controller.

BUT, for some reason none of these events include the user's browser and OS.

The gem documentation (https://github.com/zevarito/mixpanel#usage) seems to indicate that I would need to manually include these:

Additional information contained in your environment (e.g., http_referer) can simply be sent in as attributes where appropriate for your use case.

Is this really the case? If so, what's the best way to do this? Use something like the browser gem (https://github.com/fnando/browser) and then populate the browser and os properties in my events?

1

There are 1 best solutions below

0
On

The reason the standard HTTP info was not being sent to Mixpanel was because I was not correctly using the Rack Middleware setup. To get it working, I had to

  1. Set the persist: true option on both the Middleware config and when initializing the Mixpanel class. This allows messages to be be sent via js even if there is a redirect (pretty typical on a form submit)
  2. Use the mixpanel.append_track method instead of just mixpanel.track

All of this is present in the gem documentation, it's just not very clear.