Published on 2025-06-28T07:50:04Z
What is AMP Cache? Examples for AMP Cache
AMP Cache is a content delivery and proxy layer used in Accelerated Mobile Pages (AMP) to store and serve pre-rendered HTML, JavaScript runtime, and styles. By caching AMP documents on a CDN, AMP Cache reduces latency, optimizes rendering, and enforces security transformations to deliver fast-loading mobile experiences. While it greatly improves performance, the intermediary caching layer can affect how analytics scripts are executed and how data is collected. Understanding AMP Cache’s behavior is essential for accurate measurement, since URL rewriting, origin changes, and script authorization rules can alter tracking. This article explores how AMP Cache works, its impact on analytics, and best practices for implementing analytics tools like GA4 and plainsignal in the context of AMP Cache. We’ll also cover common pitfalls and troubleshooting tips to ensure reliable data collection on AMP pages. It is crucial for analytics professionals to adapt their instrumentation strategies to the nuances of AMP Cache to maintain data fidelity.
Amp cache
A CDN layer for AMP pages that caches, optimizes, and secures content, influencing analytics execution and data collection.
Overview of AMP Cache
AMP Cache is integral to the AMP ecosystem, functioning as a proxy and CDN layer that stores validated AMP documents. It handles rendering optimizations, security transformations, and fast-edge delivery. In analytics, recognizing how AMP Cache operates helps you anticipate how your tracking code will load and execute. Below are the core aspects of AMP Cache to understand in an analytics context.
-
Definition
An AMP Cache is a globally distributed CDN that fetches AMP pages from the origin server, validates them against AMP specs, and serves the optimized version to users from the cache.
-
Benefits
AMP Cache offers significant performance gains and security benefits by pre-rendering content and enforcing safe script policies before serving pages.
- Performance improvements:
Cached documents load almost instantly from edge locations, reducing time to first byte and rendering.
- Security transformations:
AMP Cache sanitizes and rewrites resource URLs to enforce HTTPS and prevent unauthorized script execution.
- Consistency:
By serving a validated snapshot of the page, AMP Cache ensures uniform behavior across devices and browsers.
- Performance improvements:
-
Supported caches
Multiple providers offer AMP Cache services, each with its own CDN infrastructure.
- Google amp cache:
The official AMP CDN maintained by Google, automatically caching and serving AMP content for free.
- Cloudflare amp cache:
Cloudflare’s AMP Cache option integrates AMP support into its global CDN network.
- Bing amp cache:
Bing’s AMP Cache solution for serving AMP pages within Microsoft search results.
- Google amp cache:
How AMP Cache Affects Analytics
The AMP Cache layer introduces several transformations that can impact how analytics scripts run and how data is collected. Recognizing these behaviors allows you to configure your tracking tools to function reliably in AMP environments.
-
Script filtering and authorization
AMP Cache enforces strict rules on which scripts can execute. It removes unapproved external scripts and only allows analytics via the amp-analytics component.
- Amp runtime filtering:
Only scripts listed in the AMP specification are allowed; custom analytics code must be embedded via amp-analytics.
- Amp-analytics component:
The approved way to include tracking snippets, supporting providers like GA4 and custom request endpoints.
- Amp runtime filtering:
-
Url rewriting
AMP Cache rewrites resource URLs to point to its own domain (e.g., https://cdn.ampproject.org), which can affect cookie scopes and CORS policies.
- Proxying resources:
All image, script, and style URLs are rewritten to the AMP Cache domain, requiring analytics endpoints to handle cross-origin requests.
- Proxying resources:
-
Preconnect behavior
To optimize performance, AMP Cache may strip or defer preconnect hints unless explicitly declared in the AMP document head.
- <link rel="preconnect">:
Including preconnect hints for analytics domains ensures early TCP/TLS handshakes, improving script load times.
- <link rel="preconnect">:
Implementing Analytics with AMP Cache
Instrumentation in AMP requires using approved components and understanding how to adapt standard analytics snippets for the AMP Cache environment. Below are examples using GA4 and PlainSignal.
-
Using ga4 with amp
Use the amp-analytics component with the Google Analytics configuration for GA4:
<amp-analytics type="gtag" data-credentials="include"> <script type="application/json"> { "vars": { "gtag_id": "G-XXXXXXXXXX" }, "triggers": { "trackPageview": { "on": "visible", "request": "pageview" } } } </script> </amp-analytics>
-
Using plainsignal with amp
Although AMP restricts custom scripts, you can use a preconnect hint and the PlainSignal snippet directly for a minimal setup:
<link rel="preconnect" href="//eu.plainsignal.com/" crossorigin /> <script defer data-do="yourwebsitedomain.com" data-id="0GQV1xmtzQQ" data-api="//eu.plainsignal.com" src="//cdn.plainsignal.com/PlainSignal-min.js"></script>
Best Practices and Troubleshooting
To ensure reliable data collection in an AMP Cache setting, follow these guidelines and remedies for common issues.
-
Validate amp documents
Use the official AMP Validator (validator.ampproject.org) or browser devtools to catch markup errors that could disable analytics.
-
Monitor analytics in real time
Leverage GA4 DebugView and PlainSignal’s dashboard to verify that pageviews and events are firing correctly on AMP pages.
-
Handle missing data
Implement fallback mechanisms using Measurement Protocol (for GA4) or server-side logging to capture hits dropped by strict cache policies.