Free tool by MD Niamul

Free GA4 BigQuery SQL Generator Ready GA4 BigQuery Queries Written for Your Project, Dataset and Dates

Standard SQL for the GA4 Export, with Plain-English Notes on What Each Query Returns

19 query templates
Your project, dataset and time zone filled in
Copy, download .sql or Excel

Type your project and dataset and this free GA4 BigQuery SQL generator writes GA4 BigQuery queries you can paste straight into the BigQuery console. Each one reads the events_ export tables, filters the dates on _TABLE_SUFFIX to keep the cost down, and unpacks event_params and items for you. Every template says what it returns, which columns you get, and where the numbers will differ from the GA4 interface.

19Query templates
4Template groups
850+Projects delivered
600+Five-star reviews
MD Niamul, creator of the free ga4 bigquery sql generator
upworkTop Rated Plus
GA4 + BigQueryFree SQL Generator
OfficialStape Partner

GA4 BigQuery Queries You Can Generate

Daily Users and Sessions
Session Source / Medium
First-Touch Acquisition
Landing Pages
Top Pages
Ecommerce Funnel
Revenue and AOV
Top Items
De-duplicated Purchases
Duplicate transaction_id
Device and Country
New vs Returning
Engagement Time
Event Parameters
Cohort Retention
Consent State
Missing Source Check
_TABLE_SUFFIX Filter
FREE GA4 BIGQUERY SQL GENERATOR

Generate Your GA4 BigQuery Queries

Fill in your export details, pick a template and copy the SQL.

GA4 BigQuery SQL GeneratorTraffic · Ecommerce · Engagement · Data quality · BigQuery Standard SQL
Free · No login

1. Your BigQuery export

Rolling ranges end yesterday, because today’s table is not complete. Use the same time zone as your GA4 property.

2. Choose a query

Your query

Written against Google’s export schemaDates filtered on _TABLE_SUFFIXNothing you type is sent anywhere
WHAT IT WRITES

Which GA4 BigQuery Queries Does It Generate?

Nineteen templates in four groups, each adjusted to your export.

Daily Overview

Users, new users, sessions, events, conversions and revenue for each day.

Traffic Sources

Sessions and purchases by session source and medium, plus first-touch user acquisition.

Landing Pages and Pages

Sessions, engagement and conversions by landing page, and top pages by views.

Ecommerce

The funnel from view_item to purchase, revenue and average order value, and top items.

Engagement

New and returning users, engagement time per session, event counts and weekly retention.

Any Event Parameter

Pull one parameter out of event_params for the event you name and count its values.

Data Quality

Repeated transaction IDs, the share of events by consent state, and sessions with no source.

Cost Awareness

Every query filters the tables by date and selects only the columns it needs.

How Does the GA4 BigQuery SQL Generator Work?

Three steps. The tool only writes text.

01

Enter your export details

Project ID, dataset, date range and the time zone of your GA4 property.

02

Pick a template

Search or filter by group. Read what it returns and the caveats.

03

Run it in BigQuery

Paste the SQL into the BigQuery console, check the bytes it will process, then run it.

How Is GA4 Data Stored in BigQuery?

When you link GA4 to BigQuery, Google creates a dataset named analytics_ followed by your property ID. Inside it there is one table per day, named events_YYYYMMDD. If you switch on streaming export you also get events_intraday_YYYYMMDD for the current day.

Each row is one event. Details that belong to the event sit in nested lists: event_params holds parameters as a key with a value in one of four slots (string_value, int_value, float_value, double_value), and items holds the products. That is why a GA4 BigQuery query needs UNNEST, and why writing one from scratch is slow.

Why filter on _TABLE_SUFFIX?

BigQuery charges on-demand queries by the amount of data they read. A query on events_* with no date filter reads every day you have ever exported. Filtering on _TABLE_SUFFIX tells BigQuery which daily tables to open, so it reads only those. Every template here does that. Before you run a query, look at the estimate of bytes it will process in the BigQuery console.

