正如Google Analytics(分析)用户界面中所示,我想通过查询获取每个产品列表的产品收入,如下所示。然而,所有的产品收入分配给“(未设定)”,而在用户界面中它分配给产品的列表。
此外,在BQ中,似乎只有产品列表印象和产品列表点击(BQ字段hits.eCommerceAction.action_type)分配给了产品列表。产品详细信息视图,结帐和唯一购买似乎也没有分配给产品列表,而在GA UI中却分配了。我猜想与产品收入相同的问题。
有人知道如何获得理想的结果吗?
SELECT
prod.productListName AS ProdListName,
SUM(产品收益)/ 1000000 AS PrRev
从
`[项目ID]。[数据集ID] .ga_sessions_ *`AS t,t.hits AS匹配,hits.product AS产品
哪里
_TABLE_SUFFIX'20181103'之间
AND'20181103'
通过...分组
产品名
由PrRev DESC订购
答案 0 :(得分:2)
hits.product.productListName字段仅针对产品列表视图和产品列表单击操作设置。 您可以通过以下方式获得每个产品列表的收入:
#standardSQL
select
l.productListName as listName,
ROUND(SUM(p.productRevenue), 2) as productRevenue
from
(select
concat (fullVisitorId, ".", cast(visitId as string), ".", cast(visitStartTIme as string), ".", cast(totals.visits as string)) as sessionId,
h.hitNumber as hitNumber,
p.v2ProductName as productName,
p.productRevenue/1000000 as productRevenue
from
`bigquery-public-data.google_analytics_sample.ga_sessions_20170801`, unnest(hits) h, unnest(h.product) as p
where h.eCommerceAction.action_type ='6')p
join
/* (select
concat (fullVisitorId, ".", cast(visitId as string), ".", cast(visitStartTIme as string), ".", cast(totals.visits as string)) as sessionId,
p.v2ProductName as productName,
p.productListName as productListName,
MAX(h.hitNumber) as hitNumber_
from
`bigquery-public-data.google_analytics_sample.ga_sessions_20170801`, unnest(hits) h, unnest(h.product) as p
where h.eCommerceAction.action_type = '1'
group by 1,2,3
order by 1 )l */
(select
sessionId,
productName,
productListName,
hitNumber_
from(
select
sessionId,
productName,
productListName,
hitNumber_,
row_number() over (partition by sessionId, productName order by hitNumber_ desc) as rn
from
(select
concat (fullVisitorId, ".", cast(visitId as string), ".", cast(visitStartTIme as string), ".", cast(totals.visits as string)) as sessionId,
p.v2ProductName as productName,
p.productListName as productListName,
h.hitNumber as hitNumber_
from
`bigquery-public-data.google_analytics_sample.ga_sessions_20170801`, unnest(hits) h, unnest(h.product) as p
where h.eCommerceAction.action_type = '1'))
where rn = 1
)l
on
p.sessionId = l.sessionId
and p.productName = l.productName
where p.hitNumber > l.hitNumber_
group by listName
ORDER BY 2 DESC