Skip to content

Instantly share code, notes, and snippets.

@chavesm
Last active January 18, 2023 21:11
Show Gist options
  • Save chavesm/8b719fc32505b26d4dcfa32a0a423617 to your computer and use it in GitHub Desktop.
Save chavesm/8b719fc32505b26d4dcfa32a0a423617 to your computer and use it in GitHub Desktop.
<?php // Ignore this line when copying/pasting this code to your child theme's functions.php file.
/**
* This example sets custom dimension #9 to be the WordPress
* post ID of the page/post being visited.
*
* This is compatible with MonsterInsights gtag code. This filter supercedes
* the monsterinsights_frontend_tracking_options_analytics_before_pageview
* filter.
*
* - Change the number 9 to your custom dimension index number.
* - Change the call to get_the_id() to what you need the CD value to be.
*/
add_filter(
monsterinsights_frontend_tracking_options_persistent_gtag_before_pageview,
function( $options ) {
$options[ 'dimension9' ] = get_the_id();
return $options;
},
20 // priority
);
@chavesm
Copy link
Author

chavesm commented Feb 8, 2021

Thanks for sharing your solution, @ThePiGuy :-)

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