BigQuery, SQL, & Looker Studio
College of Business Administration - Cal Poly Pomona - CCIDM
3/17/2026
The Modern Marketing Problem: We have too much data and not enough time. If you are manually copy-pasting metrics into Excel every Friday, you are losing to automation.
🔥 The Career Impact: Today, we move from Marketing Theory (The Art) to Marketing Operations (The Science). Mastering SQL and cloud architecture instantly separates you from 90% of entry-level applicants.
Our Pipeline for Today: GA4 (Live Data) & CSV (Budgets) ➡️ BigQuery (Storage & SQL) ➡️ Looker Studio (Dashboard)
What is Google Analytics 4? GA4 is Google’s current web and app tracking platform. It logs what users do when they visit your site, where they came from, and what they buy.
The Old Way (Universal Analytics): Historically, analytics tracked “Sessions” (a block of time a user spent on a site). Data was rigid and heavily aggregated.
The GA4 Way: Everything is an Event! In GA4, the concept of a session takes a back seat. Now, every single interaction is an Event.
page_view event.scroll event.purchase event.Why this matters for SQL: Because GA4 just dumps millions of these raw events into BigQuery, it creates highly complex, nested data (Arrays) that requires SQL to unpack.
🚨 The Limits of GA4 (The UI)
✅ The Power of the Cloud (BigQuery + Looker)
The “Big Three” Cloud Providers
When companies say they “use the cloud,” they are just renting massive computers from one of three tech giants:
What is BigQuery? BigQuery is a specific product inside Google Cloud. It is a fully managed Enterprise Data Warehouse.
Think of Google Cloud as the giant digital office building, and BigQuery is the massive, ultra-secure filing cabinet we are renting inside of it.
After taking this workshop, participants should be able to:
SELECT and WHERE) to filter data and find specific answers.Digital marketing roles fall into 4 categories, and each needs this data stack differently.
(Writers, Social, Designers)
(SEO, PPC, Email Specialists)
(Analysts, Data Scientists)
VIEWs, and manage the “single source of truth” for the whole company.(Managers, CMOs)
Columnar Storage & The Cost of Querying:
Excel (Row-Based):
Reads data row by row, left to right. Great for finding one specific customer’s entire profile.
BigQuery (Columnar):
Stores data by columns. If you only want to calculate “Total Revenue,” the computer completely ignores the other 100 columns.
The Cost of BigQuery:
The Golden Rule: SELECT * scans every single column in the database. In the real world, this costs your company real money. Only SELECT the columns you need!
ccidm-spring2026-sandbox.No credit card required for Sandbox environments!
How does data get into our warehouse?
The Native Export Pipeline
Note: Data takes 24 hours to appear. For today’s querying, we will use a Google public dataset!
Let’s bring in our offline campaign budgets.
marketing_data.campaign_budgets.csv.budget_lookup.The Automated Pipeline:
marketing_data dataset.Where is the Google Ads Data today?
Because we are querying Google’s public ga4_obfuscated_sample_ecommerce dataset, we cannot link it to a live Google Ads account. Furthermore, Google does not provide a matching public Google Ads dataset for this GA4 data.
To make our ROI math work today, our campaign_budgets.csv file is simulating the cost data that this Data Transfer Service would normally generate for you!
Method 1: The Direct Link
The fastest way to load the dataset is to follow this direct link straight to the Google Cloud Console:
Method 2: The Explorer Pane
If you want to find it manually inside BigQuery:
bigquery-public-data and press Enter.ga4_obfuscated_sample_ecommerce.SQL (Structured Query Language) is how we talk to databases. Today we are using GoogleSQL (BigQuery’s specific dialect). Before we type anything, let’s look at the basic “grammar” of a query. If you know these three commands, you know 80% of SQL.
SELECT (The Columns): What data do I want to see? Think of this as hiding or showing columns in an Excel sheet.FROM (The Address): Exactly which filing cabinet and folder is this data in?WHERE (The Rows): How do I filter this data? Think of this as clicking the funnel icon in Excel to only show specific rows.Think of BigQuery’s structure just like the file system on your laptop:
ccidm-workshop)marketing_data)budget_lookup)Why does this matter?
When you write a SQL query, the computer doesn’t magically know where your data is. You have to give it the full “address” by connecting all three levels with periods: `project.dataset.table`
Now let’s expand our query. We will add math and grouping.
What is the * doing in the FROM statement? BigQuery partitions (splits) GA4 data into a new table for every single day. The * is a Wildcard. It tells BigQuery: “Look at all the days at once.”
How we type it:
SELECTFROMWHEREGROUP BYORDER BYHow the computer reads it:
FROM (Finds the table)WHERE (Filters the rows)GROUP BY (Buckets the data)SELECT (Does the math)ORDER BY (Sorts the final list)Tip
GoogleSQL Syntax Refrence: https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax
Let’s combine our live web performance with our static budgets using a WITH clause to create a temporary table!
WITH ga4_aggregate AS (
SELECT
traffic_source.medium AS channel,
COUNT(event_name) AS purchases
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE event_name = 'purchase'
GROUP BY traffic_source.medium
)
SELECT
b.channel,
ga.purchases,
b.spend,
ROUND((b.spend / ga.purchases), 2) AS CPA
FROM `marketing_data.budget_lookup` AS b
LEFT JOIN ga4_aggregate AS ga
ON b.channel = ga.channel
ORDER BY CPA ASC;Step 1: Get your database metadata (schema).
AI needs context to avoid hallucinating.
#| code-fold: true
WITH DateRange AS (
SELECT
-- 1. Use Regex to cleanly extract just the 8-digit date
MIN(REGEXP_EXTRACT(table_name, r'^events_(\d{8})$')) AS earliest_date,
MAX(REGEXP_EXTRACT(table_name, r'^events_(\d{8})$')) AS latest_date
FROM
`bigquery-public-data.ga4_obfuscated_sample_ecommerce.INFORMATION_SCHEMA.TABLES`
WHERE
-- 2. Filter out intraday tables using Regex
REGEXP_CONTAINS(table_name, r'^events_\d{8}$')
)
SELECT
c.column_name,
c.data_type,
d.earliest_date,
d.latest_date
FROM
`bigquery-public-data.ga4_obfuscated_sample_ecommerce.INFORMATION_SCHEMA.COLUMNS` c
CROSS JOIN
DateRange d
WHERE
c.table_name = 'events_20210131'
-- 3. Keep the columns in their original schema order
ORDER BY
c.ordinal_position;Step 2: Copy the results table and give this prompt to any AI:
“I am querying a BigQuery GA4 dataset. Attached is my schema. Write a query using the
events_*wildcard table. Find the total number of ‘purchase’ events grouped by the user’s device category. Be sure to include a date range to limit data costs.”
Always validate the logic before running!
The Problem: Looker Studio is a visualization layer, not a data transformation engine. If we force Looker to perform our complex LEFT JOIN on the fly, the dashboard will be incredibly slow.
The Solution: A view is a saved SQL query that acts as a “virtual table.” We do the heavy lifting in BigQuery and save it. When Looker Studio connects, it sees a clean, Excel-like table.
#| code-fold: true
CREATE OR REPLACE VIEW `marketing_data.v_campaign_performance` AS
WITH ga4_aggregate AS (
SELECT
PARSE_DATE('%Y%m%d', event_date) AS date, -- Turns "20210131" into a real Date
traffic_source.medium AS channel,
COUNT(event_name) AS purchases,
SUM(ecommerce.purchase_revenue) AS revenue
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
WHERE event_name = 'purchase'
GROUP BY date, channel
)
SELECT
ga.date,
b.channel,
ga.purchases,
b.spend,
ga.revenue
FROM `marketing_data.budget_lookup` AS b
LEFT JOIN ga4_aggregate AS ga
ON b.channel = ga.channel
ORDER BY ga.date DESC;ccidm-spring2026-sandbox > marketing_data > v_campaign_performance.When you add a Date Range Control in Looker Studio, you might see “No Data” or broken charts. Why?
PARSE_DATE).Visuals to Add:
Calculated Fields:
SUM(Revenue)/MAX(Spend) directly in Looker Studio.Today we transformed from theoretical marketers to data operators.
✅ Set up a cloud database (BigQuery)
✅ Uploaded and joined disparate data sources
✅ Wrote SQL with AI assistance
✅ Modeled a virtual table (View)
✅ Automated a dynamic Looker Studio dashboard
Scalable Customer & Campaign Analysis in R
What happens when you need to run deep customer cohort analysis or funnel drop-offs, and spreadsheets crash?
Next time, we tackle “Big-ish Data” on your local machine using R, DuckDB, and Arrow.
Thank You!
Helpful Links:
Center for Customer Insight and Digital Marketing