添加增强的电子商务指标进行查询

时间:2019-04-18 14:15:55

标签: google-analytics google-bigquery enhanced-ecommerce

我有此查询,希望添加“ hits.ecommerceaction.action_type = 2”的“产品详细信息视图”的其他指标。

我通常了解这些查询的工作方式,但是这对我来说已经很复杂了,我正努力将这些额外的嵌套匹配添加到组合中。

我已经可以使用此查询来为我提供目标网页和其他尺寸,因此我现在要做的就是在产品详细信息视图中添加

SELECT DISTINCT
   a.date
  ,a.landingpage
  ,a.medium
  ,a.sources
  ,a.campaign
  ,a.device
  ,a.content
  ,a.country
  ,COUNT(DISTINCT(a.sessionId)) sessions
  ,SUM(a.bounces) bounces
  ,SUM(a.trans) trans
  ,SUM(a.rev)/1000000 rev
  ,AVG(a.avg_pages) avg_pages
  ,(SUM(tos)/COUNT(DISTINCT(a.sessionId)))/60 session_duration
  ,COUNT(DISTINCT(a.user)) users



FROM
(
    SELECT DISTINCT 
       CONCAT(CAST(fullVisitorId AS STRING),CAST(visitStartTime AS STRING)) sessionId
      ,fullvisitorid user
      ,(SELECT sourcePropertyInfo.sourcePropertyDisplayName FROM UNNEST(hits) where hitnumber = (SELECT MIN(hitnumber) from UNNEST(hits) where type = 'PAGE')) country
      ,(SELECT page.pagePath FROM UNNEST(hits) WHERE hitnumber = (SELECT MIN(hitnumber) FROM UNNEST(hits) WHERE type = 'PAGE')) landingpage

      ,date
      ,trafficSource.medium medium
      ,trafficSource.source sources
      ,trafficSource.campaign campaign
      ,trafficSource.adContent content
      ,device.deviceCategory device
      ,totals.bounces bounces

      ,totals.timeonsite tos
      ,totals.transactions trans
      ,totals.transactionRevenue as rev
      ,(SELECT COUNT(hitnumber) FROM UNNEST(hits) WHERE type = 'PAGE') avg_pages



   FROM `ghd-analytics-235112.132444882.ga_sessions_*`
    WHERE _TABLE_SUFFIX >= '20190417'   /*date start*/
    AND _TABLE_SUFFIX <= '20190417'    /*date end*/ 
    AND totals.visits = 1   

) a
GROUP BY landingpage,medium,device,sources,campaign,content,date,country
ORDER BY sessions desc

任何想法/帮助都非常感谢!

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案,我尝试了其他解决方案,但这似乎现在可以解决。

 ,(SELECT COUNT(eventinfo.eventaction) FROM UNNEST(hits) WHERE eventinfo.eventaction = 'productDetail') pviews

在此处完整查询是否有其他需要的人。

/* landing page, medium, source, campaign, adcontent, device, country, sessions, bounces, avg pages per session, time on site, transactions, revenue

   add additional dimensions and metrics into the second select statement, aggregate in the top select statement, order by any new dimensions

 */
 SELECT DISTINCT
   a.date
  ,a.landingpage
  ,a.medium
  ,a.sources
  ,a.campaign
  ,a.device
  ,a.content
  ,a.country
  ,COUNT(DISTINCT(a.sessionId)) sessions
  ,SUM(a.bounces) bounces
  ,SUM(a.trans) trans
  ,SUM(a.rev)/1000000 rev
  ,AVG(a.avg_pages) avg_pages
  ,(SUM(tos)/COUNT(DISTINCT(a.sessionId)))/60 session_duration
  ,COUNT(DISTINCT(a.user)) users
  ,sum(a.pviews) pviews



FROM
(
    SELECT DISTINCT 
       CONCAT(CAST(fullVisitorId AS STRING),CAST(visitStartTime AS STRING)) sessionId
      ,fullvisitorid user
      ,(SELECT sourcePropertyInfo.sourcePropertyDisplayName FROM UNNEST(hits) where hitnumber = (SELECT MIN(hitnumber) from UNNEST(hits) where type = 'PAGE')) country
      ,(SELECT page.pagePath FROM UNNEST(hits) WHERE hitnumber = (SELECT MIN(hitnumber) FROM UNNEST(hits) WHERE type = 'PAGE')) landingpage
       ,date
      ,trafficSource.medium medium
      ,trafficSource.source sources
      ,trafficSource.campaign campaign
      ,trafficSource.adContent content
      ,device.deviceCategory device
      ,totals.bounces bounces

      ,totals.timeonsite tos
      ,totals.transactions trans
      ,totals.transactionRevenue as rev
      ,(SELECT COUNT(hitnumber) FROM UNNEST(hits) WHERE type = 'PAGE') avg_pages
      ,(SELECT COUNT(eventinfo.eventaction) FROM UNNEST(hits) WHERE eventinfo.eventaction = 'productDetail') pviews


   FROM `ghd-analytics-XXXXXX.XXXXXXX.ga_sessions_*`
    WHERE _TABLE_SUFFIX >= '20190417'   /*date start*/
    AND _TABLE_SUFFIX <= '20190417'    /*date end*/ 
    AND totals.visits = 1   

) a


GROUP BY landingpage,medium,device,sources,campaign,content,date,country
ORDER BY sessions desc