Last active
May 31, 2022 00:27
-
-
Save jhnvdw/3d70ea00d2514f227356c62a154b4bd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
-- Sessions (metric) | |
COUNT(DISTINCT CONCAT(fullVisitorId, CAST(visitStartTime AS STRING))) AS Sessions, | |
-- Bounces (metric) | |
COUNT(DISTINCT | |
CASE | |
WHEN totals.bounces = 1 THEN CONCAT(fullVisitorId, CAST(visitStartTime AS STRING)) | |
ELSE | |
NULL | |
END | |
) AS Bounces, | |
-- Bounce Rate (metric) | |
COUNT(DISTINCT | |
CASE | |
WHEN totals.bounces = 1 THEN CONCAT(fullVisitorId, CAST(visitStartTime AS STRING)) | |
ELSE | |
NULL | |
END | |
) / COUNT(DISTINCT CONCAT(fullVisitorId, CAST(visitStartTime AS STRING))) AS Bounce_Rate, | |
-- Average Session Duration (metric) | |
SUM(totals.timeOnSite) / COUNT(DISTINCT CONCAT(fullVisitorId, CAST(visitStartTime AS STRING))) AS Average_Session_Duration | |
FROM | |
`bigquery-public-data.google_analytics_sample.ga_sessions_*` | |
WHERE | |
_table_suffix BETWEEN '20160801' | |
AND FORMAT_DATE('%Y%m%d',DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)) | |
AND totals.visits = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment