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:
- 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 whenfunction_exists( 'amp_is_request' )returns true - Adjusts tracking behavior — Modifies how views are counted based on AMP constraints
- Manages JavaScript output — Loads AMP-specific compatibility assets only when needed to avoid conflicts with standard optimization flows
- Injects necessary components — Outputs the
amp-scriptcustom 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
- Navigate to Post Views > Counting > Tracking Behavior
- Select an appropriate Counter Mode — See the Counter Mode Constraints section below
- Navigate to Post Views > Integrations
- 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:
-
AMP template mode and Counter Mode mismatch
- AMP JavaScript restrictions vary by template mode (Reader, Transitional, Standard). In Reader mode,
amp-scriptexecution 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.
- AMP JavaScript restrictions vary by template mode (Reader, Transitional, Standard). In Reader mode,
-
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
-
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:
- Verify PHP Mode is selected as the counter mode
- Check that the AMP integration file exists at
includes/integrations/amp.php - Confirm no other plugins are removing required AMP script components
- 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
