Last active
April 8, 2021 18:27
-
-
Save kimcoleman/1114506c1c3e6177c495e3664c6013bb to your computer and use it in GitHub Desktop.
Update to the GADWP / ExactMetrics Lite tracking code for custom dimension for Membership Level
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
<?php | |
/** | |
* Update to the GADWP / ExactMetrics Lite tracking code for custom dimension for Membership Level | |
* | |
*/ | |
function my_pmpro_membership_level_exactmetrics_frontend_tracking_options_analytics_end( $options ) { | |
// Get the value to track for the current user. | |
if ( is_user_logged_in() && function_exists( 'pmpro_getMembershipLevelForUser' ) ) { | |
// Get the current users's membership level ID. | |
$current_user_membership_level = pmpro_getMembershipLevelForUser( get_current_user_id() ); | |
$value = $current_user_membership_level->ID; | |
} else { | |
// Set the tracked membership level ID to no_level. | |
$value = 'no_level'; | |
} | |
$options['membership_level'] = "'set','dimension1', '" . $value . "'"; | |
return $options; | |
} | |
add_filter( 'exactmetrics_frontend_tracking_options_analytics_before_scripts', 'my_pmpro_membership_level_exactmetrics_frontend_tracking_options_analytics_end' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Putting Google Analytics to work for your Membership Site" at Paid Memberships Pro here: https://www.paidmembershipspro.com/putting-google-analytics-to-work-for-your-membership-site/