
Meta's marketing analytics team wants a campaign-level view of top-of-funnel performance across recent ad delivery. Write a SQL query to return top-of-funnel clicks and cost per click (CPC) by campaign for the last 30 days.
DATE '2024-06-30'.funnel_stage = 'top_of_funnel'.campaign_idcampaign_nametop_funnel_clickstotal_spendcpc0 clicks and NULL CPC.top_funnel_clicks descending, then campaign_id ascending.meta_campaigns| column | type | description |
|---|---|---|
| campaign_id | INT | Unique campaign identifier |
| campaign_name | VARCHAR(100) | Campaign name in Meta Ads Manager |
| objective | VARCHAR(50) | Campaign objective |
| status | VARCHAR(20) | Current campaign status |
meta_ad_delivery| column | type | description |
|---|---|---|
| delivery_id | INT | Unique delivery record |
| campaign_id | INT | Campaign tied to spend |
| delivery_date | DATE | Date of ad delivery |
| spend_usd | DECIMAL(10,2) | Spend recorded for that date |
| impressions | INT | Delivered impressions |
meta_click_events| column | type | description |
|---|---|---|
| click_id | INT | Unique click event |
| campaign_id | INT | Campaign tied to the click |
| click_date | DATE | Date of click |
| funnel_stage | VARCHAR(30) | Funnel stage classification |
| click_source | VARCHAR(30) | Source surface for the click |
meta_campaigns| campaign_id | campaign_name | objective | status |
|---|---|---|---|
| 103 | Reels Prospecting US | TRAFFIC | ACTIVE |
| 101 | Advantage+ Shopping Spring | SALES | ACTIVE |
| 104 | Lead Gen SMB | LEADS | PAUSED |
| 102 | Click to Message LATAM | ENGAGEMENT | ACTIVE |
meta_ad_delivery| delivery_id | campaign_id | delivery_date | spend_usd | impressions |
|---|---|---|---|---|
| 2003 | 102 | 2024-06-29 | 90.00 | 9000 |
| 2001 | 101 | 2024-06-28 | 120.00 | 10000 |
| 2008 | 104 | 2024-05-31 | 80.00 | 7000 |
| 2006 | 103 | 2024-06-05 | 0.00 | 0 |
meta_click_events| click_id | campaign_id | click_date | funnel_stage | click_source |
|---|---|---|---|---|
| 3002 | 101 | 2024-06-29 | top_of_funnel | Facebook Feed |
| 3005 | 102 | 2024-06-28 | mid_funnel | Messenger Inbox |
| 3008 | 103 | 2024-05-30 | top_of_funnel | Instagram Reels |
| 3010 | 104 | 2024-06-10 | top_of_funnel | Facebook Feed |
| campaign_id | campaign_name | top_funnel_clicks | total_spend | cpc |
|---|---|---|---|---|
| 101 | Advantage+ Shopping Spring | 3 | 200.00 | 66.67 |
| 103 | Reels Prospecting US | 2 | 60.00 | 30.00 |
| 104 | Lead Gen SMB | 1 | 80.00 | 80.00 |
| 102 | Click to Message LATAM | 0 | 100.00 | NULL |
| Column | Type | Description |
|---|---|---|
| campaign_idPK | INT | Unique campaign identifier |
| campaign_name | VARCHAR(100) | Campaign name in Meta Ads Manager |
| objective | VARCHAR(50) | Campaign objective |
| status | VARCHAR(20) | Current campaign status |
| Column | Type | Description |
|---|---|---|
| delivery_idPK | INT | Unique delivery record |
| campaign_id | INT | Campaign tied to spend |
| delivery_date | DATE | Date of ad delivery |
| spend_usd | DECIMAL(10,2) | Spend recorded for that date |
| impressions | INT | Delivered impressions |
| Column | Type | Description |
|---|---|---|
| click_idPK | INT | Unique click event |
| campaign_id | INT | Campaign tied to the click |
| click_date | DATE | Date of click |
| funnel_stage | VARCHAR(30) | Funnel stage classification |
| click_source | VARCHAR(30) | Source surface for the click |
{"meta_campaigns":[[103,"Reels Prospecting US","TRAFFIC","ACTIVE"],[101,"Advantage+ Shopping Spring","SALES","ACTIVE"],[105,"Brand Awareness EMEA","AWARENESS","ACTIVE"],[104,"Lead Gen SMB","LEADS","PAUSED"],[102,"Click to Message LATAM","ENGAGEMENT","ACTIVE"],[106,"App Install Android","APP_PROMOTION",null],[107,"Creators Partnership Test","ENGAGEMENT","DRAFT"],[108,"WhatsApp Retargeting","SALES","ACTIVE"],["1","Holiday Prospecting US","OUTCOME_LEADS","LEARNING_LIMITED"],["2","Travel Intent EU",Output[["101","Advantage+ Shopping Spring","3","200.00","66.67"],["103","Reels Prospecting US","2","60.00","30.00"],["3","Auto Leads Midwest","0","-35.00","null"],["4","App Install Android","0","71.00","null"],["12","Catalog Sales UK","0","119.00","null"],["17","Creators Partnership Test","0","69.00","null"],["18","Creators Partnership Test","0","-15.00","null"],["102","Click to Message LATAM","0","90.00","null"],["105","Brand Awareness EMEA","0","30.00","null"],["106","App Install Android","0","-10.0