KatInterview

Aggregate Event Signal Quality Across Advertiser Pixels

SQL & DataModel answer
MediumModel answerSQL & Datasqlaggregationjoins

Last updated

Compute pixel-level signal metrics aggregated to advertiser-day grain, then correlate data quality scores with conversion and revenue performance.

You are building analytics for a digital advertising platform's event tracking system. All timestamps use UTC. Your analysis covers the most recent 30 complete calendar days (excluding today).

Schema

advertisers

  • advertiser_id BIGINT
  • vertical STRING
  • created_at TIMESTAMP

pixels

  • pixel_id BIGINT
  • advertiser_id BIGINT
  • installed_at TIMESTAMP

pixel_signal_daily

  • ds DATE
  • pixel_id BIGINT
  • events_received BIGINT
  • valid_event_rate DOUBLE — fraction of received events passing validation (0.0 to 1.0)
  • match_rate DOUBLE — fraction of valid events successfully matched to ad traffic (0.0 to 1.0)

ad_performance_daily

  • ds DATE
  • advertiser_id BIGINT
  • impressions BIGINT
  • clicks BIGINT
  • spend_usd DOUBLE
  • attributed_conversions BIGINT
  • attributed_revenue_usd DOUBLE

Relationships

  • Each advertiser may have multiple pixels
  • Each pixel generates daily signal records
  • Each advertiser generates daily performance records

Part 1: Daily Advertiser Signal Summary

Write a query returning one row per advertiser per day with:

  • ds
  • advertiser_id
  • active_pixels — count of pixels that received ≥1 event that day
  • total_events_received
  • avg_valid_event_rate — event-weighted average of valid_event_rate across active pixels

Part 2: Quality Correlation Analysis

Investigate how signal data quality relates to advertising outcomes.

Definitions:

  • pixel_day_quality_score = valid_event_rate × match_rate
  • advertiser_day_quality = event-weighted average of pixel_day_quality_score across all active pixels for that advertiser-day
  • CVR = attributed_conversions / clicks (handle division by zero)
  • ROAS = attributed_revenue_usd / spend_usd (handle division by zero)

Quality buckets:

  • 'low' when advertiser_day_quality < 0.60
  • 'medium' when 0.60 ≤ advertiser_day_quality < 0.85
  • 'high' when advertiser_day_quality ≥ 0.85

Return one row per quality bucket across the 30-day window:

  • quality_bucket
  • advertiser_day_count
  • avg_quality_score
  • total_spend_usd
  • total_clicks
  • total_conversions
  • cvr
  • roas

Hints

Hint 1

Aggregate pixel-level data to advertiser-day grain before joining with performance data to avoid fan-out multiplication

Hint 2

Event-weighted averages require SUM(events × metric) / SUM(events), not AVG(metric)

Hint 3

Compute CVR and ROAS as ratios of bucket-level totals, not averages of daily ratios