Prompt
How do I set up a targeting API for audience onboarding with privacy-safe identity matching?
Latest observation
To set up a targeting API for audience onboarding with privacy-safe identity matching, design it as a system that accepts audience data from a client, matches it against your identity graph using protected identifiers, and returns activation-ready audience keys or segments without exposing raw PII.
1) Define the onboarding flow
A typical flow looks like this:
-
Client uploads audience
The advertiser or data provider sends a list of users, usually with identifiers like:- phone number
- postal address
- mobile ad IDs
- CRM IDs
-
Normalize and protect identifiers Before matching:
- normalize inputs
- hash or tokenize sensitive fields
- remove raw PII as soon as possible
-
Match against your identity graph Your system checks:
- exact hashed matches
- deterministic linkages
- allowed probabilistic matches, if policy permits
-
Return onboarding results Return only:
- matched internal IDs
- segment membership
- activation tokens
- counts and status summaries
-
Activate to destinations Push matched audiences to ad platforms or downstream endpoints through approved connectors.
2) Core privacy-safe identity design
Use these principles:
A. Minimize raw PII
- Accept PII only at ingestion boundary.
- Immediately normalize and hash/tokenize.
- Do not store raw PII unless absolutely necessary.
B. Deterministic matching first
Prefer strong identifiers:
- SHA-256 hashed email/phone
- normalized address
- first-party user IDs mapped through consented sources
C. Use a trusted identity graph
Store relationships like:
- hashed email ↔ internal user ID
- device ID ↔ user ID
- customer ID ↔ household ID
D. Enforce consent and purpose limitation
For each record, check:
- user consent status
- region/jurisdiction rules
- permitted use for targeting
- retention policy
E. Return only privacy-safe outputs
Never return:
- raw PII
- full joined identity graph
- unnecessary internal identifiers
3) API architecture
A practical setup:
Ingestion API
Used by partners to submit audiences.
Example endpoint
POST /audiences/importPOST /audiences/{id}/members
Payload
{
"audience_name": "Spring Promo Buyers",
"source": "crm_upload",
"identifiers": [
{
"type": "email",
"value": "user@example.com",
"hashing": "sha256",
"normalized": true
}
],
"consent": {
"status": "granted",
"lawful_basis": "consent"
}
}
Matching service
Internal service that:
- normalizes fields
- hashes if needed
- searches identity store
- scores matches
- applies policy checks
Activation API
Used to publish matched audience to destinations.
Example endpoint
POST /audiences/{id}/activate
Status API
For async processing:
GET /jobs/{job_id}GET /audiences/{id}/summary
4) Identity matching methods
Deterministic matching
Best for privacy-safe onboarding.
Examples:
- exact hashed email match
- exact hashed phone match
- CRM ID mapped to known customer ID
Recommended rules:
- use the same normalization standard across all partners
- specify hashing algorithm and salt policy
- compare only normalized forms
Probabilistic matching
If used, make it optional and tightly controlled:
- only with explicit consent/policy approval
- use aggregate confidence thresholds
- avoid exposing match reasons externally
For privacy-sensitive onboarding, deterministic is usually preferred.
5) Normalization standards
Consistency is crucial. Define canonical formatting for:
- emails: lowercase, trim spaces
- phone numbers: E.164 format
- addresses: standardized postal normalization
- names: trim, remove extra whitespace, locale-aware rules
Example:
User@Example.com→user@example.com+1 (555) 123-4567→+15551234567
Then hash the normalized value.
6) Security controls
Implement:
- TLS in transit
- encryption at rest
- strict IAM / least privilege
- audit logging
- rate limiting
- request signing or mTLS for partners
- key management via KMS/HSM
- data retention controls and deletion workflows
Also:
- separate partner-specific namespaces
- isolate audiences by tenant
- prevent cross-tenant leakage
7) Recommended API behavior
Input validation
Reject:
- malformed identifiers
- unsupported identifier types
- records missing required consent fields
Async processing
For large uploads:
- accept job
- return
job_id - process in background
- provide status updates
Idempotency
Support idempotency keys so retries don’t duplicate records.
Partial success
Return counts like:
- received
- normalized
- matched
- rejected
- suppressed due to consent
8) Example onboarding response
{
"audience_id": "aud_12345",
"job_id": "job_98765",
"status": "processing",
"received": 100000,
"accepted": 98210,
"rejected": 1790,
"matched": 72155,
"suppressed": 4021
}
9) Privacy and compliance checklist
Make sure the design supports:
- consent management
- GDPR/CCPA/CPRA compliance
- data subject deletion requests
- purpose limitation
- retention limits
- vendor DPAs
- cross-border transfer controls
- logging without sensitive payloads
10) Practical implementation pattern
A strong pattern is:
- API gateway for auth, quotas, logging
- Normalization service for identifier standardization
- Hashing/tokenization service
- Identity graph store
- Policy engine for consent/region rules
- Audience store
- Activation connectors
- Audit and monitoring layer
11) Suggested endpoint set
Minimal set:
POST /audiencesPOST /audiences/{audience_id}/members:importGET /audiences/{audience_id}GET /jobs/{job_id}POST /audiences/{audience_id}/activateDELETE /audiences/{audience_id}
12) Best practices summary
- Normalize before matching
- Hash or tokenize identifiers immediately
- Match deterministically when possible
- Enforce consent and purpose checks
- Return only privacy-safe outputs
- Make onboarding asynchronous and auditable
- Separate tenants and destinations
- Minimize retention of raw identifiers
If you want, I can also provide:
- a sample OpenAPI spec,
- a reference architecture diagram, or
- a code example for the matching pipeline.