Skip to content

Instantly share code, notes, and snippets.

@chavesm
Created October 13, 2020 08:06
Show Gist options
  • Save chavesm/218e8ec615094f32f6737a00f832b894 to your computer and use it in GitHub Desktop.
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.
<?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