Google Analytics UserID API提取

编程入门 行业动态 更新时间:2024-10-25 08:20:54
本文介绍了Google Analytics UserID API提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尝试从GoogleAnalytics提取用户ID.这是为了查看使用哪个网站的用户最多和最少. 我将检索使用以下任一方法传递的前5个用户ID和后5个用户ID :

Trying to extract a userID from GoogleAnalytics. This is to view which user is the using the website most and least. I would to retrieve the top 5 user IDs and bottom 5 user IDs that were passed using either:

gtag('config', 'GA_TRACKING_ID', { 'user_id': 'USER_ID' });

OR

using a custom dimension...( support.google/analytics /answer/2709828?hl = zh_CN )

我(大概)知道在Google BUT上保留无法识别"信息的政策和服务条款,在线发布的帖子表明您可以链接回CMS数据.

I'm (vaguely) aware of policies and TOS to keep 'non identifying' information on Google BUT there are posts online indicating you can link back to CMS data.

到目前为止的步骤 具有UserID和视图设置的Google Analytics(分析)-使用Google信息中心,并使用该提示显示经过过滤的用户ID和所有网站数据.

Steps so far Google Analytics with UserID and view setup - Working in Google dashboard and showing filtered userID and All website data using the idea.

要求:

提取日期之间每个userId的页面视图和会话数据 范围(默认为全部)

Extract page view and session data for each userId between a date range (or all by default)

  • 通过标准GA方法的用户ID
  • 通过自定义维度方法的用户ID
  • 任何帮助,指示或示例说明某人如何完成这样的事情. 注意:这是将数据从GA中提取出来,并在外部系统/仪表板上进行操作/显示.

    Any help, pointers or examples how someone has completed something like this are appreciated. NOTE: This is to PULL data out of GA and manipulate/display it on an external system/dashboard.

    看到这表明不可能: Google Analytics(分析)用户ID跟踪 并指出(种类)为 Google Analytics(分析)API实施,用于跟踪php中的特定用户活动

    Seen this which states it's not possible: Google analytics userID tracking and this which states it (kind of) is google analytics API implementation for tracking a specific user activities in php

    推荐答案

    我使用的解决方案:

    跟踪

  • 创建Google Analytics(分析)帐户
  • 通过激活UserID跟踪(标记为NewView1)来创建新视图
  • 使用 developers.google/analytics/devguides/collection/gtagjs/custom-dims-mets 即定义您的自定义维度
  • 获取Google Analytics(分析)跟踪代码+添加自定义定义代码
  • 使用您要查看的指标"创建自定义报告,并按照我之前创建的自定义维度"进行过滤. (注意:数据需要大约12个小时才能看到,因此不要指望立即工作)
  • Create Google Analytics account
  • Create a new view by activating the UserID tracking (labeled NewView1)
  • Use developers.google/analytics/devguides/collection/gtagjs/custom-dims-mets i.e. Define your custom dimension
  • Get Analytics tracking code + Add custom definition code
  • Create a Custom report using the 'metrics' you want to see and filtering by the 'custom dimension' I created earlier. (note: data took ~ 12 hours to be visible so don't expect to work instantly)
  • 前端跟踪添加

    gtag('config', 'GA_TRACKING_ID', { 'custom_map': {'dimension<Index>': 'dimension_name'} }); // Sends the custom dimension to Google Analytics. gtag('event', 'any_event_name', {'dimension_name': dimension_value});

    提取

  • 创建新的Google Developer Console项目(API)
  • 使用服务帐户将API与Analytics(分析)( developers.google/analytics/devguides/reporting/core/v4/quickstart/service-php )-API->凭证->创建凭据(服务帐户密钥)
  • (分配角色[我的角色设置为Project =>视图])
  • 按照示例将Text文件保存到文件系统并重命名为json
  • 通过将电子邮件"从服务帐户详细信息复制/粘贴到Google Analytics(分析)用户管理中,为您的Analytics(分析)项目添加权限.
  • 获取您要提取的数据的视图ID(跟踪的第2步中创建的Analtyics)
  • 使用示例代码(HelloAnalytics.php)连接并提取数据
  • 使用自定义维度过滤结果
  • Create New Google Developer Console Project (API)
  • Use a Service Account to connect the API with Analytics ( developers.google/analytics/devguides/reporting/core/v4/quickstart/service-php ) -- API -> credentials -> Create Credentials (Service Account key)
  • (assign role [mine was set to Project => View])
  • Save the Text file to your filesystem and rename to json as per examples
  • Add permissions to your Analytics project by copy/pasting the 'Email' from the Service account details into Analytics User Management.
  • Get the view ID of the data you wish to extract (Analtyics created in step 2 in tracking)
  • Use the sample Code (HelloAnalytics.php) to connect and extract data
  • Use your custom dimension to filter results
  • 我使用的维度过滤条件为 $ dimensions (见下文)

    The dimension filter I used was $dimensions (see below)

    ... $dimensions = new \Google_Service_AnalyticsReporting_Dimension(); $dimensions->setName('ga:dimension1'); // as per docs // Create the ReportRequest object. $request = new \Google_Service_AnalyticsReporting_ReportRequest(); $request->setViewId($VIEW_ID); $request->setDateRanges($dateRange); $request->setMetrics(array($sessions, $pageviews)); $request->setDimensions($dimensions);

    从那里,我可以通过API看到与在分析网络上的自定义报告中可以看到的相同的数据.

    From there I was able to see the same data via API that I could see in the custom report on analytics web.

    注意:设置时请注意您所在的Google项目和视图 权限和尺寸.

    NOTE: be careful of which Google project and view you're in while setting up permissions and dimensions.

    注意:使用gtag()代码而不是通用(ga())js代码

    NOTE: using gtag() code and not Universal (ga()) js code

    答案是关于我如何实现自己的特定目标的非常简短/粗略的摘要.这不是一种千篇一律的解决方案,但希望它能使人们更好地了解如何在Google中设置和提取自定义变量数据.

    The answer is a very brief/rough summary of how I achieved my specific goal. It is not a one-size-fits all solution but hopefully it will give someone a better idea of how to set and extract custom variable data within Google.

    最终结果是来自API的数据.从那里开始,由您决定.

    The final result was data from the API. From there it's up to you.

更多推荐

Google Analytics UserID API提取

本文发布于:2023-11-24 19:48:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626582.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Analytics   Google   API   UserID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!