Last active
August 29, 2015 14:27
-
-
Save talsafran/2f4118410566a87a68b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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