2017-10-18 121 views
0

我試圖使用standardSQL複製GA數量指標(ga:itemQuantity)並查詢GA導出到BigQuery日期分區表(ga_sessions_YYYYMMDD)。ga:itemQuantity in ga_sessions_YYYMMDD(Big Query)

我曾嘗試以下,但「量」總是空:

#standardSQL 
SELECT 
sum(hit.item.itemQuantity) as quantity 
FROM `precise-armor-133520.1500218.ga_sessions_20170801` t 
CROSS JOIN 
UNNEST(t.hits) AS hit 
order by 1 ASC; 

其他指標的工作,並匹配100%與GA UI所以我假定這不是一個數據導出的問題。例如:

SELECT 
sum(totals.totalTransactionRevenue) as revenue, sum(totals.transactions) as transactions 
FROM `precise-armor-133520.1500218.ga_sessions_201708*` t 
CROSS JOIN 
UNNEST(t.hits) AS hit 
group by `date` 
order by `date` asc 

這些總計分別與GA UI中的收入和交易(度量)相匹配。

GA度量數量(ga:itemQuantity)的標準SQL查詢是什麼?

+0

不知'hits.product.productQuantity'工作? –

+0

我也嘗試過,並且以下面的查詢至少返回了一個返回值,但它與GA Web UI中的度量「數量」不匹配。 SELECT sum(p.productQuantity),從(SELECT h.product,'date' as d FROM'precise-armor-133520.1500218.ga_sessions_201710 *' ,UNNEST(hits)as h ),UNNEST(product)as p group by d order by d asc –

回答

0

爲了通過每個日期在GA的Web UI,以配合 「數量」,請使用下列標準的SQL:

SELECT 
    SUM(product.productQuantity) 
    ,`date` 
FROM 
    `precise-armor-133520.1500218.ga_sessions_*` 
    ,UNNEST(hits) AS hits 
    ,UNNEST(hits.product) AS product 
WHERE hits.eCommerceAction.action_type = "6" 
and _TABLE_SUFFIX between '20170801' and FORMAT_DATE("%Y%m%d", CURRENT_DATE) 
group by 2 
order by 2 asc 
0

這是行不通的?

#standardSQL 
SELECT 
sku, 
SUM(qtd) qtd 
FROM(
SELECT 
    ARRAY(SELECT AS STRUCT productSKU sku, productQuantity qtd FROM UNNEST(hits), UNNEST(product) WHERE ecommerceAction.action_type = '6') data 
    FROM `precise-armor-133520.1500218.ga_sessions_20170801` 
), 
UNNEST(data) 
GROUP BY sku 
ORDER BY qtd DESC 
LIMIT 1000 

不知道你如何設法unnest產品領域,也許這可以解決您的問題。