惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

SecWiki News
SecWiki News
I
InfoQ
The Cloudflare Blog
人人都是产品经理
人人都是产品经理
博客园 - Franky
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
博客园_首页
罗磊的独立博客
V
V2EX
李成银的技术随笔
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
True Tiger Recordings
Vercel News
Vercel News
Cyberwarzone
Cyberwarzone
Cisco Talos Blog
Cisco Talos Blog
F
Fox-IT International blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
M
Microsoft Research Blog - Microsoft Research
Know Your Adversary
Know Your Adversary
爱范儿
爱范儿
The Register - Security
The Register - Security
G
Google Developers Blog
The Hacker News
The Hacker News
Malwarebytes
Malwarebytes
S
Securelist
博客园 - 三生石上(FineUI控件)
Jina AI
Jina AI
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
S
SegmentFault 最新的问题
博客园 - 叶小钗
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
博客园 - 聂微东
T
Threatpost
博客园 - 【当耐特】
D
Docker
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
V
Visual Studio Blog
C
Cisco Blogs
IT之家
IT之家
S
Security Archives - TechRepublic
Latest news
Latest news
阮一峰的网络日志
阮一峰的网络日志

HCLonely Blog

HCLonely Blog - IP签名图片生成服务 HCLonely Blog - 树莓派搭建私有在线PS网站 将 Node.js 项目打包为一个可执行文件 哔哩哔哩硬核会员搜题脚本 在静态网站上实现浏览记录功能 统一推送服务Nodejs API 在线答题搜答案脚本 青年大学习安卓跳过方法 公主连结 Re:Dive 中文输入法词库 HCLonely Blog - 基于 NodeJs 的 live2d 后端 Api 服务器 HCLonely Blog - hexo-calendar 活动日历插件 Git 免密、免 SSH 进行 push & pull 一款基于 webstack 的 hexo 主题 使用 cron-job 解决 LeanCloud 因流控原因自动唤醒失败的问题 Valine 添加验证码、博主标签及评论微信、QQ 通知 HCLonely Blog - 使用 Cloud Studio 在线搭建、编辑、部署 Hexo 给你的网页添加一个 moc3 格式的 Live2d 模型 Hexo-tag-steamgame 插件 Hexo-online-server 在线编辑发布文章插件 Hexo 博客美化
HCLonely Blog - 百度分析和谷歌分析适配 pjax
2020-08-07 · via HCLonely Blog

本文最后更新于天前,内容可能已不再适用!

现在有很多网站使用 pjax, 包括本站也是。本站主题是从 Typecho 的 hansome 主题移植过来的,在移植过程中就遇到了这个问题:
开启 pjax 后百度分析和谷歌分析之统计首次访问的页面,之后的页面都不会统计。
下面来说一下我是如何解决的。

百度分析

pjax:complete添加以下回调:

if(typeof _hmt !== "undefined" && typeof _hmt.push === "function") _hmt.push(['_trackPageview',window.location.pathname]);

谷歌分析

谷歌分析似乎有两种,请根据你引用的 js 库修改:

  • ga: 使用https://www.google-analytics.com/analytics.js
  • gtag: 使用https://www.googletagmanager.com/gtag/js?id=UA-*******

ga

pjax:complete添加以下回调:

if(typeof ga === "function") ga('send', 'pageview', window.location.href);

gtag

pjax:complete添加以下回调(感谢@FGHRSH):

if(typeof gtag === "function") gtag('event', 'pageview', {page_location: window.location.href});

最后修改:2021-09-01 11:12:36

如果觉得我的文章对你有用,请随意赞赏