将观看次数从Google Analytics(分析)添加到网页 [英] Add view count to webpage from Google Analytics

查看:87
本文介绍了将观看次数从Google Analytics(分析)添加到网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为网页创建观看次数功能.为此,我创建了一个新属性,并从 Google Analytics(分析)生成了跟踪ID.

I am trying to create a view count feature for a webpage. To do this, I created a new property and generated a tracking id from Google Analytics.

有没有办法从那里使用页面访问数据并将其显示在我跟踪的同一页面上?

Is there a way I can use the page vists data from there and display it on the same page that I am tracking?

推荐答案

可以,但是由于GA API已通过身份验证,因此您将需要以一种或另一种方式处理该身份验证.

You can, but since GA APIs are authenticated, you will need to handle that authentication one way or another.

您基本上有3个选择:

  • User doing OAuth: by default you would need to implement the OAuth flow like the Query Explorer is doing, which is obviously not adequate if the counter is meant to be public, as visitors won't have the appropriate GA permissions to get data from that property
  • Pre generated access token: you can generate the access token manually, and use that token to make the requests: https://developers.google.com/analytics/devguides/reporting/embed/v1/component-reference#auth-options

serverAuth.access_token类型:字符串

serverAuth.access_token Type: string

如果您已经具有有效的访问令牌,则可以将其传递给直接授权方法,不会提示用户授权.有关如何检索访问令牌的详细信息,请参见OAuth 2.0文档.

If you already have a valid access token, you can pass it to the authorize method directly and the user will not be prompted to authorize. For details on how to retrieve an access token, see the OAuth 2.0 documentation.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