Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Update to the GADWP / ExactMetrics Lite tracking code for custom dimension for Membership Level
<?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' );
@laurenhagan0306
Copy link

laurenhagan0306 commented Apr 8, 2021

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/

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment