ChrAlpha / hexo-theme-cards

Another Simple & Swift theme for Hexo
https://theme-cards.ichr.me
GNU General Public License v3.0
421 stars 47 forks source link

添加数据统计服务 Cloudflare Web Analytics #82

Closed bronya5th closed 3 years ago

bronya5th commented 3 years ago

因为是第一次写JavaScript,所以是依照gtag和google的代码来写的,Cloudflare Web Analytics的脚本属性是defer,感觉和async有点相似所以就直接套用了。Cloudflare Web Analytics会验证主机名(hostname)与添加JS代码段的网站是否匹配。测试流程是依照hexo-theme-cards/.github/workflows/test.ymltheme-cards-demo/.github/workflows/deploy.yml来的,应该是可以使用的。

报错提示(本地报错出现这样的提示应该就是可用了):

Access to resource at 'https://cloudflareinsights.com/cdn-cgi/rum' from origin 'http://localhost:4000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'http://localhost' that is not equal to the supplied origin.

Cloudflare Web Analytics的JavaScript 参考片段:

<!-- Cloudflare Web Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "xxxxxxxxxx"}'></script><!-- End Cloudflare Web Analytics -->

参考资料:

  1. https://support.cloudflare.com/hc/en-us/articles/360052685432-Cloudflare-Web-Analytics
  2. 脚本:async,defer (javascript.info)
  3. https://dash.cloudflare.com/sign-up/web-analytics
bronya5th commented 3 years ago

需要更新主题文档么?

ChrAlpha commented 3 years ago

需要更新主题文档么?

合并至 master 分区时会更新文档的