Cloudflare Workers Async Google Analytics

☁️ The Cloudflare Workers implementation of an async Google Analytics
Alternatives To Cloudflare Workers Async Google Analytics
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Post Mortems10,270
2 months ago10
A collection of postmortems. Sorry for the delay in merging PRs!
Encrypted Dns1,976
3 months ago12unlicense
DNS over HTTPS config profiles for iOS & macOS
3 months ago56mitHTML
A Google Drive Index built with Vue Running on CloudFlare Workers
7 months ago56JavaScript
Index your Google Drive
a year ago30mitJavaScript
reverse proxy, 反向代理,免翻墙访问Youtube/twitter/Google, 支持telegram web登录。请勿将本项目用于非法用途,否则后果自负。
43 years ago16January 01, 20191apache-2.0Go
A DNS-protocol proxy for DNS-over-HTTPS providers, such as Google and Cloudflare
2 months ago38March 24, 2022mitJavaScript
Netlify replacement to deploy simple websites with better flexibility, speed and without vendor lock-in
Cloudflare Workers Async Google Analytics149
2 years ago5June 16, 20201mitJavaScript
:cloud: The Cloudflare Workers implementation of an async Google Analytics
2 months ago2mitTypeScript
Cloudflare + Google = supercharged web surfing
Gargantuan Takeout Rocket112
24 days ago3
🚀 Backup Google Takeout archives (YouTube channel and Google Photos) at 1GB/s+ to Azure Storage periodically with minimal human toil and financial cost
Alternatives To Cloudflare Workers Async Google Analytics
Select To Compare

Alternative Project Comparisons


Author Sukka License MIT NPM Version Build with Cloudflare Workers Gzip size of cfga.min.js

The Cloudflare Workers implementation of an async Google Analytics


This project is based on Google Analytics Measurement Protocol, using Cloudflare Workers with a less than 1KB gzipped tiny cfga.min.js to accelerate the Google Analytics, rather than a heavy (45KB gzipped) analytics.js from Google.

Get Start

1. Import into Cloudflare Workers

Login into Cloudflare Dashboard and enter Workers App. Create a new script, delete default code in the editor, and then copy the woker.js content into the editor. After saving the workers script, do not forget to register a route for the scripts.

Now you can test your workers with a simple HTTP request. You should able to see 403 Forbidden. Then you can deploy the scripts.

2. Insert the cfga.min.js into your website

Just add those few lines of the code to your website, right before </body>. Do not forget to replace the default configuration with your own!

window.ga_tid = "UA-XXXXX-Y"; // {String} The trackerID of your site.
window.ga_api = ""; // {String} The route of your cloudflare workers you just registered before.
<script src="[email protected]" async></script>

3. Watch this repo with Releases Only.

Click the watch button at the top of the repo and choose Releases Only, so you can get notice of release update in time.


For SPA site

cfga.js will send the data once the window's load event is fired.

But you can still manually send the data again by calling window.cfga(), just like the original analytics.js with ga('send', 'pageview').

Say hello to EasyList

Recently cloudflare-workers-async-google-analytics has been blocked by EasyList. Great Job though. So I am going to play a cat & mouse game now.

From 1.0.3 the random string will be added as a parameter to bypass EasyList. Also, this could help, too:

  • Add the route cfga/jquery.js for your Cloudflare Workers.
  • Use setup as below:
window.ga_api = ""; // {String} The route of your cloudflare workers you just registered before.

Block jquery.js if you can, haha!


Data type the cfga.min.js collected and sent

Currently, cloudflare-workers-async-google-analytics and cfga.min.js only support collect those types of data listed below. If you want to collect more, you should use Google Analytics official track code.

  • dl: Document location URL
  • uip: User real IP
  • ua: User Agent
  • dt: Document Title
  • de: Document Encoding
  • dr: Document Referrer
  • ul: User Language
  • sd: Screen Colors Depth
  • sr: Screen Resolution
  • plt: Page Load Time
  • dns: DNS Time
  • pdt: Page Downloaad Time
  • rrt: Redirect Response Time
  • tcp: TCP Connect Time
  • srt: Server Response Time
  • dit: DOM Interactive Time
  • clt: Content Load Time


cloudflare-workers-async-google-analytics blocks those types of request by default:

  • No User-Agent in request headers
  • No Referer in request headers
  • No Tracker ID given in request headers
  • Use some other measurements from Cloudflare WAF

And if you want to restrict your workers only for your website, all you need to do is to edit a few lines of your workers:

  • Launch Cloudflare Workers Editor again.
  • You can see some commented out code at the first line like this:
//const AllowedReferrer = '';
  • replace your domain with, then remove //.

Notice: set AllowedReferrer value to means all the subdomains of will be allowed as well.


cloudflare-workers-async-google-analytics © Sukka, Released under the MIT License.
Authored and maintained by Sukka with help from contributors (list).

Personal Website · Blog · GitHub @SukkaW · Telegram Channel @SukkaChannel · Twitter @isukkaw · Keybase @sukka

Popular Google Projects
Popular Cloudflare Projects
Popular Companies Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Google Analytics