Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikezielonka/b1ed67191d5bc547c9af3eb30c74072e to your computer and use it in GitHub Desktop.
Save mikezielonka/b1ed67191d5bc547c9af3eb30c74072e to your computer and use it in GitHub Desktop.
Mini-plugin to add an additional Google Analytics tracking code to web stories
/**
* Plugin Name: Web Stories Additional GA Tracking
* Description: Mini-plugin to add an additional Google Analytics tracking code to web stories
* Plugin URI: https://wp.stories.google/
* Author: Pascal Birchler, Google
* Author URI: https://opensource.google.com/
* Version: 0.0.1
* License: Apache License 2.0
* License URI: https://www.apache.org/licenses/LICENSE-2.0
*/
// SEE https://amp.dev/documentation/components/amp-pixel/
add_action(
'web_stories_print_analytics',
static function () {
// TODO: REPLACE WITH YOUR OWN GOOGLE ANALYTICS TRACKING ID.
$tracking_id = 'UA-1234567';
?>
<amp-story-auto-analytics gtag-id="<?php echo esc_attr( $tracking_id ); ?>"></amp-story-auto-analytics>
<?php
}
);
// Prevent Sitekit from loading UA
add_filter(
'googlesitekit_analytics_tag_amp_blocked',
static function ( $blocked ) {
return $blocked ?: is_singular( 'web-story' );
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment