Skip to content

Commit

Permalink
feat: expose a global funtion window.cfga
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jun 16, 2020
1 parent 56f54ee commit 4e6ac69
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions README.md
Expand Up @@ -31,7 +31,7 @@ Just add those few lines of the code to your website, right before `</body>`. Do
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/cfga@1.0.2" async></script>
<script src="https://cdn.jsdelivr.net/npm/cfga@1.0.3" async></script>
```

### 3. Watch this repo with `Releases Only`.
Expand All @@ -40,9 +40,17 @@ Click the `watch` button at the top of the repo and choose `Releases Only`, so y

## 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](https://github.com/easylist/easylist/commit/2ce2444193f5d479fb131e9dc89bbde9c82c8ad1). Great Job though. So I am going to play a cat & mouse game now.

From `1.0.2` the random string will be added as a parameter to bypass EasyList. Also, this could help, too:
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:
Expand Down
2 changes: 2 additions & 0 deletions cfga.js
Expand Up @@ -59,6 +59,8 @@
window.__ga_img.src = window.ga_api + '?' + pv_data.join('&');
}

window.cfga = sendGA;

if (document.readyState === 'complete') {
sendGA();
} else {
Expand Down
2 changes: 1 addition & 1 deletion cfga.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "cfga",
"version": "1.0.2",
"version": "1.0.3",
"description": "The Cloudflare Workers implementation of an async Google Analytics",
"main": "cfga.min.js",
"scripts": {
Expand Down

0 comments on commit 4e6ac69

Please sign in to comment.