Render amp-analytics in story post type (Web Stories plugin integration)
See original GitHub issueFeature Description
We should integrate with the Web Stories plugin to place our amp-analytics snippet within stories.
Responsibilities between the two plugins should be distributed the following:
- Site Kit will take care of rendering the basic
amp-analyticssnippet, with tracking ID etc. Site Kit can hook into the Web Storiesweb_stories_print_analyticsaction for that. - Web Stories will take care of adding the necessary story-specific events. Web Stories can hook into the
googlesitekit_amp_gtag_optfilter for that and add the event configuration e.g. ifis_singular( 'amp_story' )(since that filter fires for any AMP context, not just stories).
Web Stories will need to make slight adjustments accordingly (see https://github.com/google/web-stories-wp/issues/1168): The plugin should remove the functionality where it renders the snippet itself (replicating a lot of Site Kit logic) and instead simply filter into Site Kit’s googlesitekit_amp_gtag_opt to add story-specific events for stories.
cc @swissspidy
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Site Kit should place the
amp-analyticssnippet based on the regular configuration in Web Stories posts (usingweb_stories_print_analytics). - Secondary: Site Kit should ensure no
amp-auto-adstag is rendered for Web Stories.
Implementation Brief
- In the
Analytics::registermethod, hook the existing$print_amp_gtagclosure intoweb_stories_print_analytics. - Update the
Context::is_ampmethod to also return true ifis_singular( 'web-story' ). Since that is now decoupled from the AMP plugin, but itself is always using AMP anyway, we can reliably do that. - Update
AdSenseclass methods where there are checks foris_singular( 'amp_story' )to also checkis_singular( 'web-story' )in the same way. Let’s keep theamp_storyones for backward-compatibility.
QA Brief
Changelog entry
- Render
amp-analyticssnippet for Web Stories.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Advertise in Web Stories - amp.dev
Advertising with Web Story ads allows for seamless and disruption-free integration into the user's journey, keeping them engaged and delighted by the platform....
Read more >Web Stories WordPress Plugin: 9 Must-Know SEO Tips
Web Stories for WordPress is a new plugin by Google. Important SEO tips should be kept in mind for optimal Web Story performance...
Read more >AMP Stories: Everything You Need To Know (Complete Guide)
AMP Stories is an open source technology. You can create a story with few lines of HTML and Javascript, and display it on...
Read more >Add Analytics to AMP pages - Google Developers
Accelerated Mobile Pages (AMP) is a platform used to build web pages for static content that renders fast. AMP includes an <amp-analytics> ...
Read more >7 Smart Ways to Improve Your Google Web Stories for Search ...
How to add AMP code to your Web Story: Use the AMP- analytics script and add it to the <head> of your file....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This looks to have been QA’d in the PR - https://github.com/google/site-kit-wp/pull/1596#pullrequestreview-420020682
IB approved 👍