在 Google Analytics API 中使用和查询自定义维度 [英] Using and querying Custom Dimensions in Google Analytics API

查看:52
本文介绍了在 Google Analytics API 中使用和查询自定义维度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查询我的 Analytics(通用)以接收按自定义维度排序的指标列表.

I am attempting to query my Analytics (Universal) to receive a list of metrics sorted by a custom dimension.

7 月,Google AnalyticsAPI 博客宣布:

开发人员可以使用自定义维度将唯一 ID 发送到 Google Analytics(分析),然后使用核心报告 API 检索这些 ID 以及其他 Google Analytics(分析)数据.

"Developers can use custom dimensions to send unique IDs into Google Analytics, and then use the core reporting API to retrieve these IDs along with other Google Analytics data.

例如,您的内容管理系统可以使用 Google Analytics(分析)跟踪代码将内容 ID 作为自定义维度传递.然后,开发人员可以使用 API 获取按 ID 列出的最受欢迎的内容列表,并在其网站上显示最受欢迎的内容列表."

For example, your content management system can pass a content ID as a custom dimension using the Google Analytics tracking code. Developers can then use the API to get a list of the most popular content by ID and display the list of most popular content on their website."

尽管如此,我还是无法从我的分析中检索到任何结果.我的发送功能如下:

Despite this, I have been unable to retrieve any results from my Analytics. My send function is below:

ga('send', 'pageview', {
  'dimension1':'red'
});

不幸的是,使用 'ga:dimension1 == red' 过滤器查询 GA 没有检索到任何结果.

Unfortunately, querying GA using a filter of 'ga:dimension1 == red' does not retrieve any results.

gapi.client.analytics.data.ga.get({
  'ids': 'ga:' + "123456",
  'start-date': '2013-11-10',
  'end-date': '2013-11-20',
  'metrics': 'ga:visits',
  'filters': 'ga:dimension1==red'
}).execute(function(r){console.log(r);});

我也尝试过使用自定义细分来检索数据,但无济于事:

I have also tried using custom segments to retrieve the data, to no avail:

'segment': 'dynamic::ga:dimension1==red'

数据显示在 GA 的自定义报告中.如何通过 API 访问它?

The data appears in Custom Reports in GA. How can I access it via the API?

推荐答案

您需要在查询中包含一个维度.比如'dimension':'ga:dimension1',然后使用你的过滤器'ga:dimension1==red'.查询浏览器对于测试 API 请求非常有帮助.

You need to include a the dimension in the query. Such as 'dimension': 'ga:dimension1', then use your filter 'ga:dimension1==red'. The Query Explorer is very helpful for testing API requests.

这篇关于在 Google Analytics API 中使用和查询自定义维度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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