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

时间:2022-09-07 15:14:02

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

我正在尝试查询我的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. 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."

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

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

尽管如此,我仍无法从我的Google Analytics中检索任何结果。我的发送功能如下:

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. How can I access it via the API?

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

2 个解决方案

#1


9  

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.

您需要在查询中包含维度。例如'dimension':'ga:dimension1',然后使用你的过滤器'ga:dimension1 == red'。查询资源管理器对测试API请求非常有用。

#2


-1  

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 . Hence the syntax will be ga:dimension1=="what ever you want"

嘿,这非常有帮助。非常感谢你的回答。让我也用一个例子来回答这个问题:对于ga定义的维度,让语法看起来像 - ga:landingPagePath ==“你想要什么”现在说有一个名为pagepath的自定义维度是customdimension1。因此语法将是ga:dimension1 ==“你想要什么”

#1


9  

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.

您需要在查询中包含维度。例如'dimension':'ga:dimension1',然后使用你的过滤器'ga:dimension1 == red'。查询资源管理器对测试API请求非常有用。

#2


-1  

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 . Hence the syntax will be ga:dimension1=="what ever you want"

嘿,这非常有帮助。非常感谢你的回答。让我也用一个例子来回答这个问题:对于ga定义的维度,让语法看起来像 - ga:landingPagePath ==“你想要什么”现在说有一个名为pagepath的自定义维度是customdimension1。因此语法将是ga:dimension1 ==“你想要什么”

相关文章