简体   繁体   English

在Google AnalyticsAPI中使用和查询自定义维度

[英]Using and querying Custom Dimensions in Google Analytics API

I am attempting to query my Analytics (Universal) to receive a list of metrics sorted by a custom dimension. 我正在尝试查询我的Google Analytics(通用)以接收按自定义维度排序的指标列表。

In July, the Google Analytics API blog announced: 7月, Google AnalyticsAPI博客宣布:

"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以及其他Google Analytics数据。

For example, your content management system can pass a content ID as a custom dimension using the Google Analytics tracking code. 例如,您的内容管理系统可以使用Google Analytics跟踪代码将内容ID作为自定义维度传递。 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. 然后,开发人员可以使用API​​按ID获取最受欢迎的内容列表,并在其网站上显示最受欢迎的内容列表。 "

Despite this, I have been unable to retrieve any results from my Analytics. 尽管如此,我仍无法从我的Google Analytics中检索任何结果。 My send function is below: 我的发送功能如下:

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

Unfortunately, querying GA using a filter of 'ga:dimension1 == red' does not retrieve any results. 不幸的是,使用'ga:dimension1 == red'过滤器查询GA不会检索任何结果。

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'

The data appears in Custom Reports in GA. 数据显示在GA的自定义报告中。 How can I access it via the API? 如何通过API访问它?

You need to include a the dimension in the query. 您需要在查询中包含维度。 Such as 'dimension': 'ga:dimension1' , then use your filter 'ga:dimension1==red' . 例如'dimension': 'ga:dimension1' ,然后使用你的过滤器'ga:dimension1==red' The Query Explorer is very helpful for testing API requests. 查询资源管理器对测试API请求非常有用。

hey this is very helpful. 嘿,这非常有帮助。 thanks so much for the answer. 非常感谢你的回答。 Let me also answer this question with an example: let so for a ga defined dimension, the syntax would look like - ga:landingPagePath=="what ever you want" now say there is a custom dimension called pagepath which is customdimension1 . 让我也用一个例子来回答这个问题:对于ga定义的维度,让语法看起来像 - ga:landingPagePath ==“你想要什么”现在说有一个名为pagepath的自定义维度是customdimension1。 Hence the syntax will be ga:dimension1=="what ever you want" 因此语法将是ga:dimension1 ==“你想要什么”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM