Skip to main content
Web Stories for WordPress includes built-in support for Google Analytics to help you track user engagement and measure the performance of your stories.

Overview

The analytics integration automatically tracks key user interactions including page views, story completion, link clicks, audio interactions, and page attachment engagement.

Configuration

Setting Up Google Analytics

  1. Navigate to Stories > Settings > Analytics in your WordPress admin
  2. Enter your Google Analytics tracking ID (format: UA-XXXXX-Y or G-XXXXXXXXXX)
  3. Save your settings
The analytics code will be automatically injected into all published stories.
The plugin uses <amp-story-auto-analytics> by default for automatic event tracking. Legacy <amp-analytics> mode is also available for backward compatibility.

Tracked Events

The plugin automatically tracks the following story interactions:
  • story_progress: Fired when each story page becomes visible
  • story_complete: Fired when the last page is shown (completion rate)
  • Event data includes story title, page index, and progress percentage
  • story_focus: User clicks an element that opens a tooltip (links, embedded content)
  • story_click_through: User clicks through on a tooltip or link
  • story_open: User opens a drawer or dialog (e.g., page attachments)
  • story_close: User closes a drawer or dialog
  • story_audio_muted: User mutes the story audio
  • story_audio_unmuted: User unmutes the story audio
  • story_page_attachment_enter: User opens a page attachment
  • story_page_attachment_exit: User dismisses a page attachment

Implementation Details

The analytics tracking is implemented in includes/Analytics.php:99-235 and uses two modes:

Auto Analytics (Default)

The modern approach using <amp-story-auto-analytics>:
<amp-story-auto-analytics gtag-id="G-XXXXXXXXXX"></amp-story-auto-analytics>
This automatically configures Google Analytics with sensible defaults for Web Stories.

Legacy Analytics

For advanced customization, you can enable legacy mode which uses <amp-analytics> with a custom configuration:
<amp-analytics type="gtag" data-credentials="include">
  <script type="application/json">
  {
    "vars": {
      "gtag_id": "G-XXXXXXXXXX",
      "config": {
        "G-XXXXXXXXXX": { "groups": "default" }
      }
    },
    "triggers": {
      "storyProgress": {
        "on": "story-page-visible",
        "request": "event",
        "vars": {
          "event_name": "custom",
          "event_action": "story_progress",
          "event_category": "${title}",
          "event_label": "${storyPageIndex}"
        }
      }
    }
  }
  </script>
</amp-analytics>

Custom Analytics Configuration

You can customize the analytics configuration using WordPress filters:

Filter Analytics Configuration

add_filter('web_stories_analytics_configuration', function($config) {
    // Add custom triggers
    $config['triggers']['customEvent'] = [
        'on' => 'story-page-visible',
        'request' => 'event',
        'vars' => [
            'event_name' => 'custom',
            'event_action' => 'my_custom_event',
            'event_category' => '${title}',
        ],
    ];
    
    return $config;
});
The web_stories_analytics_configuration filter only applies when using legacy analytics mode. Auto analytics mode uses Google’s default configuration.

Variable Substitutions

When configuring custom analytics events, you can use AMP variable substitutions:
  • ${title} - Story title
  • ${storyPageIndex} - Current page index
  • ${storyPageCount} - Total number of pages
  • ${storyProgress} - Progress percentage (0-100)
  • ${canonicalUrl} - Story URL
See the AMP Variable Substitutions documentation for the complete list.

Privacy Considerations

The analytics integration respects user privacy and complies with GDPR requirements. Make sure to include Google Analytics in your privacy policy and cookie consent mechanisms.

Troubleshooting

  1. Verify your tracking ID is correct in Stories > Settings
  2. Check that you’re not using the plugin’s internal tracking ID
  3. Allow 24-48 hours for data to appear in Google Analytics
  4. Use the Google Analytics Debugger Chrome extension to verify events are firing
  1. Open your browser’s developer console and check for errors
  2. Verify the story is using AMP validation
  3. Test with legacy analytics mode if auto-analytics isn’t working
  4. Check that third-party analytics plugins aren’t interfering

Build docs developers (and LLMs) love