Migrate To Cloudflare Web Analytics from Google Analytics

A few days ago, I migrated the web analytics tool for this site. The new tool is Cloudflare Web Analytics, and the old tool is Google Analytics.

This article provides an overview of this migration process.


Why did I migrate the tool?

The reason is that I wanted to prioritize privacy-first tools.

Privacy Regulations of Each Country

In recent years, privacy has become more important. In Japan, the Act on the Protection of Personal Information was enacted in May 2003 and has since been revised multiple times. At the time this article was written, the latest revision occurred in 2021, and it came into effect this year (2023).

It regulates the use of cookies and stealth marketing practices.

In the European Union (EU), the General Data Protection Regulation (GDPR) came into effect in May 2018. In California, the California Consumer Privacy Act (CCPA) was enacted in June 2018 and came into effect in January 2020.

Privacy Protection of Web Advertisement

Web Advertisement Platforms also work to protect privacy. Since January 16, 2024, web publishers must use the CMP, which supports IAB TCF v2.0 and is approved by Google to display the ads on their websites to the EU region and UK audience with Google AdSense.

On sites that support IAB TCF 2.0, advertisements, even those that are not personalized, may not be displayed without user consent.

The revenue from advertisements will decrease, making it challenging for websites to operate solely on ad revenue. They should find other methods other than advertisements.

About Cloudflare Web Analytics

Cloudflare Web Analytics is a free web analyzing tool. It is privacy first and has the following features.

  • It doesn’t use the client-side state such as cookies and localStorage.
  • It doesn’t use the “fingerprint”.

I also integrated it easily into my site.

How to adapt it

Follow the steps below to add Cloudflare Web Analytics to your website.

  1. Remove old analytics tools if you have used them.
  2. Add your website to Cloudflare.
  3. Insert the generated JS (JavaScript) code before the ending of the body tag.

Remove Old Tools

This website used Google Analytics. I also use the SEO plugin, which supports GA, and I entered the tracking code into the plugin. I cleared it and turned off the plugin.

Add the Website

Add the website to the Web Analytics. You can add any sites, including those that do not use Cloudflare.

Open the “Web Analytics” of “Analytics & Logs” on the Cloudflare Dashboard.
Click “Add a site” in “Quick Actions” column.
Click "Add a site" in "Quick Actions" column.
Enter the host of the Website’s URL and click the “Done” button.

For example, the hostname is www.rk-k.com for this site. If you enter a site that is not registered with Cloudflare, the message “Click here to use www.rk-k.com which does not belonged to Cloudflare websites” will appear. Then click it.

Enter the host of the Website's URL and click the "Done" button.
The JS code snippet appears. Copy it.
Copy the generated JS code snippet.

Insert the Code

Insert the copied code before the ending of the body tag. This website uses the “SWELL” theme of WordPress, so I introduce the method for this theme.

Open the WordPress dashboard.
Select the “Customize” from the “Appearance” menu.
Select the "Customize" from the "Appearance" menu.
Click the “高度な設定” (Advanced Settings).
Click the "高度な設定" (Advanced Settings).
Insert the copied JS code into the field “bodyタグ終了直前に出力するコード” (Just before the ending of the body tag).
Insert the copied JS code into the field "bodyタグ終了直前に出力するコード" (Just before the ending of the body tag).
Click the “Publish” button.

Update the Privacy Policy

My privacy policy describes the web analytics tool, so I must update the privacy policy.

Erase the description about Google Analytics usage and add the description about Cloudflare Web Analytics usage. For example, the following description is available in my privacy policy. If you want to see the latest version, click here.

About the Traffic Analytics Tool

This site uses Cloudflare Web Analytics. It doesn’t use cookies and localStorage. Traffic data is anonymized, and it doesn’t specify the person.

For more about Cloudflare Web Analytics, see the official website.

Disconnect the Linked Services (Applications)

One of my websites uses Google AdSense, and my AdSense account is linked to Google Analytics. Surprisingly, Google Analytics continued to receive metrics from that site even after I removed the GA tracking code. I am still trying to figure out the reason. The reason may be cache. The cache containing the tracking code may still be alive.

Clear the Cache

This site uses two caches: SWELL built-in cache and Cloudflare cache. These caches contain tracking codes, so I need to purge them.

Clear the SWELL Contents Cache

To clear the SWELL contents cache, follow the steps below.

Open the WordPress dashboard.
Select the “Cache clear (Contents)” from the “SWELL Settings” menu.
Select the "Cache clear (Contents)" from the "SWELL Settings" menu.

Clear the Cloudflare Cache

My site uses the Cloudflare plugin for WordPress. It can purge the cache. Follow the steps below.

Open the WordPress dashboard.
Select the “Cloudflare” from the “Settings” menu.
Select the "Cloudflare" from the "Settings" menu.
Click the “Purge Cache” button in the “Home” tab, and select “Purge Everything”.
Click the "Purge Cache" button in the "Home" tab, and select the "Purge Everything".


Cloudflare Web Analytics is more straightforward than Google Analytics.

However, I can see the page views, the visitors count, the countries of visitors, etc. I can also see the page loading time. Cloudflare web analytics removes the metrics of the bot.

It quickly and frequently updates the data. It updates the metrics of new visitors in a few minutes.

Authored Books

Let's share this post !

Author of this article

Akira Hayashi (林 晃)のアバター Akira Hayashi (林 晃) Representative(代表), Software Engineer(ソフトウェアエンジニア)

アールケー開発代表。Appleプラットフォーム向けの開発を専門としているソフトウェアエンジニア。ソフトウェアの受託開発、技術書執筆、技術指導・セミナー講師。note, Medium, LinkedIn
Representative of RK Kaihatsu. Software Engineer Specializing in Development for the Apple Platform. Specializing in contract software development, technical writing, and serving as a tech workshop lecturer. note, Medium, LinkedIn