Forked from swissspidy/web-stories-auto-analytics.php
Last active
May 28, 2023 17:18
-
-
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
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
/** | |
* 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