在bigquery中通过两个不同粒度的自定义维度获取页面视图

时间:2016-11-21 17:14:20

标签: google-analytics google-bigquery

我正在尝试从bigquery中提取报告,我可以通过此查询查看按天划分的网页浏览量和一些自定义维度(一个在命中级别,另一个在会话级别):

SELECT 
      date
      ,SUM(totals.pageviews) as PVs
      ,MAX(IF(hits.customDimensions.index = 11, hits.customDimensions.value,NULL)) AS x
      ,MAX(IF(customDimensions.index = 1, customDimensions.value,NULL)) AS y

FROM TABLE_DATE_RANGE([111111111.ga_sessions_]
                     ,TIMESTAMP('2016-10-01')
                     ,TIMESTAMP('2016-10-31')) 

       GROUP EACH BY 1

我得到以下内容:

Error: Cannot query the cross product of repeated fields customDimensions.index and hits.page.pagePath.

我一直在寻找其他答案,但没有找到解决类似问题的任何问题。你能建议一个更好的查询吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要展平数据

查看Google的示例报告"无法查询重复字段的交叉产品children.age和citiesLived.yearsLived"在Dealing with data

之内

"要查询多个重复字段,您需要展平其中一个字段:

SELECT fullName, age, gender, citiesLived.place FROM (FLATTEN([dataset.tableId], children)) WHERE (citiesLived.yearsLived > 1995) AND (children.age > 3) GROUP BY fullName, age, gender, citiesLived.place"

绕过table_date_range限制,尝试先创建子选择

SELECT
  hits.eventInfo.eventCategory,
  hits.eventInfo.eventAction,
  customDimensions.value
FROM
  FLATTEN((
    SELECT
      hits.eventInfo.eventCategory,
      hits.eventInfo.eventAction,
      customDimensions.index,
      customDimensions.value
    FROM (TABLE_DATE_RANGE([dataset.table_], DATE_ADD(CURRENT_TIMESTAMP(), -3, 'DAY'), DATE_ADD(CURRENT_TIMESTAMP(), -1, 'DAY')))),hits.eventInfo.eventCategory)

Official Google BigQuery issue and feature request tracker

上讨论过