Last active
January 18, 2023 21:11
-
-
Save chavesm/8b719fc32505b26d4dcfa32a0a423617 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 // 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 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the following to execute a JavaScript function instead of a static value: