我对如何在GBQ中计算平均会话持续时间进行了很多研究,发现了这一点:
“在您指定的日期范围内,每个会话的持续时间之和,然后将该总和除以会话总数。”
要查找会话总数,我对CONCAT(fullVisitorId,VisitId)进行了计数:
SQL查询的编写方式如下:
SELECT sub.pagePath, ROUND(SUM(sub.timeonSite)/COUNT( DISTINCT
sub.distinct_visitid_fullvisitorid),2) AS Avg_Session_Duration
FROM
(
SELECT
hits.page.pagePath,
totals.timeonSite,
totals.visits AS totals_visits,
fullvisitorid AS distinct_fullvisitorid,
visitid AS distinct_visitid,
(CONCAT(CAST(fullvisitorid AS string),CAST(visitid AS string))) AS distinct_visitid_fullvisitorid
FROM `tfa-big-query.74006564.ga_sessions_*` AS GA, UNNEST(GA.hits) AS hits
WHERE _table_suffix BETWEEN '20181003' AND '20190303'
) sub
WHERE
sub.pagePath LIKE '%/where-we-work/new-york%'
GROUP BY sub.pagePath
在GA界面中,每个URL页面显示的平均会话持续时间不超过0秒至5分钟。 但是对于大多数网址,我的平均会话时长超过800分钟。