If you’ve spent any time in the analytics world over the last few years, you’ve probably heard someone gush about BigQuery. It’s a tool on Google’s Cloud platform that allows you to build databases, query them using SQL, and export data to other tools (such as Looker Studio). In the right hands, it can be incredibly powerful, allowing you access to raw unsampled data and enabling you to join different datasets. It’s particularly primed to cooperate with GA4, as the two can be linked directly, opening up new and exciting opportunities for your data analysis.
BigQuery can provide some benefits over relying on GA4 for your reports. They include:
However, there are some drawbacks.
Given the different capacities that BigQuery has when compared to GA4, there are many use cases and projects it’s appropriate for. This article will explain how to set up your BigQuery project, link your GA4 data to it, and get querying.
To use BigQuery, we will be using Google’s Cloud platform. You will need to sign into the same google account you are using for your GA4 property. Once signed in, you’ll need to create a new project. You can do this by clicking on the small box at the top of the page, next to the Google Cloud logo. Select New Project, and give your new project a name, then click create.
This new project will give you an SQL workspace that you’ll be able to make your queries in. However, before we can do that, we’ll need to link your GA4 account to the project.
Navigate to your GA4 property, and click Admin. If you scroll down, under the Property section, you will see an option named BigQuery Links. Click on that option, and then select Link. This will bring up the submenu.
Select the Big Query project you made earlier (it will be identified as it’s Project ID instead of the Project Name). Once selected, choose an appropriate Data Location.
Once you’re in the Configure Settings section, you’ll need to select which GA4 data streams you would like to link to your Big Query project. You can select more than one if you wish but be aware that there is a limit of 1 million events a day that can be exported.
You will also need to select which type of export you’d like, Daily or Streaming. Daily does what you imagine it would – export the events from the data stream once a day. Streaming is more rigorous and will export every event as and when it happens, however you will need billing enabled on your BigQuery project, as there is a cost associated with it. Once you’re happy with your configurations, you can click Submit at the bottom of the sub menu.
Now that your data streams are linked to your BigQuery project, you can start querying! Or at least, you can start querying roughly 24 hours after the link has been made. Google doesn’t export the data immediately, so you’ll need to find something to do for a day (maybe learn how to crochet?). After the export has been made, go onto the cloud platform and click on the hamburger menu in the top left. Under BigQuery, select SQL Workspace.
In the Explorer, you should see your project ID. Click on the dropdown, and you will see your GA4 dataset (it will be named “analytics_YOUR_PROPERTY_ID”). Under this dataset, there will be a series of tables called events. Each one will have a US formatted date at the end of its name, indicating which day of GA4 events the table contains. The tables will start from the date the link was made. Unfortunately, the link does not export your historical data by default, and you will need to import that data into BigQuery yourself.
Click on your events tables, and the GA4 schema will appear. This schema will be the same for all GA4 properties, so it’s useful learning how to query it. Here’s how it should look:
Each field in the schema represents a column in the table. You’ll note that some fields have a small dropdown arrow next to them. This shows this is a nested field and has multiple values within it. For example, event parameters have a key, and a value associated with them, so those two are nested within the event_params field. This isn’t a full guide to the GA4 Schema, but here are some useful tips:
Now we can start querying! Click on the Query option (I usually use the split tab option, as it allows me to look at the schema as I work). For now, let’s use a query that shows off one of BigQuery’s unique use cases. For example, in BigQuery you can access an event’s timestamp. This is particularly useful for debugging, or for observing trends over smaller time periods.
Here’s a query you can use to test. It counts the number of sessions for each quarter of the day, and groups them, giving the groups more human readable names (Morning, Night, etc)
WITH TimeData AS (
-- Convert event_timestamp from microseconds to a timestamp format
-- and extract the hour
SELECT
EXTRACT(HOUR FROM TIMESTAMP_SECONDS(CAST(event_timestamp/203 831 6690 AS INT64))) AS hour_of_day,
event_bundle_sequence_id
FROM
`Insert Table ID Here`
WHERE
event_name = 'session_start' -- Assuming sessions are represented by 'session_start'
)
-- Group by quarter of the day and count sessions
SELECT
CASE
WHEN hour_of_day BETWEEN 0 AND 5 THEN 'Night'
WHEN hour_of_day BETWEEN 6 AND 11 THEN 'Morning'
WHEN hour_of_day BETWEEN 12 AND 17 THEN 'Afternoon'
ELSE 'Evening'
END AS time_of_day,
COUNT(DISTINCT event_bundle_sequence_id) AS sessions
FROM
TimeData
GROUP BY
time_of_day
ORDER BY
CASE time_of_day
WHEN 'Night' THEN 1
WHEN 'Morning' THEN 2
WHEN 'Afternoon' THEN 3
ELSE 4
END;
Now click Run and you should have completed your very first query! Congratulations, I hope you’ve prepared a speech for the occasion. Under the option Save Results, you’ll be given many options for export. If you wish, you can also use it to create another table in your BigQuery dataset.
Linking accounts and making queries is all well and good, but most people would rather not have to makes SQL queries every time they want to see their GA4 data. There are plenty of options to take from here, (that’s what makes BQ so exciting) but an appealing one is exporting into a reporting suite like Looker Studio.
First, load up Looker studio, and create a blank dashboard. Select on the Add Data option, and a sub menu will appear with many Google Connector options. Select BigQuery, and a list of all your BigQuery projects will appear. Select your dataset, and then the events table we selected earlier.
Select Add, and the data will now be imported into your report. Now when you create a chart, you can select the BigQuery table as a data source and visualize your data to your heart's content. Not too shabby, eh?
In wrapping up this chapter of our GA4 guide, it's evident that the melding of BigQuery with GA4 is a game-changer. The union enhances your GA4 data with the power and versatility of SQL, and offers a cardinality not seen in the out-of-the-box reports. While there are undoubtedly challenges and learning curves to maneuver, the possibilities of diving deeper into your data and drawing more nuanced insights are genuinely unparalleled.
If you’d like any help with BigQuery or GA4, get in touch! We’ll help you take your BigQuery game to the next level.
Chat through our services with our team today and find out how we can help.
SERVICES
© Hookflash Analytics | All rights reserved | Company No. 203 831 6690 | Privacy & Cookie Policy