GA在BigQuery页面上的平均时间

时间:2015-11-09 20:26:11

标签: google-analytics google-bigquery

我无法在后端GA BigQuery导出数据中计算出页面上的平均时间,并想知道是否有人可能会看到下面的代码是否合理。

我无法将其与查询资源管理器工具相匹配。

有没有办法为LondonCycleHelmet数据运行查询资源管理器工具?

非常感谢任何帮助,谢谢

select
  pageviews,
  exit_pageviews,
  sum_hit_length_seconds,
  sum_hit_length_seconds / (pageviews - exit_pageviews) as avg_time_on_page
from
  (
  select 
    SUM(hit_length_seconds) as sum_hit_length_seconds, 
    COUNT(IF(hits.type='PAGE',(CONCAT(session_key,'_',hits.page.hostname,'_',hits.page.pagePath)),NULL)) AS pageviews,
    COUNT(IF((next_hit_time is null) or (hits.hitNumber=hits_hitNumber_max),(CONCAT(session_key,'_',hits.page.hostname,'_',hits.page.pagePath)),NULL)) AS exit_pageviews,
  from
    (
    select
      *,
      (next_hit_time-hits.time)/1000 as hit_length_seconds,
    from
      (
      select
        fullVisitorId,
        visitId,
        visitorId,
        hits.type,
        hits.time,
        hits.hitNumber,
        hits.page.hostname,
        hits.page.pagePath,
        -- create some keys to handle data later
        concat(fullVisitorId,"_",string(visitId)) as session_key,
        concat(fullVisitorId,"_",string(visitId),"_",string(hits.hitNumber),"_",string(hits.time)) as hit_key,
        -- get max and min number of hits for each session
        MAX(hits.hitNumber) WITHIN RECORD AS hits_hitNumber_max,
        MIN(hits.hitNumber) WITHIN RECORD AS hits_hitNumber_min,    
        -- get min and max hit times to work out full session length
        MAX(hits.time) WITHIN RECORD AS hits_time_max,
        MIN(hits.time) WITHIN RECORD AS hits_time_min,        
        -- get next and previous hit time to be able to work out length of each hit
        LAG(hits.time, 1) OVER (PARTITION BY fullVisitorId, visitId ORDER BY hits.time ASC) as previous_hit_time,
        LEAD(hits.time, 1) OVER (PARTITION BY fullVisitorId, visitId ORDER BY hits.time ASC) as next_hit_time,
      from
        [google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910] 
      )
    )
  )

UPDATE /澄清

我认为,当我看到一个单独的页面时,它开始走出困境。

例如,如果我在BigQuery中运行:

select
  pageviews,
  exit_pageviews,
  sum_hit_length_seconds,
  sum_hit_length_seconds / (pageviews - exit_pageviews) as avg_time_on_page
from
  (
  select 
    SUM(hit_length_seconds) as sum_hit_length_seconds, 
    COUNT(IF(hits.type='PAGE',(CONCAT(session_key,'_',hits.page.hostname,'_',hits.page.pagePath)),NULL)) AS pageviews,
    COUNT(IF((next_hit_time is null) or (hits.hitNumber=hits_hitNumber_max),(CONCAT(session_key,'_',hits.page.hostname,'_',hits.page.pagePath)),NULL)) AS exit_pageviews,
  from
    (
    select
      *,
      (next_hit_time-hits.time)/1000 as hit_length_seconds,
    from
      (
      select
        fullVisitorId,
        visitId,
        visitorId,
        hits.type,
        hits.time,
        hits.hitNumber,
        hits.page.hostname,
        hits.page.pagePath,
        -- create some keys to handle data later
        concat(fullVisitorId,"_",string(visitId)) as session_key,
        concat(fullVisitorId,"_",string(visitId),"_",string(hits.hitNumber),"_",string(hits.time)) as hit_key,
        -- get max and min number of hits for each session
        MAX(hits.hitNumber) WITHIN RECORD AS hits_hitNumber_max,
        MIN(hits.hitNumber) WITHIN RECORD AS hits_hitNumber_min,    
        -- get min and max hit times to work out full session length
        MAX(hits.time) WITHIN RECORD AS hits_time_max,
        MIN(hits.time) WITHIN RECORD AS hits_time_min,        
        -- get next and previous hit time to be able to work out length of each hit
        LAG(hits.time, 1) OVER (PARTITION BY fullVisitorId, visitId ORDER BY hits.time ASC) as previous_hit_time,
        LEAD(hits.time, 1) OVER (PARTITION BY fullVisitorId, visitId ORDER BY hits.time ASC) as next_hit_time,
      from
        [XXX.ga_sessions_20151001],
        [XXX.ga_sessions_20151002],
        [XXX.ga_sessions_20151003],
      where
        hits.page.pagePath='/2015/10/01/blah-blah/'            
      )
    )
  ) 

我明白了:

[   {     "综合浏览量":" 24002",     " exit_pageviews":" 22468",     " sum_hit_length_seconds":" 455762.1240000001",     " avg_time_on_page":" 297.10699087353333"   } ]

但是如果我这样看一下查询浏览器:

ga-query-exlorer-settings

我明白了:

ga-query-exlorer-results

所以它看起来像浏览器匹配,但页面上的退出和时间似乎完全不同,我无法弄清楚为什么。

任何人都可以在您自己的数据上重新创建此示例吗?

感觉它与如何在GA中计算出口和时间有关,但在BQ GA食谱中找不到如何计算页面或出口时间的任何示例。

0 个答案:

没有答案