简体   繁体   中英

How to Pull Load Speed and Bounce Rate via Bigquery

I'm trying to write a query via Bigquery with Google Analytics data to find out the impact of the page speed on my site. There is a lot of research that talk about the impact of a slow site website on conversions and I'm hoping to run a similar type of analysis ( for example ).

Currently I have the below query, however it looks like hit.time increases with totals.pageviews. If I'm not mistaken, this must mean that the hits.time is registered as total time on a site and not necessarily the total time on a given page.

SELECT
  ROUND(AVG(totals.pageviews),0) AS avg_page_views,
  CASE 
        WHEN hits.time <= 1000 THEN '0 Second'
        WHEN hits.time BETWEEN 1001 AND 2000 THEN '1 Second'
        WHEN hits.time BETWEEN 2001 AND 3000 THEN '2 Second'
        WHEN hits.time BETWEEN 3001 AND 4000 THEN '3 Second'
        WHEN hits.time BETWEEN 4001 AND 5000 THEN '4 Second'
        WHEN hits.time BETWEEN 5001 AND 6000 THEN '5 Second'
        WHEN hits.time BETWEEN 6001 AND 7000 THEN '6 Second'
        WHEN hits.time BETWEEN 7001 AND 8000 THEN '7 Second'
        WHEN hits.time BETWEEN 8001 AND 9000 THEN '8 Second'
        WHEN hits.time BETWEEN 9001 AND 10000 THEN '9 Second'
        WHEN hits.time BETWEEN 10001 AND 10000 THEN '10 Second'
        ELSE 'More than 10 Seconds'
   END hits.time
FROM
    [session.ga_sessions_20150501]
WHERE
        hits.page.pagePath != ''
        and totals.bounces IS NOT NULL
        AND hits.hitnumber >= 1
        AND hits.time > 0
        AND hits.type = 'PAGE'
        AND hits.page.pagePath LIKE '%/work/apps/business/%'  
GROUP BY 1,2
ORDER BY 1
LIMIT 2000
;

Any thoughts on how to change this query to pull the speed per page so it can be graphed with something like conversions or bounce rate? I know this data exists in Google Analytics, however I can't find a good dimension to use for via the Bigquery API , or in Google Analytics for that matter.

Thanks in advance!

This is now possible, I presume its been added since the original question.

The below correctly matches page load time back to the GA interface.

with speed_metrics as (
SELECT
date,
device.browser,
device.operatingSystem,
device.deviceCategory,
geoNetwork.country,
visitorId, 
fullVisitorId,
IF(totals.visits=1,CONCAT(fullVisitorId, CAST(visitId AS STRING)), null) AS 
session_id,
hits.hitNumber,
hits.latencyTracking.pageLoadSample, 
hits.latencyTracking.pageLoadTime,
hits.latencyTracking.pageDownloadTime,
hits.latencyTracking.redirectionTime,
hits.latencyTracking.speedMetricsSample,
hits.latencyTracking.domainLookupTime,
hits.latencyTracking.serverConnectiontime,
hits.latencyTracking.serverResponseTime,
hits.latencyTracking.domLatencyMetricsSample,
hits.latencyTracking.domInteractiveTime,
hits.latencyTracking.domContentLoadedTime
FROM `river-island-clothing-co-ltd.155484603.ga_sessions_20210308`
, unnest (hits) as hits 
)
select 
avg(pageLoadTime) / 1000 as avg_load_time ,
sum(pageLoadTime) / count(distinct (concat(session_id, cast(hitNumber as string)))) / 
1000 as also_avg_load_time
from speed_metrics
where pageLoadSample is not null
LIMIT 1000

The useful bits to be aware of is that the results are generated from a sample of your overall pageviews/sessions, note the where clause. Since this is at hit level (pageview in this case) the number of records = the number of pageviews, hence both aggregations generate the same result!

You are totally off here.

hits.time means something else:

The number of milliseconds after the visitStartTime when this hit was registered. The first hit has a hits.time of 0.

So measures the time elapsed since visit start time, and not at all loading time. It's the request time when it was initiated, nothing that has to do with DOM.

AFAIK there is no metric to give you DOM load time.

Schema:

https://support.google.com/analytics/answer/3437719?hl=en&ref_topic=3416089&vid=1-635792326108722532-2868285191

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM