Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Unify CRM and Google Analytics View
00:00
5 left

Unify CRM and Google Analytics View

HardSQL · PostgreSQL

Problem

Business Context

You’re a data engineer at a fast-growing e-commerce retailer (~3M monthly active users) that sells direct-to-consumer. Marketing spends heavily on paid search and email, but the company can’t reliably connect anonymous web behavior (Google Analytics-style events) to known customers (CRM) once they purchase or log in. This leads to mis-attributed CAC/LTV, broken retargeting audiences, and inconsistent executive reporting.

Your warehouse receives:

  • CRM data with customer records and orders.
  • Web analytics events (GA-like) keyed by ga_client_id (cookie/device identifier).
  • A crosswalk table mapping ga_client_id to customer_id when a user logs in or completes checkout.

Because users can browse anonymously on multiple devices, a single customer may map to multiple ga_client_ids over time. You want a single customer view that rolls up web behavior and revenue.

Task

Write a SQL query that produces a unified customer-level dataset for January 2025.

Requirements

  1. Output one row per customer_id.
  2. Include:
    • customer_id, email
    • first_touch_channel: the channel of the customer’s earliest known web event (across all mapped GA client IDs)
    • sessions_jan_2025: distinct session count in Jan 2025
    • pageviews_jan_2025: total page_view events in Jan 2025
    • orders_jan_2025: number of orders placed in Jan 2025
    • revenue_jan_2025: sum of order totals in Jan 2025
  3. Only count web events that can be attributed to a customer via the mapping table.
  4. If a customer has no January web events, they should still appear if they have a January order (and web metrics should be 0 / NULL as appropriate).
  5. Use a deterministic rule for first touch: earliest event_ts; if ties, choose lexicographically smallest channel.

Schema

crm_customers
ColumnTypeDescription
customer_idPKINTCRM customer primary key
emailVARCHAR(255)Customer email address
created_atTIMESTAMPTimestamp when the customer record was created
crm_orders
ColumnTypeDescription
order_idPKBIGINTOrder primary key
customer_idINTCustomer placing the order (FK to crm_customers)
order_tsTIMESTAMPOrder timestamp
order_totalDECIMAL(10,2)Total charged amount for the order
ga_events
ColumnTypeDescription
event_idPKBIGINTEvent primary key
ga_client_idVARCHAR(64)GA client/cookie identifier
session_idVARCHAR(64)Session identifier
event_tsTIMESTAMPEvent timestamp
event_nameVARCHAR(50)Event type (e.g., page_view)
channelVARCHAR(50)Marketing channel attribution for the event
identity_map
ColumnTypeDescription
ga_client_idPKVARCHAR(64)GA client identifier (one side of the crosswalk)
customer_idINTMapped CRM customer_id
first_seen_tsTIMESTAMPFirst time this mapping was observed
Tablescrm_customerscrm_ordersga_eventsidentity_map
Interviewer

Your question is Unify CRM and Google Analytics View. Start with the requirements and the four tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.