Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Read about this technique here:
# https://medium.com/p/e538ed6567a6
class ApplicationController < ActionController::Base
after_filter :track_event
private
EVENT_TRANSLATIONS = {
'users#create' => 'User Created',
'users#update' => 'User Updated',
'orders#new' => 'Order Started',
'orders#create' => 'Order Created',
'orders#update' => 'Order Updated'
}
def track_event
mixpanel.track(event_user, event_name, event_properties)
end
def event_properties
{}
end
def event_user
current_user.try(:id).to_s
end
def event_name
controller_action = "#{params[:controller]}##{params[:action]}"
EVENT_TRANSLATIONS[controller_action] || controller_action
end
end
class OrdersController < ApplicationController
private
def event_properties
{ quantity: @order.quantity, meal_name: @order.meal.name }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment