question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Render amp-analytics in story post type (Web Stories plugin integration)

See original GitHub issue

Feature 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-analytics snippet, with tracking ID etc. Site Kit can hook into the Web Stories web_stories_print_analytics action for that.
  • Web Stories will take care of adding the necessary story-specific events. Web Stories can hook into the googlesitekit_amp_gtag_opt filter for that and add the event configuration e.g. if is_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-analytics snippet based on the regular configuration in Web Stories posts (using web_stories_print_analytics).
  • Secondary: Site Kit should ensure no amp-auto-ads tag is rendered for Web Stories.

Implementation Brief

  • In the Analytics::register method, hook the existing $print_amp_gtag closure into web_stories_print_analytics.
  • Update the Context::is_amp method to also return true if is_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 AdSense class methods where there are checks for is_singular( 'amp_story' ) to also check is_singular( 'web-story' ) in the same way. Let’s keep the amp_story ones for backward-compatibility.

QA Brief

Changelog entry

  • Render amp-analytics snippet for Web Stories.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ryanwelchercommented, May 29, 2020
0reactions
swissspidycommented, May 6, 2020

IB approved 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found