Marketing Analyst
1. Scaffold the staging views
Prompt the agent:
In marketing-analyst/assets/, create three Bruin SQL assets for the staging layer. All should materialize as views (cheap, always fresh) with schema staging.
staging/google_ads.sql → staging.google_ads
- Source:
raw.google_ads_campaigns - Cast
dateto DATE, trim/dedupe on (campaign_id, date) usingQUALIFY ROW_NUMBER() OVER (PARTITION BY campaign_id, date ORDER BY date DESC) = 1 - Convert
cost_micros→cost_usd= cost_micros / 1e6 - Derived metrics per row:
ctr = clicks / NULLIF(impressions, 0),cvr = conversions / NULLIF(clicks, 0),cpc_usd = cost_usd / NULLIF(clicks, 0) - Keep: campaign_id, campaign_name, date, impressions, clicks, conversions, conversion_value, cost_usd, ctr, cvr, cpc_usd
staging/klaviyo.sql → staging.klaviyo
- Source:
raw.klaviyo_campaigns - Cast
send_timeto TIMESTAMP and derivesend_date = send_time::DATE - Dedupe on campaign_id (keep the most recent snapshot)
- Derived metrics:
open_rate = opens / NULLIF(recipients, 0),click_rate = clicks / NULLIF(recipients, 0),revenue_per_recipient = revenue / NULLIF(recipients, 0) - Add a comment noting that
opensare unreliable on iOS; preferclicksorrevenuefor engagement signals - Keep: campaign_id, send_time, send_date, recipients, opens, clicks, unsubscribes, revenue, open_rate, click_rate, revenue_per_recipient
staging/ga4.sql → staging.ga4
- Source:
raw.ga4_traffic - Cast
dateto DATE - Dedupe on (date, sessionSource, sessionMedium)
- Classify
channelfrom medium:cpc→ 'Paid Search',organic→ 'Organic',email→ 'Email',(none)/direct→ 'Direct', everything else → 'Other' - Derived:
cvr = conversions / NULLIF(sessions, 0) - Keep: date, sessionSource, sessionMedium, channel, sessions, totalUsers, conversions, purchaseRevenue, cvr
For each asset, add a top-level description:, column descriptions, and at least one quality check (e.g. not_null on the grain columns, unique on the dedupe key).
Show me the SQL for each asset before writing the files. Don't run anything yet - I'll approve first.
Read each SQL file the agent produces. Look specifically for the unit conversion (cost_micros → cost_usd), the dedup logic, and the channel classification. If anything looks off, push back - it's cheaper to correct here than downstream.