Three kinds of traffic source

  • traffic_source is the source that first acquired the user. It does not change on later visits.
  • collected_traffic_source holds the campaign values and click IDs collected with that event.
  • session_traffic_source_last_click holds the last-click source of the session, including Google Ads details where available.

The generator has a template for each and says which one it uses. The two newer records were added to the export after it launched. If your export is older, days from before they were added show empty values.

Why will the numbers not match GA4 exactly?

Google explains several reasons. The GA4 interface estimates counts such as users and sessions, while BigQuery counts them exactly. The interface can add modelled data for visitors who declined consent and can use Google Signals; neither is in the export. Reports can hide small rows through thresholding. Attribution in the interface cannot be fully rebuilt from the export. Daily tables can also keep changing for up to 72 hours. Expect close, not identical.

What this tool cannot check

The queries are generated text. The tool cannot run them, cannot see your data and cannot confirm that your project ID, dataset or event names exist. It has not been able to test the SQL against your export. If your export started before a field was added, queries that use that field return empty values for the older days: this affects the session source template (session_traffic_source_last_click), the collected source and missing source templates (collected_traffic_source) and the active users column (is_active_user). Always check the bytes-processed estimate before you run anything, and compare a first result with a GA4 report you trust.

GA4 BigQuery Export Fields Worth Knowing

From Google’s export schema documentation.

FieldWhat it holdsNote
event_timestampWhen the event was loggedMicroseconds, in UTC
event_dateThe day of the eventText as YYYYMMDD, in the property’s time zone
user_pseudo_idThe anonymous ID for the browser or app installEmpty for events collected without analytics consent
ga_session_idThe session IDInside event_params as an int_value. Unique only together with user_pseudo_id
event_paramsParameters sent with the eventA repeated key and value record. Needs UNNEST
itemsProducts on ecommerce eventsA repeated record. Needs UNNEST
ecommerce.purchase_revenueRevenue of a purchase eventIn the local currency. Purchase events only
traffic_sourceSource that first acquired the userNot filled in intraday tables
collected_traffic_sourceCampaign values collected with the eventAdded to the export later than the original schema
session_traffic_source_last_clickLast-click source of the sessionAdded to the export later than the original schema
privacy_infoConsent state for analytics and ads storageValues Yes, No or Unset
is_active_userWhether the user was active that dayFilled in daily tables only

Who Is This Generator For?

Analysts

Start from a working query instead of a blank editor.

Marketers

Get numbers out of BigQuery without learning UNNEST first.

Agencies

Reuse the same checked templates across client exports.

Tracking specialists

Find duplicate purchases, consent gaps and missing sources quickly.

MORE FREE TOOLS

More Free Marketing Tools by MD Niamul

33 free tools for tracking, analytics, advertising and SEO. No login needed.

Free GTM & GA4 Regex Tester

Build and test regular expressions for GTM triggers and GA4 filters, with ready patterns.

Open the regex tester →

Free Measurement Plan Generator

Get a tracking plan for your business type: events, parameters and platform mapping in Excel.

Open the plan generator →

Free Google Ads Audit Tool

Scan a landing page and keywords for Quality Score, ad copy, CTR and tracking issues.

Open the Google Ads audit →

Free UTM Builder

Create clean UTM links with platform presets, GA4 channel preview and bulk export.

Open the UTM builder →

Trusted by 600+ Brands & Agencies

MYLENE
HOVER BOARDS
GT SOLI
CAMBRIDGE
BIENEN CORB 24
ZULU SHACK CREATIVE
ADPSY LLC
HIGH PERFORMANCE MEDIA
ADS PERFORMANCE
LEGESI
TESTIMONIAL

Analytics & Conversion Tracking Client Testimonials

Hear from our clients. Loved by 600+ businesses worldwide.

Madison Jonas, client of MD Niamul
Madison JonasGoogle Ads clientLinkedIn recommendation
★★★★★

“I had an excellent experience working with MD on my Google Ads account. Everything was set up perfectly and worked smoothly without any issues or troubleshooting needed. His expertise and attention to detail made the whole process effortless.”

Mehboob Khan, client of MD Niamul
Mehboob KhanGoogle Analytics projectsLinkedIn recommendation
★★★★★

“I worked with Niamul on multiple Google Analytics projects and was impressed by his expertise and precision. He has a strong grasp of tracking, reporting, and optimization, always ensuring accurate insights. He is proactive, reliable, and easy to collaborate with.”

Jacco Bouw, client of MD Niamul
Jacco BouwShopify, GA4 & Google Ads trackingLinkedIn recommendation
★★★★★

“MD Niamul is extremely skilled. He fixed my Shopify, Google Analytics, and Google Ads conversion tracking perfectly. Everything works exactly as it should now, and he even added an extra data layer, which was very helpful. Outstanding service, fast delivery, and highly recommended.”

Ryan S Kemp, client of MD Niamul
Ryan S KempCMO, Co-Founder, Zulu Shack CreativeLinkedIn recommendation
★★★★★

“Reliable, knowledgeable, and truly trustworthy. I’ve been working with Niamul for over a year, and he consistently delivers exceptional results across all analytics tasks. His expertise, communication, and commitment make him my go-to specialist for tracking, measurement, and data accuracy.”

Casper Klein, client of MD Niamul
Casper KleinMeta Pixel & server-side trackingLinkedIn recommendation
★★★★★

“MD N delivered flawless Meta Pixel, CAPI, and server-side tracking. He understood our goals quickly, explained everything clearly, and ensured full transparency. Communication was smooth, updates were consistent, and the results improved our data accuracy and ad performance.”

600+

Five-star reviews from businesses and agencies in the USA, Canada, UK and Australia.

Read All Reviews

Video Testimonials: Hear It From Our Clients

FAQ

Frequently Asked Questions About the Free GA4 BigQuery SQL Generator

Is the GA4 BigQuery SQL generator free?

Yes. It runs in your browser with no login and no email form.

Does it connect to my BigQuery project?

No. It only writes SQL text using the project and dataset names you type. It cannot run the queries or see your data, and nothing you type is sent anywhere.

Where do I find my project ID and dataset?

In the BigQuery console, the left panel lists your project. Under it is the dataset, named analytics_ followed by your GA4 property ID. The daily tables inside are named events_ with the date.

Will these queries cost money to run?

BigQuery bills on-demand queries by the data they read, and has a free monthly allowance. Each template limits the dates with _TABLE_SUFFIX and selects only the columns it needs. Check the bytes-processed estimate in the console before you run a query.

Why do the results not match my GA4 reports?

Google lists several reasons: the interface estimates some counts, adds modelled data and Google Signals, applies thresholding and uses attribution that cannot be fully rebuilt from the export. Recent days can also still be updating.

What is the difference between events_ and events_intraday_ tables?

events_ tables are the finished daily export. events_intraday_ tables are filled during the day when streaming export is on, and some fields such as traffic_source and is_active_user are not filled there.

How do I get an event parameter out of GA4 data in BigQuery?

Parameters are stored in the repeated event_params record. You select the value with a small sub-query that uses UNNEST and the parameter key. The “Extract an event parameter” template writes it for you.

Which source and medium does the session query use?

The main template uses session_traffic_source_last_click, the session’s last-click source. A second template uses collected_traffic_source for older exports. Both are explained next to the SQL, with their limits.

Are the queries tested?

They are written against Google’s published export schema and checked for syntax, but they have not been run on your data. Treat the first result as a draft and compare it with a GA4 report.

Queries Are the Easy Part. Trustworthy Data Is the Job

I am MD Niamul, a conversion tracking and web analytics specialist and an official Stape partner. I set up GA4 with BigQuery export, fix the tracking behind it, and build reporting in Looker Studio that your team can rely on.