Skip to content

Post By

Does Cloudflare Cache Affect Google Analytics Tracking? GA4 Explained

If you use Cloudflare and Google Analytics 4 (GA4), you may eventually notice something that looks suspicious.

Maybe GA4 traffic suddenly drops. Maybe Realtime stops showing your visits. Or maybe your server logs show much more traffic than Google Analytics.

The obvious question is:

Does Cloudflare cache affect Google Analytics tracking?

The short answer is no, not normally.

With a standard Google Analytics setup, Cloudflare caching does not stop GA4 from tracking visitors. Cloudflare serves your website to the visitor, but the Google Analytics JavaScript runs inside the visitor’s browser and sends analytics data directly to Google.

Cloudflare itself confirms that using Cloudflare does not affect Google Analytics when GA is installed using Google’s recommended methods.

However, there are a few Cloudflare settings and unusual configurations that can indirectly cause tracking problems.

Let’s look at exactly what happens.

How Cloudflare and Google Analytics work together

It helps to separate the two systems.

A normal page request looks roughly like this:

Visitor
   ↓
Cloudflare
   ↓
Your website/server

Cloudflare sits between your visitor and your hosting server.

It may serve cached images, JavaScript, CSS and other files without contacting your server every time.

Google Analytics works differently.

After the browser receives your page, the Google tag runs in the browser:

Visitor's browser
   ↓
Google Analytics / Google Tag Manager
   ↓
Google

The GA4 request does not normally travel through your website’s Cloudflare proxy.

That is the important difference.

Cloudflare can serve your page from cache while the visitor’s browser still executes Google Analytics normally.

Cloudflare’s documentation explains that the Google Analytics JavaScript sends traffic directly from the user’s browser rather than through your origin server.

So a Cloudflare HIT does not mean GA4 loses that pageview.

Does Cloudflare cache the Google Analytics script?

Normally, no.

Cloudflare caches resources that belong to websites proxied through Cloudflare. It does not simply take third-party resources hosted elsewhere and put them into your website’s Cloudflare cache.

For example, the standard Google tag loads from Google’s infrastructure.

The basic GA4 implementation looks similar to this:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>

That file belongs to Google, not your website.

Cloudflare’s cache therefore is not sitting between the visitor and that Google-hosted JavaScript simply because your website uses Cloudflare.

Cloudflare also states that it does not cache off-site third-party resources through your site’s normal cache.

What does Cloudflare cache by default?

By default, Cloudflare mainly caches static resources such as:

  • Images
  • CSS
  • JavaScript files
  • Fonts
  • PDFs
  • Videos and other static files

Normal HTML pages are not cached by Cloudflare by default.

Cloudflare specifically states that its CDN does not cache HTML or JSON by default. You can change this behaviour using Cache Rules if you want Cloudflare to cache HTML pages.

For a normal WordPress website using the standard Cloudflare configuration, this means Cloudflare caching itself should have almost no reason to interfere with GA4.

But there are exceptions.

1. You are caching the entire HTML page

This is the first thing I would check if Google Analytics stopped working after changing Cloudflare settings.

Cloudflare allows you to create Cache Rules that make HTML pages eligible for caching.

This can be useful for performance, but it changes the situation slightly.

Imagine that your website originally contains:

G-OLD123456

You then change your GA4 Measurement ID to:

G-NEW789012

Your origin server now has the new code.

But if Cloudflare still has the old HTML page cached, some visitors may temporarily receive the version containing the old Google Analytics tag.

The same problem can happen if you:

  • Add Google Analytics for the first time
  • Remove GA4
  • Change a GTM container ID
  • Modify a consent-management script
  • Change the location of your tracking code

This does not mean Cloudflare is blocking Google Analytics.

It means Cloudflare is serving an older version of your HTML.

Cloudflare warns that making everything cacheable can include HTML and dynamic content, so these rules need to be configured carefully.

The fix

If you recently changed your analytics code:

  1. Purge the relevant Cloudflare cache.
  2. Purge your WordPress caching plugin or server cache.
  3. Open the website in an Incognito/Private browser window.
  4. View the page source.
  5. Search for your GA4 Measurement ID or GTM container ID.

Make sure the ID shown in the HTML is the one you expect.

2. Rocket Loader is affecting your JavaScript

This is probably the most important Cloudflare-specific issue to test.

Cloudflare Rocket Loader attempts to improve page rendering by changing how JavaScript loads.

It can defer both inline and external JavaScript.

For most websites this may work without any problem.

But analytics setups can become complicated when you have:

  • Google Tag Manager
  • GA4
  • Cookie consent software
  • Advertising pixels
  • Custom JavaScript events
  • Conversion tracking
  • WordPress optimisation plugins

You may then have multiple scripts that depend on each other loading in a specific order.

If your tracking worked before enabling Rocket Loader and stopped immediately afterwards, Rocket Loader is a reasonable thing to test.

Test Rocket Loader

Temporarily disable:

Cloudflare → Speed → Settings → Content Optimization → Rocket Loader

Then test GA4 again.

Cloudflare itself recommends disabling Rocket Loader and retesting when JavaScript problems appear.

If Rocket Loader is the problem, you do not necessarily need to disable it for your entire site.

Cloudflare lets you exclude individual JavaScript files using:

data-cfasync="false"

For example:

<script data-cfasync="false" src="/javascript.js"></script>

Cloudflare also supports excluding specific pages using Configuration Rules.

I would not immediately start adding exclusions everywhere, though.

First prove that Rocket Loader is actually causing the problem.

3. Your GA4 installation may be the real problem

Cloudflare often gets blamed because it is an obvious layer sitting in front of the website.

But if GA4 is not collecting data, the problem may have nothing to do with caching.

Google lists several common reasons for missing Analytics data, including:

  • Google tag not installed
  • Google tag installed incorrectly
  • GTM changes not published
  • Tag missing from some pages
  • Incorrect Measurement ID
  • Analytics data still processing

Google also warns against accidentally installing both a direct Google tag and Google Tag Manager configuration in a way that causes duplicate tracking.

Before changing Cloudflare settings, verify the GA4 implementation itself.

4. Cookie consent can make GA4 appear broken

This has become increasingly common.

If your website uses a cookie consent platform, GA4 may intentionally not fire until the visitor gives the required consent.

A setup might look like:

Visitor opens website
      ↓
Consent banner loads
      ↓
Analytics permission checked
      ↓
GA4 allowed or restricted

If the consent tool fails, loads too late or is configured incorrectly, GA4 may not start.

This becomes especially confusing when Cloudflare, a WordPress optimisation plugin and a cookie plugin are all manipulating JavaScript.

You might disable Cloudflare and suddenly see Analytics working again.

That does not automatically prove the cache was the cause.

A JavaScript execution-order issue may have been the real problem.

5. Ad blockers and browser privacy features affect GA4

Another common mistake is testing Google Analytics using your normal browser.

Many browser extensions block analytics scripts.

Privacy tools may also restrict tracking.

So you visit your website, open GA4 Realtime and see nothing.

Before assuming your implementation is broken, test with:

  • An Incognito/Private window
  • Extensions disabled
  • A different browser
  • A phone using mobile data

Then check Realtime again.

Google says the Realtime report can normally be used to verify activity shortly after generating traffic on the website.

6. Server analytics and GA4 will not show the same numbers

This is another place where Cloudflare creates confusion.

Suppose you compare GA4 against:

  • AWStats
  • cPanel statistics
  • Nginx logs
  • Apache logs
  • Hosting analytics

The numbers will probably be different.

And after enabling Cloudflare caching, the difference may become even larger.

Why?

Because if Cloudflare serves a cached resource, the request may never reach your origin server.

That changes what your origin server logs.

Google Analytics is measuring something different: browser-based visitor activity.

Cloudflare specifically notes that while normal Google Analytics tracking is unaffected, server-log-based analytics such as AWStats can be affected because some requests never reach the origin.

So don’t expect:

Server requests = GA4 pageviews

They are not measuring the same thing.

7. Cloudflare Zaraz is different

There is one major exception to everything above.

Cloudflare offers Zaraz, which can run analytics and marketing tools through Cloudflare rather than loading the normal third-party scripts in the browser.

GA4 can be configured through Zaraz.

If you use Zaraz, then you are no longer talking about a standard browser-based GA4 implementation.

Cloudflare states that some normal GA4 functionality is not automatically available through Zaraz.

For example, Cloudflare’s current documentation says that some GA4 automatic events that normally come from the standard JavaScript implementation need to be manually configured using Zaraz triggers and actions.

So if you use:

Cloudflare Zaraz + GA4

troubleshoot Zaraz separately.

Do not apply every normal gtag.js or GTM troubleshooting guide to it.

How I would troubleshoot Cloudflare + GA4

If GA4 stopped collecting traffic after you enabled or changed Cloudflare, I would troubleshoot it in this order.

Step 1: Check GA4 Realtime

Open your website yourself and look at the GA4 Realtime report.

Don’t wait for normal GA4 reports to update.

Step 2: Use Google Tag Assistant

Google’s Tag Assistant is one of the easiest ways to check whether the Google tag is actually loading and sending data.

Google recommends Tag Assistant when verifying both direct Google tag and Google Tag Manager implementations.

Step 3: Check the source code

Search your rendered source for:

G-

or:

GTM-

Confirm that the correct ID exists.

Step 4: Purge caches

If you recently changed your tracking code, purge:

  • Cloudflare cache
  • WordPress caching plugin
  • Server-level cache
  • CDN/page cache if another service is involved

Step 5: Temporarily disable Rocket Loader

Retest the website.

If GA4 suddenly works, investigate JavaScript loading order instead of disabling Cloudflare completely.

Step 6: Check your consent system

Test once with analytics consent granted.

Then check whether the GA4 requests appear.

Step 7: Test without browser extensions

Use another browser or Incognito mode.

Step 8: Check Google Tag Diagnostics

Google now provides Tag Diagnostics to identify problems such as pages without tags, tags positioned incorrectly and missing Google tag configuration.

This should usually tell you much more than simply turning Cloudflare on and off.

Should you disable Cloudflare to fix Google Analytics?

Usually, no.

Disabling your CDN should not be the first solution to an analytics problem.

You would be removing performance, caching and security benefits without identifying the actual cause.

Instead, isolate the problem.

Try:

GA4 test
↓
Purge cache
↓
Test again
↓
Disable Rocket Loader
↓
Test again
↓
Check consent
↓
Check Tag Assistant

Change one thing at a time.

Otherwise, you can easily “fix” the problem without knowing what actually caused it.

Does Cloudflare Cache Affect Google Analytics Tracking? Final Answer

For a normal GA4 or Google Tag Manager installation, Cloudflare caching does not normally affect Google Analytics tracking.

The page may come from Cloudflare’s cache, but GA4 still runs in the visitor’s browser and communicates with Google separately.

Problems are more likely when:

  • You cache HTML and an old analytics tag remains cached.
  • Rocket Loader changes JavaScript execution.
  • A cookie consent tool prevents GA4 from firing.
  • Your GA4/GTM installation is incorrect.
  • A browser or extension blocks analytics.
  • You use Cloudflare Zaraz instead of the standard Google Analytics implementation.

So if your GA4 traffic drops after enabling Cloudflare, don’t immediately assume:

“Cloudflare is caching my Google Analytics.”

In most cases, it isn’t.

Check the tag itself, JavaScript execution, consent setup and browser requests first.

Useful official documentation

For further troubleshooting, these are the sources I would start with: