create_ga4_views¶
create_ga4_views(ga4_dataset, destination_dataset)
Description¶
Create views to help querying GA4 Data .
This function creates table functions in destination_dataset
to help querying GA4 data contained in ga4_dataset
(like your-project.analytics_123456789
).
Table functions are like views but take parameters as input. Here, they take
start_date
andend_date
parameters to restrict the analysis period and be more efficient
Each created table function is the copy of a query from Bigquery-GA4-Queries GitHub repo created by Ali Izadi.
For example, event_scope__flatten_events
table function will be created in destination_dataset
.
You can then get the flatten events between '2024-11-01' and '2024-12-01' with:
select *
from `destination_dataset`.event_scope__flatten_events('2024-11-01', '2024-12-01')
You can get details on each created table function by reading the README of Bigquery-GA4-Queries repo. If you find these queries useful, please add a star to the repo to show your support.
Queries from
BigQuery Administration
,Extras
folders are ignored as they go beyond GA4
Usage¶
Call or Deploy create_ga4_views
?
Call create_ga4_views
directly
The easiest way to use bigfunctions
create_ga4_views
function is deployed in 39 public datasets for all of the 39 BigQuery regions.- It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)
Public BigFunctions Datasets
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Deploy create_ga4_views
in your project
Why deploy?
- You may prefer to deploy
create_ga4_views
in your own project to build and manage your own catalog of functions. - This is particularly useful if you want to create private functions (for example calling your internal APIs).
- Get started by reading the framework page
Deployment
create_ga4_views
function can be deployed with:
pip install bigfunctions
bigfun get create_ga4_views
bigfun deploy create_ga4_views
Examples¶
call bigfunctions.eu.create_ga4_views("your-project.your_ga4_dataset", "your-project.your_destination_dataset");
call bigfunctions.us.create_ga4_views("your-project.your_ga4_dataset", "your-project.your_destination_dataset");
call bigfunctions.europe_west1.create_ga4_views("your-project.your_ga4_dataset", "your-project.your_destination_dataset");
Use cases¶
Steps to Query GA4 Data Efficiently Using BigFunctions¶
1. Create a Destination Dataset
Prepare a dataset in BigQuery where the GA4 table functions will be stored. For example:
create schema `Ga4-Project.ga4_bigquery_queries`;
2. Call the GA4 View Creation Function
Use the bigfunction to create table functions for querying GA4 data. For example:
call bigfunctions.us.create_ga4_views(
'Ga4-Project.analytics_310989290',
'Ga4-Project.ga4_bigquery_queries'
);
3. Wait for the function to process and create all necessary table functions.
Once completed, all table functions (queries) are available in your destination dataset.
4. Query GA4 Data Using Table Functions
You can now query specific GA4 data efficiently with date ranges by calling the created table functions. For example:
select *
from `Ga4-Project.ga4_bigquery_queries`.event_scope__flatten_events('2024-11-01', '2024-12-01');
Replace '2024-11-01' and '2024-12-01' with your desired date range.
Need help or Found a bug?
Get help using create_ga4_views
The community can help! Engage the conversation on Slack
We also provide professional suppport.
Report a bug about create_ga4_views
If the function does not work as expected, please
- report a bug so that it can be improved.
- or open the discussion with the community on Slack.
We also provide professional suppport.