Last active
August 29, 2015 14:00
-
-
Save carter2422/11261176 to your computer and use it in GitHub Desktop.
Account Upgrade
This file contains 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
// Track account upgrade | |
function cgc_rcp_account_upgrade( $user_id, $data ) { | |
if( ! function_exists( 'rcp_get_subscription_name' ) ) | |
return; | |
$mp = Mixpanel::getInstance( CGC_MIXPANEL_API ); | |
$user = get_userdata( $user_id ); | |
$mp->identify( $user->user_login ); | |
$subscription = rcp_get_subscription( $user_id ); | |
$expiration = rcp_get_expiration_date( $user_id ); | |
$recurring = rcp_is_recurring( $user_id ) ? 'Yes' : 'No'; | |
$rcp_payments = new RCP_Payments; | |
$new_user = $rcp_payments->last_payment_of_user( $user_id ); | |
$user_time = strtotime( $user->user_registered, current_time( 'timestamp' ) ); | |
$renewal = ! empty( $new_user ); | |
$upgrade = $user_time < $ten_min_ago && ! $renewal ? true : false; | |
$person_props = array(); | |
$person_props['$first_name'] = $user->first_name; | |
$person_props['$last_name'] = $user->last_name; | |
$person_props['$email'] = $user->user_email; | |
$person_props['$username'] = $user->user_login; | |
$person_props['Account Type'] = 'Citizen'; | |
$person_props['Account Status'] = 'Active'; | |
$person_props['Account Level'] = $subscription; | |
$person_props['Recurring'] = $recurring; | |
$person_props['Expiration'] = $expiration; | |
$person_props['$created'] = date( 'Y-m-d H:i:s' ); | |
$mp->people->set( $user->user_login, $person_props, array( '$ip' => cgc_mixpanel_get_ip() ) ); | |
$event_props = array(); | |
$event_props['distinct_id'] = $user->user_login; | |
$event_props['Account Type'] = 'Citizen'; | |
$event_props['Account Status'] = 'Active'; | |
$event_props['Account Level'] = $subscription; | |
$event_props['Recurring'] = $recurring; | |
$event_props['Expiration'] = $expiration; | |
$event_props['Renewal'] = $renewal ? 'Yes' : 'No'; | |
$event_props['Time Since Creation'] = human_time_diff( $user_time, current_time( 'timestamp' ) ); | |
$mp->track( 'Account Upgraded', $event_props ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment