Why Our Analytics Script Gets a Perfect Google PageSpeed Score
Back to blog
web-performance pagespeed analytics caching

Why Our Analytics Script Gets a Perfect Google PageSpeed Score

ClearAnalytics Team · · 4 min read

Google PageSpeed Insights is ruthless. It flags every uncached resource, every render-blocking script, every wasted kilobyte. For most websites running third-party analytics, the tracking script is one of the biggest PageSpeed offenders.

Not with ClearAnalytics.

The Problem with Most Analytics Scripts

When you add Google Analytics (GA4) to your site, you load a 45KB+ script from a third-party domain. Google Tag Manager adds another 80KB+ on top. These scripts:

  • Are loaded from third-party domains, triggering DNS lookups and TLS handshakes
  • Often have short or no cache lifetimes, forcing re-download on every visit
  • Execute immediately, competing with your own JavaScript
  • Set cookies, which means additional data in every request
  • Get flagged by Google PageSpeed for inefficient caching and excessive size

Even privacy-focused alternatives like Plausible (1.5KB) and Fathom (5KB) load from third-party CDNs with varying cache policies.

What We Do Differently

ClearAnalytics takes a fundamentally different approach. Our tracking script:

Under 1KB in size. Our lightweight variant is just 1KB. Even the full tracking script with custom events, click goals, and GA4 dataLayer interception is under 3KB. Compare that to Google Analytics at 45KB+.

First-party serving. The script is served from your own domain at /js/ca.js. No third-party DNS lookups. No cross-origin requests. Your browser already has the connection open.

1-year browser caching. We serve the script with Cache-Control: public, max-age=31536000, immutable and proper ETag headers. After the first visit, the browser uses the cached version for up to a year without making any network request at all.

Deferred loading. The defer attribute means the script never blocks HTML parsing. It downloads in the background and executes after the DOM is ready.

Why Aggressive Caching Matters

Google PageSpeed specifically checks for efficient cache policies on all loaded resources. When a resource has no cache headers or short cache lifetimes, PageSpeed flags it as a performance issue.

With our 1-year immutable cache, returning visitors load the script from disk cache with zero network cost. This means:

  • Zero bytes transferred on repeat page views
  • No DNS lookup, no TLS handshake, no HTTP request
  • Google PageSpeed sees proper caching and does not penalize you
  • Core Web Vitals remain unaffected

Why Others Do Not Do This

Most analytics providers serve scripts from their own CDN (e.g., cdn.plausible.io or cdn.usefathom.com). This has trade-offs:

Third-party origin: The browser needs a separate DNS lookup and TLS handshake. This adds 100-300ms on the first visit, even with HTTP/2.

No control over caching: When scripts are served from a third-party CDN, the website owner cannot set cache headers. The analytics provider controls the cache policy, and most use short or no cache lifetimes to enable rapid script updates.

Ad blocker visibility: Third-party analytics scripts are easy for ad blockers to identify and block. First-party scripts at your own domain path are much harder to detect.

We chose the first-party approach because it gives you, the website owner, full control. Your server, your cache headers, your performance.

Two Script Variants: Choose Your Size

Not every website needs custom event tracking. That is why we offer two variants:

Pageviews Only (ca.js) — under 1KB

  • Pageview and SPA navigation tracking
  • Session duration via the Visibility API
  • UTM campaign attribution
  • 1-year browser caching

Perfect for blogs, landing pages, and content sites that only need traffic insights.

Full Tracking (ca-events.js) — under 3KB

  • Everything from Pageviews Only
  • Custom events API (window.ca('event-name', { props }))
  • Click goal tracking with data-ca-goal attributes
  • GA4 dataLayer interception for e-commerce events

Perfect for SaaS, e-commerce, and apps that need conversion and event tracking.

Measuring the Impact

We tested the impact on a production website using Lighthouse:

  • First Contentful Paint: +0ms
  • Largest Contentful Paint: +0ms
  • Total Blocking Time: +0ms
  • Cumulative Layout Shift: 0
  • Performance Score: 100/100

The script is invisible to Lighthouse and PageSpeed because it is tiny, deferred, and cached.

How to Get Started

Sign up for a free account, add your domain, and pick your script variant. Paste the one-line snippet before your closing </head> tag. Within minutes, you will have accurate analytics data without any impact on your PageSpeed score.

No cookies. No consent banners. No performance penalty. Just clean, accurate analytics.

Enjoyed this article?

Try ClearAnalytics for free and get privacy-first analytics for your website.