Bruin AI Step 4 of 6

Marketing Analyst

1. Scaffold the staging views

Prompt the agent:

AI Prompt

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.sqlstaging.google_ads

  • Source: raw.google_ads_campaigns
  • Cast date to DATE, trim/dedupe on (campaign_id, date) using QUALIFY ROW_NUMBER() OVER (PARTITION BY campaign_id, date ORDER BY date DESC) = 1
  • Convert cost_microscost_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.sqlstaging.klaviyo

  • Source: raw.klaviyo_campaigns
  • Cast send_time to TIMESTAMP and derive send_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 opens are unreliable on iOS; prefer clicks or revenue for engagement signals
  • Keep: campaign_id, send_time, send_date, recipients, opens, clicks, unsubscribes, revenue, open_rate, click_rate, revenue_per_recipient

staging/ga4.sqlstaging.ga4

  • Source: raw.ga4_traffic
  • Cast date to DATE
  • Dedupe on (date, sessionSource, sessionMedium)
  • Classify channel from 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_microscost_usd), the dedup logic, and the channel classification. If anything looks off, push back - it's cheaper to correct here than downstream.

Sign up to our newsletter

Practical updates on open-source data pipelines, AI analysts, governance, and what we are shipping at Bruin.