AnalyticsReporting V4:我可以将 DynamicSegment 和 segmentId 组合为逻辑 AND 吗?
AnalyticsReporting V4: Can I combine a DynamicSegment and a segmentId as logical AND?
我正在尝试将一些查询从 Core Reporting V3 迁移到 V4(具体来说 PHP 中的 AnalyticsReporting V4)。在一种情况下,我想将自定义细分与 "predefined" 细分之一结合起来。
预期结果:
我收到一个响应,其中两个段都应用于响应(逻辑与)
实际结果:
我收到回复,其中每一行都针对每个细分市场单独列出。
我的问题
我如何应用两个细分以在每个结果中接收一行?在这种情况下 - 获取所有通过平板电脑或台式机访问并进行了三个以上会话的用户。
在 V3 中,我通过组合多个 user::condition:somethingSomething.
来做到这一点
我想一种方法是首先获取我需要的预定义段的段定义,然后使用它来构建 SegmentDimensionFilter - 但最好避免这种情况。
这是我的(测试)查询,其中 segmentId:'gaid::-15' 为 "Tablet and Desktop Traffic"。在我的真实查询中,我使用的是 SequenceSegment,但这里的响应是相同的:
+"dateRanges": array:1 [▼
0 => {#542 ▼
+"endDate": "2016-05-18"
+"startDate": "2016-04-18"
}
]
+"dimensions": array:1 [▼
0 => {#545 ▼
+"name": "ga:segment"
}
]
+"metrics": array:1 [▼
0 => {#546 ▼
+"expression": "ga:users"
}
]
+"segments": array:2 [▼
0 => {#548 ▼
+"dynamicSegment": {#549 ▼
+"name": "AK: Loyal Visitors"
+"userSegment": {#553 ▼
+"segmentFilters": array:1 [▼
0 => {#556 ▼
+"simpleSegment": {#560 ▼
+"orFiltersForSegment": {#563 ▼
+"segmentFilterClauses": array:1 [▼
0 => {#566 ▼
+"dimensionFilter": {#570 ▼
+"dimensionName": "ga:sessionCount"
+"expressions": "3"
+"operator": "NUMERIC_GREATER_THAN"
}
}
]
}
}
}
]
}
}
}
1 => {#543 ▼
+"segmentId": "gaid::-15"
}
]
+"orderBys": array:1 [▼
0 => {#547 ▼
+"fieldName": "ga:users"
+"sortOrder": "DESCENDING"
}
]
这里是响应,请注意每个细分如何单独列为自己的维度:
"columnHeader" => array:2 [▼
"dimensions" => array:1 [▼
0 => "ga:segment"
]
"metricHeader" => array:1 [▼
"metricHeaderEntries" => array:1 [▼
0 => array:2 [▼
"name" => "ga:users"
"type" => "INTEGER"
]
]
]
]
"data" => array:6 [▼
"rows" => array:2 [▼
0 => array:2 [▼
"dimensions" => array:1 [▼
0 => "Tablet and Desktop Traffic"
]
"metrics" => array:1 [▼
0 => array:1 [▼
"values" => array:1 [▼
0 => "74309"
]
]
]
]
1 => array:2 [▼
"dimensions" => array:1 [▼
0 => "AK: Loyal Visitors"
]
"metrics" => array:1 [▼
0 => array:1 [▼
"values" => array:1 [▼
0 => "10740"
]
]
]
]
]
"totals" => array:1 [▼
0 => array:1 [▼
"values" => array:1 [▼
0 => "85049"
]
]
]
"rowCount" => 2
如有任何帮助,我们将不胜感激!如果我需要澄清一些事情,请告诉我。
多个细分
正如您的查询结果证明 Analytics Reporting API V4 ReportRequest 可以有多个段,每个段显示在结果的 ga:segment
维度中。
逻辑与段过滤器
回答你的问题 不,你不能 OR/AND 将段 ID 与你自己的子句一起使用,因为给定的段 ID 可以由多个单独的过滤子句组成.
实际上您请求的段 ID 有两个 segmentFilterClauses:
gaid::-5 == sessions::condition::ga:deviceCategory==tablet,ga:deviceCategory==desktop
但并非一无所有
如您所料,您需要创建自己的一组细分过滤器:
{
"reportRequests":
[
{
"viewId": "XXXX",
"dimensions":
[
{
"name": "ga:segment"
}
],
"metrics":
[
{
"expression": "ga:users"
}
],
"segments":
[
{
"dynamicSegment":
{
"userSegment":
{
"segmentFilters":
[
{
"simpleSegment":
{
"orFiltersForSegment":
[
{
"segmentFilterClauses":
[
{
"dimensionFilter":
{
"dimensionName": "ga:sessionCount",
"operator": "NUMERIC_GREATER_THAN",
"expressions":
["3"
]
}
}
]
}
]
}
},
{
"simpleSegment":
{
"orFiltersForSegment":
[
{
"segmentFilterClauses":
[
{
"dimensionFilter":
{
"dimensionName": "ga:deviceCategory",
"expressions":
["tablet","desktop"
],
"operator": "IN_LIST"
}
}
]
}
]
}
}
]
},
"name": "AK: Loyal mobile users"
}
}
]
}
]
}
Checkout the above example in the API Explorer
分段 ID 向后兼容
除了能够逻辑 AND 或 OR 段过滤器之外,Analytics Reporting API V4 is backwards compatible with the V3 segment syntax:
{
"reportRequests":
[
{
"viewId": "XXXX",
"dimensions":
[
{
"name": "ga:segment"
}
],
"metrics":
[
{
"expression": "ga:users"
}
],
"segments":
[
{
"segmentId": "users::condition::ga:deviceCategory==tablet,ga:deviceCategory==desktop,ga:sessionCount>3"
}
]
}
]
}
我认为行中有错误
"users::condition::ga:deviceCategory==tablet,ga:deviceCategory==desktop,ga:sessionCount>3"
代替“,”,我们必须写“;”
"users::condition::ga:deviceCategory==tablet,ga:deviceCategory==desktop;ga:sessionCount>3"
^
我正在尝试将一些查询从 Core Reporting V3 迁移到 V4(具体来说 PHP 中的 AnalyticsReporting V4)。在一种情况下,我想将自定义细分与 "predefined" 细分之一结合起来。
预期结果:
我收到一个响应,其中两个段都应用于响应(逻辑与)
实际结果:
我收到回复,其中每一行都针对每个细分市场单独列出。
我的问题
我如何应用两个细分以在每个结果中接收一行?在这种情况下 - 获取所有通过平板电脑或台式机访问并进行了三个以上会话的用户。
在 V3 中,我通过组合多个 user::condition:somethingSomething.
来做到这一点我想一种方法是首先获取我需要的预定义段的段定义,然后使用它来构建 SegmentDimensionFilter - 但最好避免这种情况。
这是我的(测试)查询,其中 segmentId:'gaid::-15' 为 "Tablet and Desktop Traffic"。在我的真实查询中,我使用的是 SequenceSegment,但这里的响应是相同的:
+"dateRanges": array:1 [▼
0 => {#542 ▼
+"endDate": "2016-05-18"
+"startDate": "2016-04-18"
}
]
+"dimensions": array:1 [▼
0 => {#545 ▼
+"name": "ga:segment"
}
]
+"metrics": array:1 [▼
0 => {#546 ▼
+"expression": "ga:users"
}
]
+"segments": array:2 [▼
0 => {#548 ▼
+"dynamicSegment": {#549 ▼
+"name": "AK: Loyal Visitors"
+"userSegment": {#553 ▼
+"segmentFilters": array:1 [▼
0 => {#556 ▼
+"simpleSegment": {#560 ▼
+"orFiltersForSegment": {#563 ▼
+"segmentFilterClauses": array:1 [▼
0 => {#566 ▼
+"dimensionFilter": {#570 ▼
+"dimensionName": "ga:sessionCount"
+"expressions": "3"
+"operator": "NUMERIC_GREATER_THAN"
}
}
]
}
}
}
]
}
}
}
1 => {#543 ▼
+"segmentId": "gaid::-15"
}
]
+"orderBys": array:1 [▼
0 => {#547 ▼
+"fieldName": "ga:users"
+"sortOrder": "DESCENDING"
}
]
这里是响应,请注意每个细分如何单独列为自己的维度:
"columnHeader" => array:2 [▼
"dimensions" => array:1 [▼
0 => "ga:segment"
]
"metricHeader" => array:1 [▼
"metricHeaderEntries" => array:1 [▼
0 => array:2 [▼
"name" => "ga:users"
"type" => "INTEGER"
]
]
]
]
"data" => array:6 [▼
"rows" => array:2 [▼
0 => array:2 [▼
"dimensions" => array:1 [▼
0 => "Tablet and Desktop Traffic"
]
"metrics" => array:1 [▼
0 => array:1 [▼
"values" => array:1 [▼
0 => "74309"
]
]
]
]
1 => array:2 [▼
"dimensions" => array:1 [▼
0 => "AK: Loyal Visitors"
]
"metrics" => array:1 [▼
0 => array:1 [▼
"values" => array:1 [▼
0 => "10740"
]
]
]
]
]
"totals" => array:1 [▼
0 => array:1 [▼
"values" => array:1 [▼
0 => "85049"
]
]
]
"rowCount" => 2
如有任何帮助,我们将不胜感激!如果我需要澄清一些事情,请告诉我。
多个细分
正如您的查询结果证明 Analytics Reporting API V4 ReportRequest 可以有多个段,每个段显示在结果的 ga:segment
维度中。
逻辑与段过滤器
回答你的问题 不,你不能 OR/AND 将段 ID 与你自己的子句一起使用,因为给定的段 ID 可以由多个单独的过滤子句组成.
实际上您请求的段 ID 有两个 segmentFilterClauses:
gaid::-5 == sessions::condition::ga:deviceCategory==tablet,ga:deviceCategory==desktop
但并非一无所有
如您所料,您需要创建自己的一组细分过滤器:
{
"reportRequests":
[
{
"viewId": "XXXX",
"dimensions":
[
{
"name": "ga:segment"
}
],
"metrics":
[
{
"expression": "ga:users"
}
],
"segments":
[
{
"dynamicSegment":
{
"userSegment":
{
"segmentFilters":
[
{
"simpleSegment":
{
"orFiltersForSegment":
[
{
"segmentFilterClauses":
[
{
"dimensionFilter":
{
"dimensionName": "ga:sessionCount",
"operator": "NUMERIC_GREATER_THAN",
"expressions":
["3"
]
}
}
]
}
]
}
},
{
"simpleSegment":
{
"orFiltersForSegment":
[
{
"segmentFilterClauses":
[
{
"dimensionFilter":
{
"dimensionName": "ga:deviceCategory",
"expressions":
["tablet","desktop"
],
"operator": "IN_LIST"
}
}
]
}
]
}
}
]
},
"name": "AK: Loyal mobile users"
}
}
]
}
]
}
Checkout the above example in the API Explorer
分段 ID 向后兼容
除了能够逻辑 AND 或 OR 段过滤器之外,Analytics Reporting API V4 is backwards compatible with the V3 segment syntax:
{
"reportRequests":
[
{
"viewId": "XXXX",
"dimensions":
[
{
"name": "ga:segment"
}
],
"metrics":
[
{
"expression": "ga:users"
}
],
"segments":
[
{
"segmentId": "users::condition::ga:deviceCategory==tablet,ga:deviceCategory==desktop,ga:sessionCount>3"
}
]
}
]
}
我认为行中有错误
"users::condition::ga:deviceCategory==tablet,ga:deviceCategory==desktop,ga:sessionCount>3"
代替“,”,我们必须写“;”
"users::condition::ga:deviceCategory==tablet,ga:deviceCategory==desktop;ga:sessionCount>3"
^