No commit activity in last 3 years
No release in over 3 years
Allows you to track mixpanel events
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 0.7.0
~> 0.2.8
~> 0.9.12
~> 2.14.1

Runtime

> 4.0.0
 Project Readme

mixpanel_tracker

Gem Version Code Climate Build Status Coverage Status

Provides ability to track Mixpanel events in Rails. Events can be tracked from controllers - and no funnel will break.

Installation

Add to your Gemfile

gem 'mixpanel_tracker'

And bundle it

$ bundle

Then, run the generator

$ rails generate mixpanel_tracker YOUR_ACCESS_TOKEN

This will generate initializer mixpanel_tracker.rb.

If you omit YOUR_ACCESS_TOKEN, initializer will try to fetch access token from environment variable ENV['MIXPANEL_ACCESS_TOKEN'].

Place this in your layout before the closing </head> tag:

<%= include_mixpanel %>

Usage

Track events in needed places in your controllers:

# landing_controller.rb
def index
  mixpanel.track 'User arrived'
end

You can supply additional data to events:

# orders_controller.rb
def create
  if @order.save
    mixpanel.track 'Order created', items_count: @order.items.count
  end
end

Additional notes

By default, mixpanel_tracker will fetch utm params and register them in events

# mixpanel_tracker.rb
config.register_utm_params = true

You may want to not track events in your development or test environment

# mixpanel_tracker.rb
if Rails.env.test? or Rails.env.development?
  config.enabled = false
end