Created
October 13, 2020 08:06
-
-
Save chavesm/218e8ec615094f32f6737a00f832b894 to your computer and use it in GitHub Desktop.
WordPress action hook for sending a Post ID custom dimension value to Google Analytics.
This file contains 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_action( 'wp_head', function () { | |
if (is_single ()) { | |
?> | |
<script> | |
// Post ID Custom Dimension Snippet | |
let dimension9Value = '<?php echo get_the_id() ?>'; | |
//ga('set', 'dimension9', dimension9Value); | |
ga('send', 'event', 'dimension', 'Post ID', { | |
'dimension9': dimension9Value | |
}); | |
</script> | |
<?php | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment