How Cloudflare Impacts Google Analytics Stats
Impact of Cloudflare on Google Analytics Stats
Cloudflare claims that using Cloudflare does not affect Google Analytics tracking. But we have found that the use of Cloudflare can impact your Google Analytics tracking. It can also negatively impact your website stats.
For example, Cloudflare provides a feature called ‘Rocket Loader’ to improve website speed:
However, you should avoid enabling this feature because once enabled, Cloudflare automatically adds type = “text/rocketscript” (instead of type =“text/javascript”) to all the JavaScript codes embedded on your website.
This new addition can create issues with your Google Analytics tracking code or Google Tag Manager container code.
For example, the regular Google Analytics tracking code (gtag.js) looks like this:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1509844-26"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-123456-78');
</script>
But if you are using Cloudflare (with Rocket Loader enabled), then this code will look like the one below (when you view the source code of a web page):
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1509844-26"></script>
<script type="text/rocketscript">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-123456-78');
</script>
Here Cloudflare automatically added the ‘type = ‘text/rocketscript’ in the Google Analytics tracking code. This could result in your tracking code not firing or not working normally.
If you want Rocket Loader to ignore individual scripts, then add the data-cfasync=”false” attribute to the relevant script tag. For example,
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1509844-26"></script>
<script data-cfasync="false">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-123456-78');
</script>
Similarly, the regular Google Tag Manager container code looks like this:
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-AB9VD94');</script>
<!-- End Google Tag Manager -->
But if you are using Cloudflare (with Rocket Loader enabled), then this code will look like the one below (when you view the source code of a web page):
<!-- Google Tag Manager -->
<script type="text/rocketscript">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-AB9VD94');</script>
<!-- End Google Tag Manager -->
Here Cloudflare automatically added the ‘type = ‘text/rocketscript’ in the GTM code. Because of this reason, the Google Tag Manager is not able to recognize the GTM tag.
To fix this problem, add data-cfasync=”false” to the script tag. So your final GTM code would now look like the one below:
<!-- Google Tag Manager -->
<script data-cfasync="false">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-AB9VD94');</script>
<!-- End Google Tag Manager -->
The Rocket Loader feature of Cloudflare can also negatively impact other tracking scripts on your website. So we like to keep this feature disabled.
Cloudflare provides another feature called ‘Auto Minify’ through which you can minify JavaScript:
We like to keep this feature disabled because minifying JavaScript tends to create tracking issues (like underreporting of GA sessions) with Google Analytics.
The Cloudflare Pro plan could skew your Google Analytics stats and/or negatively impact your SEO traffic
We switched to Cloudflare pro (the paid version of Cloudflare) last year in order to improve website performance and get added security:
Ever since we moved to Cloudflare pro, our overall website traffic continued to decline week after week, month after month. The biggest negative impact was on organic search traffic.
Earlier we couldn’t figure out what was going wrong. The Google search console wasn’t showing any warning or penalty. We continue to add/update new content all the time as usual.
Then one day I read a couple of articles on how Cloudflare can negatively impact SEO traffic. Yes, the free version of Cloudflare which half of the world uses.
It turned out that it does negatively impact the traffic of certain websites. But since we have been using the free version of Cloudflare for over a decade without any issue, this should not be the reason for the decline in our website traffic.
But something has changed, the way we use Cloudflare now. Yes, now we use the “paid version” of Cloudflare. Bingo.
Having run out of all the options to stop website traffic from declining further, we cancelled the Cloudflare pro plan just to test how it impacts website traffic.
Within a week, website traffic increased by 10% and it continues to increase ever since. Then I concluded that it wasn’t Cloudflare but some particular settings of Cloudflare which were causing the issue.
And that setting seems to be the ‘Firewall Managed Rules‘ which gets automatically enabled when you switch to the pro plan:
If you get the chance to look at the rules, they are not straightforward and easy to understand. And you don’t really know what these rules are doing to your website traffic.
When you upgrade to pro, the Cloudflare firewall seems to become more strict and it seems to start messing up with even good bots (like Google bots), creating all sorts of crawling and indexing issues.
I haven’t done any exhaustive research or testing on dozens of websites to label my conclusion as definitive proof. But I am pretty confident that at least for our website that this is the case.
And it could be a new direction for you to explore when you are struggling with the continuous decline in website traffic.
Also depending upon the Firewall setting you use, Cloudflare can show captcha to website visitors or even logged in users thus increasing the website bounce rate (as many visitors would rather leave your website than solve a captcha).
There is always a possibility that Cloudflare end up blocking a lot of legitimate traffic to your website.
Google Analytics debugging issues due to Cloudflare Caching
You may be in a situation where you are making a lot of code changes to your website but no changes are reflected back in your Google Analytics real-time reports. As a result, you are having a hard time debugging Google Analytics and Google Tag Manager issues.
There is a high probability that because of Cloudflare’s caching, your web browser keeps loading the previous version of your web page. Because of that your code changes either do not load correctly or they do not load at all in your web browser.
You may need to either temporarily disable the Cloudflare on your website or delete the cache of the webpage where you are making code changes.
In order to temporarily disable Cloudflare on your website, follow the steps below:
Step-1: Login to your Cloudflare account and then navigate to the website on which you want to disable Cloudflare:
Step-2: Click on the ‘Overview’ tab and then click on the link ‘Pause Cloudflare on site’ under ‘Advanced Actions’:
If you want to delete the cache of the webpage where you are making code changes then follow these steps:
Step-1: Login to your Cloudflare account and then navigate to the website whose web page’s cache you want to delete.
Step-2: Click on the ‘Caching’ drop-down menu:
Step-3: Click on the ‘Configuration’ link and then click on the ‘Custom Purge’ button:
Step-4: Enter one or more URLs of the web pages whose cache you want to delete and then click on the ‘Purge’ button:
That’s how you can delete the cache of web pages via Cloudflare and test the code changes you made for GA/GTM debugging.
Cloudflare visitor stats are different from Google Analytics stats
Cloudflare provides a free website analytics report which you can access by following the steps below:
Step-1: Login to your Cloudflare account and then navigate to the website whose analytics data you want to see.
Step-2: Click on the ‘Analytics’ drop-down menu:
Step-3: Click on the ‘Unique Visitors’ tab:
You should now see a report like the one below:
The unique visitors that you see in this report is unlikely to match with the total users you see in your Google Analytics Audience Overview report. You are more than likely to see a much larger number of visitors to your website in Cloudflare analytics than in Google Analytics.
This is because Cloudflare also counts all the bot traffic to your website as visitors whereas Google Analytics does not.
If you use the Cloudflare pro plan, you get access to more detailed web analytics reports:
Again the visits and pageviews reported by Cloudflare won’t match with the Google Analytics sessions and pageviews for the same time period. Because Cloudflare uses a different tracking mechanism than Google Analytics.
Cloudflare analytic reports are very surface level. It is not a substitute for GA. Not even remotely close.
Impact of Cloudflare on Google Analytics Stats
Cloudflare claims that using Cloudflare does not affect Google Analytics tracking. But we have found that the use of Cloudflare can impact your Google Analytics tracking. It can also negatively impact your website stats.
For example, Cloudflare provides a feature called ‘Rocket Loader’ to improve website speed:
However, you should avoid enabling this feature because once enabled, Cloudflare automatically adds type = “text/rocketscript” (instead of type =“text/javascript”) to all the JavaScript codes embedded on your website.
This new addition can create issues with your Google Analytics tracking code or Google Tag Manager container code.
For example, the regular Google Analytics tracking code (gtag.js) looks like this:
<!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-1509844-26"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-123456-78'); </script>
But if you are using Cloudflare (with Rocket Loader enabled), then this code will look like the one below (when you view the source code of a web page):
<!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-1509844-26"></script> <script type="text/rocketscript"> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-123456-78'); </script>
Here Cloudflare automatically added the ‘type = ‘text/rocketscript’ in the Google Analytics tracking code. This could result in your tracking code not firing or not working normally.
If you want Rocket Loader to ignore individual scripts, then add the data-cfasync=”false” attribute to the relevant script tag. For example,
<!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-1509844-26"></script> <script data-cfasync="false"> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-123456-78'); </script>
Similarly, the regular Google Tag Manager container code looks like this:
<!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-AB9VD94');</script> <!-- End Google Tag Manager -->
But if you are using Cloudflare (with Rocket Loader enabled), then this code will look like the one below (when you view the source code of a web page):
<!-- Google Tag Manager --> <script type="text/rocketscript">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-AB9VD94');</script> <!-- End Google Tag Manager -->
Here Cloudflare automatically added the ‘type = ‘text/rocketscript’ in the GTM code. Because of this reason, the Google Tag Manager is not able to recognize the GTM tag.
To fix this problem, add data-cfasync=”false” to the script tag. So your final GTM code would now look like the one below:
<!-- Google Tag Manager --> <script data-cfasync="false">(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-AB9VD94');</script> <!-- End Google Tag Manager -->
The Rocket Loader feature of Cloudflare can also negatively impact other tracking scripts on your website. So we like to keep this feature disabled.
Cloudflare provides another feature called ‘Auto Minify’ through which you can minify JavaScript:
We like to keep this feature disabled because minifying JavaScript tends to create tracking issues (like underreporting of GA sessions) with Google Analytics.
The Cloudflare Pro plan could skew your Google Analytics stats and/or negatively impact your SEO traffic
We switched to Cloudflare pro (the paid version of Cloudflare) last year in order to improve website performance and get added security:
Ever since we moved to Cloudflare pro, our overall website traffic continued to decline week after week, month after month. The biggest negative impact was on organic search traffic.
Earlier we couldn’t figure out what was going wrong. The Google search console wasn’t showing any warning or penalty. We continue to add/update new content all the time as usual.
Then one day I read a couple of articles on how Cloudflare can negatively impact SEO traffic. Yes, the free version of Cloudflare which half of the world uses.
It turned out that it does negatively impact the traffic of certain websites. But since we have been using the free version of Cloudflare for over a decade without any issue, this should not be the reason for the decline in our website traffic.
But something has changed, the way we use Cloudflare now. Yes, now we use the “paid version” of Cloudflare. Bingo.
Having run out of all the options to stop website traffic from declining further, we cancelled the Cloudflare pro plan just to test how it impacts website traffic.
Within a week, website traffic increased by 10% and it continues to increase ever since. Then I concluded that it wasn’t Cloudflare but some particular settings of Cloudflare which were causing the issue.
And that setting seems to be the ‘Firewall Managed Rules‘ which gets automatically enabled when you switch to the pro plan:
If you get the chance to look at the rules, they are not straightforward and easy to understand. And you don’t really know what these rules are doing to your website traffic.
When you upgrade to pro, the Cloudflare firewall seems to become more strict and it seems to start messing up with even good bots (like Google bots), creating all sorts of crawling and indexing issues.
I haven’t done any exhaustive research or testing on dozens of websites to label my conclusion as definitive proof. But I am pretty confident that at least for our website that this is the case.
And it could be a new direction for you to explore when you are struggling with the continuous decline in website traffic.
Also depending upon the Firewall setting you use, Cloudflare can show captcha to website visitors or even logged in users thus increasing the website bounce rate (as many visitors would rather leave your website than solve a captcha).
There is always a possibility that Cloudflare end up blocking a lot of legitimate traffic to your website.
Google Analytics debugging issues due to Cloudflare Caching
You may be in a situation where you are making a lot of code changes to your website but no changes are reflected back in your Google Analytics real-time reports. As a result, you are having a hard time debugging Google Analytics and Google Tag Manager issues.
There is a high probability that because of Cloudflare’s caching, your web browser keeps loading the previous version of your web page. Because of that your code changes either do not load correctly or they do not load at all in your web browser.
You may need to either temporarily disable the Cloudflare on your website or delete the cache of the webpage where you are making code changes.
In order to temporarily disable Cloudflare on your website, follow the steps below:
Step-1: Login to your Cloudflare account and then navigate to the website on which you want to disable Cloudflare:
Step-2: Click on the ‘Overview’ tab and then click on the link ‘Pause Cloudflare on site’ under ‘Advanced Actions’:
If you want to delete the cache of the webpage where you are making code changes then follow these steps:
Step-1: Login to your Cloudflare account and then navigate to the website whose web page’s cache you want to delete.
Step-2: Click on the ‘Caching’ drop-down menu:
Step-3: Click on the ‘Configuration’ link and then click on the ‘Custom Purge’ button:
Step-4: Enter one or more URLs of the web pages whose cache you want to delete and then click on the ‘Purge’ button:
That’s how you can delete the cache of web pages via Cloudflare and test the code changes you made for GA/GTM debugging.
Cloudflare visitor stats are different from Google Analytics stats
Cloudflare provides a free website analytics report which you can access by following the steps below:
Step-1: Login to your Cloudflare account and then navigate to the website whose analytics data you want to see.
Step-2: Click on the ‘Analytics’ drop-down menu:
Step-3: Click on the ‘Unique Visitors’ tab:
You should now see a report like the one below:
The unique visitors that you see in this report is unlikely to match with the total users you see in your Google Analytics Audience Overview report. You are more than likely to see a much larger number of visitors to your website in Cloudflare analytics than in Google Analytics.
This is because Cloudflare also counts all the bot traffic to your website as visitors whereas Google Analytics does not.
If you use the Cloudflare pro plan, you get access to more detailed web analytics reports:
Again the visits and pageviews reported by Cloudflare won’t match with the Google Analytics sessions and pageviews for the same time period. Because Cloudflare uses a different tracking mechanism than Google Analytics.
Cloudflare analytic reports are very surface level. It is not a substitute for GA. Not even remotely close.
My best selling books on Digital Analytics and Conversion Optimization
Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.
Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.
Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.
Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.