将 Google Analytics 添加到 Magnolia CMS
我有一个使用 Magnolia CMS 构建的网站,我需要将 Google Analytics 添加到其页面。我已经安装了 Google Analytics for STK 模块,然后按照文档。
由于此跟踪号码适用于我无权访问的帐户,我可以做什么来测试此配置是否正常工作?我已经打开了该页面的源代码,但没有看到任何对 GA 的引用。有什么想法吗?
I have a site built using Magnolia CMS, and I need to add Google Analytics to its pages. I've installed the Google Analytics for STK module, and then followed the documentation.
Since this tracking number is for an account I don't have access, what can I do to test that this configuration is working? I've opened the page's source code, but don't see any reference to GA. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,Analytics 模块会将必要的 Javascript 注入到您的 all.js 文件中,该文件是根据各种模板、模块等希望可用的所有 Javascript 小块动态构建的在页面上。 (Magnolia 在服务器端连接所有这些文件,以帮助加快页面加载时间,因为您的 Javascript 需要单个 HTTP 连接,而不是为可能位于单独文件中的每一项功能连接一个连接。)
查看是否有适当的代码被注入,查看你的源代码并搜索“js/all”。这应该显示聚合的 Javascript 的 URL。 (如果您使用的是作者实例,它还会添加一个大时间戳,以确保它不会在您不希望时被缓存。)
按照该 URL 查看聚合的 Javascript,然后搜索该代码中的“UA-”。 (所有的谷歌跟踪 ID 都以“UA-”开头。)如果您发现这一点,那么分析模块确实正在执行其预期的操作。
也就是说,确保其正常工作的最佳方法是在 Google Analytics 中实际检查它。如果您无法访问真实 ID,您可以设置一个测试 ID 并使用几天,以验证您是否获得了所需的数据。 (GA 确实需要一些时间来汇总这些数据并将其显示在报告中,因此请耐心等待。)
The Analytics module by default injects the necessary Javascript into your all.js file, which is built up on the fly from all the little bits of Javascript that the various templates, modules, etc. want to have available on the page. (Magnolia concatenates all of these files on the server side to help speed page load times by requiring a single HTTP connection for your Javascript instead of one for each piece of functionality that might go in a separate file.)
To see if the appropriate code is getting injected, look at your source and search for "js/all". This should show the URL for your aggregated Javascript. (If you're on an author instance, it will also have a big timestamp added to make sure that it doesn't get cached when you don't want it to.)
Follow that URL to view your aggregated Javascript, and then search for "UA-" within that code. (All of the google tracking IDs begin with "UA-".) If you find that, than the analytics module is indeed doing what it's meant to.
That said, the best way to be sure that it's working is to actually check it in Google analytics. If you don't have access to the real ID, you might set up a test one and use that for a couple of days and verify that you're getting the data you expect. (GA does take a bit of time to aggregate that data and show it in reports, so be patient.)