Build a marketing campaign performance analytics model from scratch
harbor run -t snowflake-labs/dbt-campaign-performanceharbor download snowflake-labs/dbt-campaign-performanceCreate a new dbt model that analyzes marketing campaign performance by tracking email engagement, customer conversions, revenue attribution, and peer comparisons across campaign channels.
/app/dbt_models_duckdb/models/marts/marketing/rpt_campaign_performance.sql/app/dbt_models_snowflake/models/marts/marketing/rpt_campaign_performance.sqlThis task supports both DuckDB and Snowflake. Run echo $DB_TYPE in a shell BEFORE you write any code or spawn any subagents — the live env determines which backend the verifier runs against. Do NOT assume a default from this prose. Both /app/dbt_models_duckdb/ and /app/dbt_models_snowflake/ exist on disk; the verifier only checks the project matching the live $DB_TYPE.
DB_TYPE=duckdb$DUCKDB_PATH (default: /app/database/retail.duckdb)DB_TYPE=snowflakeSNOWFLAKE_ACCOUNTSNOWFLAKE_USERSNOWFLAKE_PASSWORDSNOWFLAKE_DATABASE - The clone database to useSNOWFLAKE_SCHEMASNOWFLAKE_WAREHOUSESNOWFLAKE_ROLE (optional)Note: For Snowflake, the entrypoint automatically creates a clone database and sets SNOWFLAKE_DATABASE. The clone is destroyed when the task completes.
You must configure dbt to connect to the database:
profiles.yml in the dbt project directory with profile name retail_dw_masterDBT_PROFILES_DIR environment variable to the directory containing profiles.ymlConfigure with type: duckdb and the database path from $DUCKDB_PATH.
Configure with type: snowflake using password authentication:
schema: to $SNOWFLAKE_SCHEMA — do NOT leave it blank. A blank or omitted schema makes Snowflake silently default to PUBLIC, so your models get built in the wrong schema and the verifier cannot find them.Use these tables:
stg_marketing__campaigns - Campaign master data (campaign_id, campaign_name, channel, start_date, end_date)stg_marketing__email_events - Email interactions (event_id, customer_id, campaign_id, event_type, event_at)int_sales__orders_enriched - Orders with customer info
ORDER_ID (uppercase!), customer_id, ordered_at, grand_total, status'CANCELLED' and abbreviation 'C'The event_type column contains: 'SENT', 'OPENED', 'CLICKED', 'CONVERTED'
| Metric | Description |
|---|---|
| emails_sent | Count of SENT events |
| emails_opened | Count of OPENED events |
| emails_clicked | Count of CLICKED events |
| conversions | Count of CONVERTED events |
| unique_recipients | Distinct customers with any email event |
| open_rate | Proportion opened (0-1) |
| click_rate | Proportion clicked of opened (0-1) |
| conversion_rate | Proportion converted of recipients (0-1) |
| attributed_revenue | Revenue from orders within 30 days after conversion |
| revenue_per_conversion | Average revenue per conversion |
Classify channels into categories based on the channel name:
| Category | Description |
|---|---|
| PAID | Paid advertising channels |
| OWNED | Owned media channels |
| EARNED | Earned/organic channels |
| OTHER | Channels not matching above |
Infer the category from keywords in the channel name.
Compare each campaign against others in the SAME channel_category (not channel!):
| Metric | Description |
|---|---|
| category_conversion_rank | Rank by conversion_rate within channel_category (1 = best, no gaps) |
| category_campaign_count | Total campaigns in same channel_category |
| above_category_avg_conversion | 1 if above channel_category average, 0 otherwise |
| category_revenue_percentile | Revenue percentile within channel_category (0-1) |
| Metric | Description |
|---|---|
| performance_index | Weighted composite (0-100) reflecting overall campaign effectiveness |
Formula: (open_rate * 0.25 + click_rate * 0.25 + conversion_rate * 0.30 + revenue_efficiency * 0.20) * 100
Where revenue_efficiency = MIN(attributed_revenue / campaign_days / 1000) max to 1.
campaign_tier - Waterfall classification (check conditions in order, first match wins):
| Tier | Condition |
|---|---|
| ineffective | conversions = 0 |
| underperforming | below category avg conversion AND click_rate < 0.20 |
| developing | below category avg conversion OR click_rate < 0.40 |
| top_performer | performance percentile >= 0.80 in category AND cvr > 0.10 |
| effective | above category avg conversion AND performance_index >= 50 |
| developing | default |
| Column | Type |
|---|---|
| campaign_id | varchar |
| campaign_name | varchar |
| channel | varchar |
| channel_category | varchar |
| emails_sent | integer |
| emails_opened | integer |
| emails_clicked | integer |
| conversions | integer |
| unique_recipients | integer |
| open_rate | decimal |
| click_rate | decimal |
| conversion_rate | decimal |
| attributed_revenue | decimal |
| revenue_per_conversion | decimal |
| category_conversion_rank | integer |
| category_campaign_count | integer |
| above_category_avg_conversion | integer |
| category_revenue_percentile | decimal |
| performance_index | decimal |
| campaign_tier | varchar |
percent_rank() and dense_rank() accordingly