Build a data clean room experiment: partner matching, governance, and lift measurement.
- User
Build a data clean room experiment: partner matching, governance, and lift measurement.
- Assistant
Build a data clean room experiment: partner matching, governance, and lift measurement.
As Sherlock, I'll guide you through designing and implementing a privacy-safe data clean room (DCR) experiment to measure advertising lift. This setup allows two partners (e.g., Advertiser A with ad exposure data and Publisher P with conversion data) to collaborate without sharing raw PII.
We'll use Google Cloud's Data Clean Rooms (serverless, easy to spin up) as the example platform—it's compliant with GDPR/CCPA and supports SQL-based queries. Alternatives: AWS Clean Rooms, Snowflake Clean Rooms, or self-hosted with Apache Spark + PySyft.
| Party | Sample Data | Prep Steps |
|---|---|---|
| Advertiser A | User IDs (email/phone), timestamps, exposure flag (1=exposed), campaign ID | Hash IDs: SHA256(lower(email)) or SHA256(phone + salt). Aggregate to cohorts (e.g., day-level). |
| Publisher P | User IDs, timestamps, conversion event (e.g., purchase value) | Same hashing. Aggregate conversions by cohort. |
[Advertiser A BigQuery] --hashed--> [DCR Membership A]
|
[Publisher P BigQuery] --hashed--> [DCR Membership P] <-- SQL Queries (Lift Calc) --> [Results Table]
|
[Governance Policies]
Match overlapping users securely using probabilistic/hashed IDs.
Create DCR Collaboration:
# Google Cloud Console or gcloud CLI
gcloud cleanrooms collaborations create collab-lift-experiment \
--requester=my-advertiser@domain.com \
--memberships-config='[{"table":"projects/my-proj/datasets/dcr/tables/exposure_data"}]'
# Publisher joins via invite link.
Upload Hashed Data (BigQuery Tables):
| Table | Columns | Example Row |
|---|---|---|
exposure_data (A) | hashed_user_id, date, exposed (0/1), campaign_id | abc123..., 2023-10-01, 1, camp1 |
conversion_data (P) | hashed_user_id, date, conversion_count, revenue | abc123..., 2023-10-01, 1, 50.00 |
Matching Query (Run in DCR SQL Editor):
-- Compute overlap (output: scalar count, no IDs)
SELECT
COUNT(DISTINCT e.hashed_user_id) as matched_users,
COUNT(DISTINCT e.hashed_user_id) * 100.0 / COUNT(DISTINCT c.hashed_user_id) as match_rate
FROM `advertiser.membership.exposure_data` e
INNER JOIN `publisher.membership.conversion_data` c
ON e.hashed_user_id = c.hashed_user_id
WHERE e.date = c.date; -- Time-aligned
APPROX_COUNT_DISTINCT).Enforce "data doesn't leave the room" with built-in controls.
| Control | Description | DCR Config |
|---|---|---|
| Access | Role-based: Viewer (queries only), no exports. | IAM: roles/cleanrooms.viewer for partners. |
| Query Rules | Block PII/select *, limit rows <1M, no JOINs outside date range. | Custom rules: DENY SELECT *; REQUIRE AGGREGATE; |
| TTL/Data Retention | Auto-delete after 30 days. | Membership config: --ttl-days=30 |
| Audit Logs | Track all queries. | Enable Cloud Audit Logs. |
| Approval Workflow | Publisher approves queries before run. | Collaboration settings: required-query-validation=true |
| Compliance | DP-ε=1.0 noise, k-anonymity k=10. | Built-in: WITH DP_NOISE(eps=1.0) |
# Python SDK for governance
from google.cloud import cleanrooms_v1
client = cleanrooms_v1.CleanroomsServiceClient()
policy = cleanrooms_v1.RequiredQueryOptions(
requested_tables=["exposure_*"], # Prefix filter
disallowed_resources=["SELECT hashed_user_id"] # Block raw IDs
)
# Attach to collaboration
Pro Tip: Start with "sandbox mode" (mock data) for testing.
Run a geo-holdout experiment or user-level randomization inside the DCR.
-- Lift: Exposed vs. Control, time-aligned (lookback 7 days)
WITH matched AS (
SELECT
e.hashed_user_id,
e.date,
e.exposed,
SUM(c.conversion_count) as convs,
SUM(c.revenue) as rev
FROM `advertiser.membership.exposure_data` e
INNER JOIN `publisher.membership.conversion_data` c
ON e.hashed_user_id = c.hashed_user_id
WHERE e.date BETWEEN '2023-10-01' AND '2023-10-07'
GROUP BY 1,2,3 -- Anonymized aggregates
),
agg_metrics AS (
SELECT
exposed,
COUNT(DISTINCT hashed_user_id) as users,
SUM(convs) as total_convs,
SUM(rev) as total_rev,
SUM(convs)*1.0 / COUNT(DISTINCT hashed_user_id) as cvr
FROM matched
GROUP BY exposed
)
SELECT
exposed,
users,
total_convs,
cvr,
(cvr - LAG(cvr) OVER (ORDER BY exposed)) / LAG(cvr) OVER (ORDER BY exposed) * 100 as lift_pct
FROM agg_metrics;
Sample Output:
| exposed | users | total_convs | cvr | lift_pct |
|---|---|---|---|---|
| 0 | 20k | 400 | 2.0% | - |
| 1 | 80k | 1,760 | 2.2% | +10% |
Stats Test (Add chi-squared p-value):
-- Use APPROX_QUANTILES or export to R/Python for t-test
SELECT chi2_test([convs_exposed, convs_control, non_convs_exposed, non_convs_control]);
-- Match on demographics (hashed cohorts)
SELECT * FROM exposure e MATCH (conversion c USING propensity_score ON demographics_bucket);
Launch Checklist:
This is production-ready—fork it in your GCP console. Questions on tweaks (e.g., Snowflake migration)? Ping me! 🕵️♂️