npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cfga

v1.0.3

Published

The Cloudflare Workers implementation of an async Google Analytics

Downloads

40

Readme

cloudflare-workers-async-google-analytics

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

Introduction

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!

<script>
window.ga_tid = "UA-XXXXX-Y"; // {String} The trackerID of your site.
window.ga_api = "https://example.com/xxx/"; // {String} The route of your cloudflare workers you just registered before.
</script>
<script src="https://cdn.jsdelivr.net/npm/[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.

Notice

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 = "https://example.com/cfga/jquery.js"; // {String} The route of your cloudflare workers you just registered before.

Block jquery.js if you can, haha!

Advanced

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

Security

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 = 'skk.moe';
  • replace your domain with skk.moe, then remove //.

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

Author

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