Build coupon effectiveness analytics with multi-table joins, conditional aggregations, NULL handling, and promotion performance metrics
harbor run -t snowflake-labs/dbt-coupon-effectivenessharbor download snowflake-labs/dbt-coupon-effectivenessBuild a comprehensive coupon and promotion effectiveness analytics suite that measures redemption rates, discount impact, revenue lift, and customer acquisition metrics. This includes analyzing promotion performance, comparing discount strategies, tracking temporal trends, and identifying high-value promotions.
This 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./app/dbt_transforms/app/dbt_models_snowflakeThe staging layer provides:
stg_pos__promotions: promotion_id, promotion_code, promotion_name, promotion_type, discount_type, discount_value, min_purchase, max_discount, start_date, end_date, is_activestg_pos__coupons: coupon_id, coupon_code, promotion_id, usage_limit, usage_count, is_active, expires_atstg_pos__coupon_usage: redemption_id, coupon_id, order_id, customer_id, discount_amount, redeemed_atstg_orders__orders: order_id, customer_id, ordered_at, grand_total, status, test_order_flag, is_first_orderOnly include orders that are:
Only include redemptions where:
Create these dbt models:
Intermediate models in models/intermediate/:
int_coupon_redemptions: Join coupon usage with coupons, promotions, and orders to create a unified redemption view with all relevant details.Mart models in models/marts/analytics/:
coupon_effectiveness: Promotion-level effectiveness metrics (table)coupon_summary: Summary by promotion type and discount type (table)coupon_trends: Monthly redemption trends per promotion (table)For each promotion, calculate:
Redemption Metrics:
Financial Metrics:
Usage Metrics:
Customer Acquisition:
Customer Concentration Risk:
Analyze how dependent a promotion's success is on a small number of customers:
Performance Tier based on total_order_value:
Efficiency Rating based on revenue_per_discount_dollar:
Customer Focus based on first_time_pct:
For each promotion, calculate using ordered_at (the order timestamp) as the date source:
Activity Status:
Measure whether a promotion's effectiveness changes over its lifecycle by comparing the first half of redemptions to the second half:
ordered_at (use deterministic ordering: ordered_at, redemption_id)Note: For promotions with only 1 redemption, set early/late counts to 1/0, early metrics to the single redemption values, late metrics to NULL, order_value_decay_pct to NULL, and decay_classification to 'Stable'.
| Column | Type | Description |
|---|---|---|
| promotion_id | string | Promotion identifier |
| promotion_name | string | Promotion name |
| promotion_type | string | Type of promotion |
| discount_type | string | Type of discount (percentage, fixed, etc.) |
| discount_value | decimal | Configured discount value |
| total_coupons | integer | Coupons under this promotion |
| total_redemptions | integer | Total times redeemed |
| unique_customers | integer | Distinct customers |
| unique_orders | integer | Distinct orders |
| repeat_redeemer_count | integer | Customers who redeemed 2+ times |
| repeat_redeemer_pct | decimal(1) | Percent repeat redeemers |
| total_discount_given | decimal(2) | Sum of discounts |
| total_order_value | decimal(2) | Sum of order values |
| total_order_value_before_discount | decimal(2) | Order value + discount |
| avg_discount_per_redemption | decimal(2) | Average discount |
| avg_order_value | decimal(2) | Average order value |
| avg_order_value_before_discount | decimal(2) | Avg order before discount |
| discount_to_revenue_ratio | decimal(1) | Discount as % of revenue |
| revenue_per_discount_dollar | decimal(2) | Revenue generated per $1 discount |
| total_usage_limit | integer | Sum of coupon limits (NULL if unlimited) |
| redemption_rate | decimal(1) | Percent of limit used (NULL if unlimited) |
| avg_redemptions_per_coupon | decimal(2) | Avg redemptions per coupon |
| avg_redemptions_per_customer | decimal(2) | Avg redemptions per customer |
| first_time_redemptions | integer | Redemptions from new customers |
| repeat_redemptions | integer | Redemptions from repeat customers |
| first_time_pct | decimal(1) | Percent from first-time buyers |
| new_customer_acquisition_cost | decimal(2) | Cost per new customer (NULL if none) |
| first_redemption_date | date | First redemption date |
| last_redemption_date | date | Last redemption date |
| days_active | integer | Days between first and last (minimum 1) |
| avg_daily_redemptions | decimal(2) | Average daily redemptions |
| activity_status | string | Active/Dormant/Inactive |
| performance_tier | string | High/Medium/Low Performer |
| efficiency_rating | string | Excellent/Good/Average/Poor |
| customer_focus | string | Acquisition/Retention/Balanced |
| revenue_rank | integer | Rank by total_order_value (1 = highest) |
| top_customer_redemptions | integer | Redemptions from top 10% customers |
| top_customer_pct | decimal(1) | Percent of redemptions from top 10% |
| single_use_customer_count | integer | Customers who redeemed once |
| single_use_customer_pct | decimal(1) | Percent single-use customers |
| concentration_risk | string | High/Medium/Low |
| early_redemption_count | integer | Redemptions in first half |
| late_redemption_count | integer | Redemptions in second half |
| early_avg_order_value | decimal(2) | Avg order value in first half |
| late_avg_order_value | decimal(2) | Avg order value in second half (NULL if 1 redemption) |
| early_avg_discount | decimal(2) | Avg discount in first half |
| late_avg_discount | decimal(2) | Avg discount in second half (NULL if 1 redemption) |
| order_value_decay_pct | decimal(1) | Percent decay in order value (NULL if 1 redemption) |
| decay_classification | string | Improving/Stable/Declining/Collapsing |
Order by revenue_rank ASC.
Summary aggregated by promotion_type and discount_type.
| Column | Type | Description |
|---|---|---|
| promotion_type | string | Type of promotion |
| discount_type | string | Type of discount |
| promotion_count | integer | Number of promotions |
| total_redemptions | integer | Total redemptions |
| unique_customers | integer | Distinct customers |
| total_discount_given | decimal(2) | Sum of discounts |
| total_order_value | decimal(2) | Sum of order values |
| avg_discount_per_redemption | decimal(2) | Average discount |
| avg_order_value | decimal(2) | Average order value |
| revenue_per_discount_dollar | decimal(2) | Revenue per $1 discount |
| first_time_pct | decimal(1) | Percent from first-time buyers |
| pct_of_total_redemptions | decimal(1) | Percent of all redemptions |
| pct_of_total_revenue | decimal(1) | Percent of all coupon revenue |
| high_performer_count | integer | Count of high performers |
| excellent_efficiency_count | integer | Count with excellent efficiency |
Order by total_order_value DESC.
Monthly breakdown of redemption patterns per promotion. Group by month using the order date (ordered_at), formatted as 'YYYY-MM'.
Weekday/Weekend Analysis: For each month, also calculate weekday vs weekend performance:
| Column | Type | Description |
|---|---|---|
| promotion_id | string | Promotion identifier |
| promotion_name | string | Promotion name |
| redemption_month | string | Month in format "YYYY-MM" (from ordered_at) |
| monthly_redemptions | integer | Redemptions in this month |
| monthly_discount | decimal(2) | Discount given in this month |
| monthly_order_value | decimal(2) | Order value in this month |
| monthly_unique_customers | integer | Unique customers in month |
| monthly_first_time_count | integer | First-time buyer redemptions |
| cumulative_redemptions | integer | Running total of redemptions |
| cumulative_discount | decimal(2) | Running total of discount |
| cumulative_order_value | decimal(2) | Running total of order value |
| month_rank | integer | Rank of this month for this promotion (1 = first) |
| pct_of_total_redemptions | decimal(1) | This month's % of promotion total |
| monthly_revenue_per_discount | decimal(2) | Monthly revenue per $1 discount |
| weekday_redemptions | integer | Mon-Fri redemptions this month |
| weekend_redemptions | integer | Sat-Sun redemptions this month |
| weekday_order_value | decimal(2) | Order value from weekday redemptions |
| weekend_order_value | decimal(2) | Order value from weekend redemptions |
| weekday_avg_order_value | decimal(2) | Avg order value on weekdays (NULL if 0 weekday redemptions) |
| weekend_avg_order_value | decimal(2) | Avg order value on weekends (NULL if 0 weekend redemptions) |
| weekend_lift_pct | decimal(1) | ((weekend_avg - weekday_avg) / weekday_avg) x 100 (NULL if either is NULL or weekday_avg is 0) |
Order by promotion_id, redemption_month.
coupon_effectiveness: tablecoupon_summary: tablecoupon_trends: tablecd /app/dbt_transforms # or /app/dbt_models_snowflake for Snowflake
dbt run --select +coupon_effectiveness +coupon_summary +coupon_trends