google-big-queryHow can I use Google Analytics and BigQuery together to analyze website data?
Google Analytics and BigQuery can be used together to analyze website data in a few different ways.
First, you can export the Google Analytics data to BigQuery and then use SQL queries to analyze the data. For example, the following query will return the total number of pageviews for a website in the last 30 days:
SELECT
date,
SUM(totals.pageviews) AS pageviews
FROM
`ga_sessions_*`
WHERE
_TABLE_SUFFIX BETWEEN FORMAT_DATE('%Y%m%d',DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY))
AND FORMAT_DATE('%Y%m%d',CURRENT_DATE())
GROUP BY
date
ORDER BY
date ASC
Output example
date pageviews
2020-05-01 15000
2020-05-02 16000
2020-05-03 17000
2020-05-04 18000
...
Second, you can use BigQuery to create custom metrics and dimensions in Google Analytics. For example, the following query will create a custom metric that calculates the average pageviews per session:
SELECT
date,
AVG(totals.pageviews) AS avg_pageviews_per_session
FROM
`ga_sessions_*`
GROUP BY
date
ORDER BY
date ASC
Once the custom metric is created, it can be used in Google Analytics to analyze the data.
More of Google Big Query
- How can I use Google Big Query to analyze Reddit data?
- How do I set up IAM permissions for Google BigQuery?
- How can I use Google BigQuery to access Wikipedia data?
- How do I use Google Big Query with Excel?
- How can I create a Google BigQuery table?
- How can I get started with Google BigQuery training?
- How do I set up permissions for Google BigQuery?
- How can I use Google Big Query to track revenue?
- How can I use IFNULL in Google BigQuery?
- How do I use a Google Big Query refresh token?
See more codes...