How to Combine Google Analytics and Google Ads Data for Comprehensive Campaign Analysis
Overview #
Syncing Your Google Data and Your Google Ads Data #
kind: source
spec:
name: googleanalytics
path: cloudquery/googleanalytics
registry: cloudquery
version: "v4.3.3"
tables: ["*"]
destinations: ["postgresql"]
backend_options:
table_name: "cq_state_googleanalytics"
connection: "@@plugins.postgresql.connection"
spec:
property_id: "<YOUR_PROPERTY_ID_HERE>"
oauth:
access_token: "<YOUR_OAUTH_ACCESS_TOKEN>"
reports:
- name: example
dimensions:
- campaignId
- campaignName
- sourceMedium
- date
- language
- country
- city
- googleAdsCampaignId
- deviceCategory
metrics:
- name: Sessions
- name: totalUsers
- name: screenPageViews
- name: averageSessionDuration
- name: bounceRate
- name: transactions
- name: purchaseRevenue
- name: activeUsers
- name: newUsers
keep_empty_rows: true
googleads_campaigns
table is in your database.Query to Combine Data #
SELECT
ga.date,
ga.dimensions->>'campaignName' AS campaign_name,
ga.dimensions->>'sourceMedium' AS source_medium,
ga.dimensions->>'deviceCategory' AS device_category,
ga.dimensions->>'country' AS country,
ga.dimensions->>'city' AS city,
ga.metrics->>'Sessions' AS sessions,
ga.metrics->>'totalUsers' AS total_users,
ga.metrics->>'screenPageViews' AS pageviews,
ga.metrics->>'averageSessionDuration' AS avg_session_duration,
ga.metrics->>'bounceRate' AS bounce_rate,
ga.metrics->>'transactions' AS transactions,
ga.metrics->>'purchaseRevenue' AS revenue,
gad.name AS google_ads_campaign_name,
gad.customer_id,
gad.advertising_channel_type,
gad.start_date AS google_ads_start_date,
gad.end_date AS google_ads_end_date,
gad.status AS google_ads_status,
gad.campaign_budget AS google_ads_campaign_budget
FROM
public.ga_example ga
JOIN
googleads_campaigns gad
ON
ga.dimensions->>'googleAdsCampaignId' = gad.id::text;
ga_example
table are stored as JSON data, so we must extract the values properly.Example Results #
date | campaign_name | source_medium | device_category | country | city | sessions | total_users | pageviews | avg_session_duration | bounce_rate | transactions | revenue | google_ads_campaign_name | customer_id | advertising_channel_type | google_ads_start_date | google_ads_end_date | google_ads_status | google_ads_campaign_budget |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2024-07-31 00:00:00 | Summer Sale | google / cpc | mobile | USA | New York | 1000 | 900 | 1500 | 300 | 0.5 | 50 | 5000 | Summer Sale | 123456789 | SEARCH | 2024-06-01 | 2024-12-31 | ENABLED | 1200000 |
2024-08-01 00:00:00 | Winter Sale | google / cpc | desktop | USA | San Francisco | 800 | 700 | 1200 | 250 | 0.6 | 30 | 3000 | Winter Sale | 123456789 | DISPLAY | 2024-07-01 | 2024-11-30 | PAUSED | 800000 |
2024-08-02 00:00:00 | Spring Sale | google / cpc | tablet | USA | Los Angeles | 1200 | 1100 | 1800 | 320 | 0.4 | 60 | 6000 | Spring Sale | 123456789 | SEARCH | 2024-08-01 | 2024-10-31 | ENABLED | 1500000 |
Summary #
Written by Ron Shemesh
Ron is a Senior Software Engineer at CloudQuery and has a background in data science and now works as a senior software engineer at CloudQuery. He has experience working in Python, SQL, React, Java and R. At CloudQuery, Ron has worked on our range of integrations and several projects foundational to platform performance. He loves taking on a challenge and using it to improve his skills.