AMP is a web component framework designed to create fast-loading mobile pages. To achieve this performance, AMP enforces strict limitations:

  • Custom JavaScript is prohibited or heavily restricted
  • Only AMP-approved scripts can run
  • Third-party tracking scripts require specific AMP components

For Post Views Counter Pro, these restrictions mean that client-side counting methods face significant limitations on AMP pages. The plugin includes a dedicated integration layer to handle these constraints.

How It Works

Post Views Counter Pro includes a dedicated AMP integration file located at includes/integrations/amp.php. This integration:

  1. Detects AMP pages — Uses the amp_is_request() function (provided by the AMP plugin) to check whether the current request is an AMP page. The integration only activates when function_exists( 'amp_is_request' ) returns true
  2. Adjusts tracking behavior — Modifies how views are counted based on AMP constraints
  3. Manages JavaScript output — Loads AMP-specific compatibility assets only when needed to avoid conflicts with standard optimization flows
  4. Injects necessary components — Outputs the amp-script custom element required for AMP-compatible tracking

The integration ensures that view counting continues to function even when AMP’s JavaScript restrictions would otherwise prevent tracking.

Setup

Prerequisites

  • Post Views Counter Pro must be activated
  • An AMP plugin (such as AMP for WordPress) must be installed and configured
  • Your site must be serving AMP versions of content

Configuration Steps

  1. Navigate to Post Views > Counting > Tracking Behavior
  2. Select an appropriate Counter Mode — See the Counter Mode Constraints section below
  3. Navigate to Post Views > Integrations
  4. Verify AMP integration is active — The integration loads automatically when AMP is detected

Configuration

Counter Mode Constraints

AMP’s JavaScript restrictions and the integration’s behavior depend on the AMP template mode served by your AMP plugin (Reader, Transitional, or Standard). The amp-script custom element enables JavaScript-based counting on AMP pages where script execution is permitted.

Counter Mode AMP Compatibility Notes
PHP Mode ✓ Compatible Server-side counting bypasses AMP JavaScript restrictions entirely
JavaScript Mode Mode-dependent amp-script can enable counting in Transitional/Standard AMP mode; may not execute in Reader mode
REST API Mode Mode-dependent Requires client-side JavaScript to initiate the REST request; applies mode-level script constraints
Fast AJAX Mode-dependent Requires JavaScript execution; availability follows the same AMP template-mode constraints as JavaScript Mode

Recommended configuration: PHP Mode provides the most consistent AMP tracking across all AMP template modes. If your site uses Transitional or Standard AMP mode and the amp-script injection is confirmed active, JavaScript-based modes may also work. Verify with your AMP plugin’s error logs and test across template modes before relying on non-PHP modes.

Tracking Targets

Configure which content types to track at Post Views > Counting > Tracking Targets. AMP pages for posts, pages, and custom post types will respect these settings.

Visitor Exclusions

Configure visitor exclusions at Post Views > Counting > Visitor Exclusions. Exclusion rules (such as excluding logged-in users or specific IP addresses) apply equally to AMP and non-AMP pages.

Troubleshooting

Views Not Updating on AMP Pages

Symptoms: View counts remain static or do not increment when visitors access AMP versions of your content.

Possible causes and solutions:

  1. AMP template mode and Counter Mode mismatch

    • AMP JavaScript restrictions vary by template mode (Reader, Transitional, Standard). In Reader mode, amp-script execution may not succeed for JavaScript-based counting modes.
    • Solution: Switch to PHP Mode at Post Views > Counting > Tracking Behavior > Counter Mode for reliable tracking across all AMP template modes, or verify that your AMP plugin is running in Transitional/Standard mode if you prefer a JavaScript-based counter mode.
  2. Caching plugin interference

    • Page caching may serve cached versions that bypass PHP execution
    • Solution: Enable Caching Compatibility at Post Views > Counting > Performance & Caching > Caching Compatibility
  3. AMP plugin configuration

    • Some AMP plugins offer different template modes (Reader, Transitional, Standard) that affect how integrations behave
    • Solution: Verify your AMP plugin is properly configured and that AMP pages are being generated correctly

Counts Stuck at Zero

If view counts never increment on AMP pages:

  1. Verify PHP Mode is selected as the counter mode
  2. Check that the AMP integration file exists at includes/integrations/amp.php
  3. Confirm no other plugins are removing required AMP script components
  4. Review your AMP plugin’s error logs for JavaScript or tracking-related warnings

Discrepancy Between AMP and Non-AMP Views

You may notice view count differences between AMP and non-AMP versions of the same content. This can occur when:

  • Different visitors access different versions (mobile users may see AMP, desktop users see standard pages)
  • The count interval settings at Post Views > Counting > Tracking Behavior treat repeat visits differently based on cookie storage availability

Cookie Storage Limitations

AMP has restrictions on cookie usage. If you’ve configured Data Storage to use cookies at Post Views > Counting > Tracking Behavior > Data Storage, be aware that:

  • AMP may limit or block cookie storage
  • The count interval relies on storing visitor data
  • Consider the Cookieless storage option for broader AMP compatibility