Skip to content

Maayan via Elementary: fix(marketing): normalize ad cost units in marketing_ads union - #1002

Open
elementary-data-demo[bot] wants to merge 1 commit into
masterfrom
elementary-fix-marketing-ads-cost-unit-normalization
Open

Maayan via Elementary: fix(marketing): normalize ad cost units in marketing_ads union#1002
elementary-data-demo[bot] wants to merge 1 commit into
masterfrom
elementary-fix-marketing-ads-cost-unit-normalization

Conversation

@elementary-data-demo

Copy link
Copy Markdown

Summary

Fixes the RETURN_ON_ADVERTISING_SPEND anomaly on cpa_and_roas (average collapsed from ~75.45 to 0.300, a ~250x drop; incident 60c571d2).

Root cause

ROAS in cpa_and_roas is 100.0 * attribution_revenue / total_spend. The revenue (numerator) branch — orderscustomer_conversionsattribution_touches.linear_revenue — is clean. The spend (denominator) branch traces back through ads_spendmarketing_ads, which does a raw UNION ALL of three ad-platform sources (stg_google_ads, stg_facebook_ads, stg_instagram_ads) with no cost normalization — it selected * from each and summed cost directly.

One source began reporting cost in cents instead of dollars, inflating its spend ~100x. Blended across the union this drove total_spend far above its baseline and crushed ROAS. The mismatch is invisible to freshness and volume tests (row counts and timestamps look normal), which is why it surfaced only as a column-value anomaly.

Fix

  • Select cost explicitly at each source branch (instead of select *) so the unit is enforced at the union boundary.
  • Apply the project's existing cents_to_dollars() macro to the cents-denominated feed so all three sources are in dollars before the union — matching the convention already used in real_time_orders for monetary fields.

Reviewer action required

I applied the conversion to stg_instagram_ads as the feed reporting in cents. Please confirm this is the correct source — I could not query live warehouse values to empirically verify which platform switched units. If it is a different platform (Google/Facebook), move the cents_to_dollars('cost') wrapper to the correct branch.

Prevention

Consider adding a per-source cost range/anomaly test on the stg_*_ads sources so a future unit shift is caught at the boundary rather than downstream in ROAS.

Created by: maayan+172@elementary-data.com

One ad source began reporting cost in cents, inflating total_spend ~100x
and collapsing RETURN_ON_ADVERTISING_SPEND in cpa_and_roas. Convert the
cents-denominated feed to dollars via cents_to_dollars and select cost
explicitly so units are enforced at the union boundary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants