使用 Google Analytics 将数据显示在我们的网页上?
在我们的某些页面上,我们会显示一些统计信息,例如今天查看该页面的次数、过去一周查看该页面的次数等。此外,我们还有一个总体统计页面,我们按顺序列出页面,浏览次数最多的。
今天,我们只是将这些页面浏览量和事件计数插入到我们的数据库中。我们还通过正常的页面跟踪及其 API 将它们发送到 Google Analytics。理想情况下,我们只需查询 Google Analytics 的 API,而不是查询数据库以获取要在网页上显示的统计信息。谷歌分析在找出真正的独特者方面做得更好,并且避免计算人为夸大其页面浏览量的人(我们允许人们在我们的网站上创建页面)。
那么问题是是否可以使用 Google Analytics 的 API 来更新我们网页上的统计信息?如果我缓存结果是否更可行?或者只是偶尔更新我们的统计数据?我非常喜欢使用 Google Analytics 来衡量我们的网站指标,但也许有更好的解决方案来满足这一特殊需求?
On some of our pages, we display some statistics like number of times that page has been viewed today, number of times it's been viewed the past week, etc. Additionally, we have an overall statistics page where we list the pages, in order, that have been viewed the most.
Today, we just insert these pageviews and event counts into our database as they happen. We also send them to Google Analytics via normal page tracking and their API. Ideally, instead of querying our database for these stats to display on our webpages, we just query Google Analytics' API. Google Analytics does a FAR better job figuring out who the real uniques are and avoids counting people who artificially inflate their pageview counts (we allow people to create pages on our site).
So the question is if it's possible to use Google Analytics' API for updating the statistics on our webpages? If I cache the results is it more feasible? Or just occasionally update our stats? I absolutely love Google Analytics for our site metrics, but maybe there's a better solution for this particular need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,可以。但是,身份验证过程和 xml 返回可能会减慢速度。您可以通过限制返回的行/列来加快速度。此外,您想要显示数据的方式的身份验证(如果我理解正确的话)将要求您使用客户端身份验证方法。您发送用户名和密码。安全是一个问题。
我已经完全按照您的描述进行操作,但必须在页面上放置加载图形以获取统计信息。
无论是哪一种,但缓存似乎都会起作用,特别是因为 GA 数据无论如何都不是实时数据。您可以进行 api 调用并存储(或处理然后存储)返回的 xml 以供稍后显示。
我还没有这样做过,但我想我可以尝试一下。甚至可以作为预定作业运行。
有一些第三方解决方案(谷歌搜索应该将其根除),但应考虑资金和可行性。
Yes, it is. But, the authentication process and xml return may slow things up. You can speed it up by limiting the rows/columns returned. Also, authentication for the way you want to display the data (if I understood you correctly) would require you to use the client authentication method. You send the username and password. Security is an issue.
I have done exactly what you described but had to put a loading graphic on the page for the stats.
Either one but caching seems like it would work especially since GA data is not real-time data anyway. You could make the api call and store (or process then store) the returned xml for display later.
I haven't done this but I think I might give it a go. Could even run as a scheduled job.
There are some third-party solutions (googling should root them out) but money and feasibility should be considered.