Skip to content

Instantly share code, notes, and snippets.

@chavesm
Created May 5, 2021 04:05
Show Gist options
  • Save chavesm/0c844b34f685186927852972743f12eb to your computer and use it in GitHub Desktop.
Save chavesm/0c844b34f685186927852972743f12eb to your computer and use it in GitHub Desktop.
<?php // Don't copy this line if adding this gist to a functions.php file.
function get_mepr_id() {
if ( !class_exists('MeprUtils') ) {
return 0;
}
$mepr_user = MeprUtils::get_currentuserinfo();
if ( $mepr_user === false ) {
return 0;
}
$active_subscriptions = $mepr_user->active_product_subscriptions('ids');
if ( empty($active_subscriptions) ) {
return 0;
}
return $active_subscriptions[0]; // Returns the first found Active Membership ID
} // function()
add_filter('monsterinsights_frontend_tracking_options_persistent_gtag_before_pageview',
function($options) {
// Set the custom dimension
$options['dimension9'] = get_mepr_id();
return $options;
},
20 // priority
); // add_filter()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment