Skip to content

Instantly share code, notes, and snippets.

@brunomertins
Forked from jhnvdw/aw_traffic_source.sql
Created March 20, 2023 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunomertins/0f54ce1ec3e4913224dc94933ee0e5f8 to your computer and use it in GitHub Desktop.
Save brunomertins/0f54ce1ec3e4913224dc94933ee0e5f8 to your computer and use it in GitHub Desktop.
SELECT
-- traffic_source.name (dimension | name of the marketing campaign that first acquired the user)
traffic_source.name,
-- traffic_source.medium (dimension | name of the medium (paid search, organic search, email, etc.) that first acquired the user)
traffic_source.medium,
-- traffic_source.source (dimension | name of the network that first acquired the user)
traffic_source.source
FROM
-- Change this to your Google Analytics 4 export location in BigQuery
`ga4.analytics_1234567890.events_*`
WHERE
-- Define static and/or dynamic start and end date
_table_suffix BETWEEN '20200220'
AND FORMAT_DATE('%Y%m%d',DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY))
GROUP BY
1,
2,
3
LIMIT
10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment