Last active
August 29, 2015 13:57
-
-
Save daniel-nelson/9749476 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
def mixpanel | |
@mixpanel ||= Mixpanel::Tracker.new(MIXPANEL[:token]) | |
end | |
def user_conversion(user, converted_at = Time.now.in_time_zone('UTC')) | |
properties = { | |
'Converted' => converted_at, | |
'Conversion Delay' => (converted_at.to_date - user.created_at.to_date).to_i | |
} | |
mixpanel.people.set_once(user.id, properties, nil, '$ignore_time' => true) | |
mixpanel.people.unset(user.id, 'Unpaid', nil, '$ignore_time' => true) | |
mixpanel.people.unset(user.id, 'Churned', nil, '$ignore_time' => true) | |
mixpanel.track(user_id, 'Conversion!') | |
end | |
# options includes 'Plan' and the 'Action' that led to churn: downgrade, account deletion, charge failure | |
def user_churn(user, options) | |
churned_at = Time.now.in_time_zone('UTC') | |
converted_at = (user.converted_at || churned_at).to_date | |
properties = { | |
'Churned' => churned_at, | |
'Plan When Churned' => user.plan_id, | |
'Paid Lifetime' => (churned_at.to_date - converted_at).to_i | |
} | |
mixpanel.people.set(user_id, properties, nil, '$ignore_time' => true) | |
mixpanel.track(user_id, 'Churn!') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment