从 Google Analytics Api 获取访问量变化
我正在尝试从他们的 API 下载一些 Google Analytics 数据。 我可以下载我的访客号码。
当您使用 Google Analytics(分析)网页时,您可以看到访问量变化的百分比,但我如何从他们的 API 获取该信息?
我可以尝试自己计算,但我不知道他们使用什么算法。
有关 API 的更多信息可以在此处找到。 数据 Feed 查询浏览器
编辑
Final formula
Visits over the last 30 days
StartDate = today.Year, today.Month - 1, today.Day
EndDate = today.Year, today.Month, today.Day - 1
Visits between 31 and 60 days ago
StartDate = today.Year, today.Month - 2, today.Day
EndDate = today.Year, today.Month -1, today.Day - 1
I'm, trying to download some Google Analytics data from their API.
I can download my visitors number.
When you use the Google Analytics webpage you can see a percents of Changes in visits, but how do I get that info from their API?
I could try to calculate it by my self, but I have no idea of what algorithm they use.
More info about the API can be found here. Data Feed Query Explorer
edit
Final formula
Visits over the last 30 days
StartDate = today.Year, today.Month - 1, today.Day
EndDate = today.Year, today.Month, today.Day - 1
Visits between 31 and 60 days ago
StartDate = today.Year, today.Month - 2, today.Day
EndDate = today.Year, today.Month -1, today.Day - 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引用我的回答此处< /a>,
公式很简单(不包括今天的数据):
如果您转到默认仪表板(其中显示过去 30 天),然后在日历上单击“与过去比较”并选择默认金额,您可以在界面中看到它的运行情况。它将向您显示用于每个计算的数字以及该帐户列表中显示的计算结果。
然而,API 不会公开预先计算的数字(例如,它们不会为您计算跳出率;它们只是为您提供相应的部分。)
因此,您需要执行两个 API 请求才能获得此数据数据。一份针对过去 30 天内的
ga:visits
,另一份针对过去 30 天内的ga:visits
。然后,当你得到它时,只需减去、除然后乘以 100,你就会得到你想要的百分比。
Quoting from my answer here,
The formula is pretty simple (excluding today's data):
You can see it in action in the interface if you go to the default dashboard, where it shows you the last 30 days, then on the calendar, click "Compare to past" and select the default amount. It'll show you the numbers used for each calculation and the calculations as they appears in that account list.
The API does not, however, expose pre-calculated numbers (for example, they don't compute bounce rate for you; they just give you the pieces for it.)
So, you'd need to do two API requests to get this data. One for
ga:visits
in the last 30 days, and then one forga:visits
in the 30 days prior.Then, when you get it, just subtract, divide, and multiply by 100, and you'll have the percent you're looking for.