Created
May 3, 2022 22:34
-
-
Save dpaternina9/b97a82bf47baf66993dedfd9fa77e888 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
<?php | |
add_filter( 'monsterinsights_frontend_tracking_options_gtag_before_pageview', function( $options, $type ) { | |
$user_id = 999; // Replace with code to get actual user ID here | |
$meta_key = 'my_meta_key'; // Replace with the user meta key here | |
$meta_value = get_user_meta( $user_id, $meta_key ); | |
if ( $type === 'ua' ) { | |
// If the customer is tracking for a UA property | |
// they need to make sure the "index" they set up for that custom dimension | |
// on their GA property matches this $index here: | |
$index = 9; | |
$options[ $index ] = $meta_value; | |
} else { | |
// For v4 properties, they need to make sure they have registered this | |
// custom dimension's parameter name on their GA4 property | |
$parameter_name = 'my_parameter_name'; | |
$options[ $parameter_name ] = $meta_value; | |
} | |
return $options; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment