Do Not Sell/Share Compliance Toolkit
This toolkit provides a modular, production-ready framework for complying with CCPA/CPRA "Do Not Sell or Share My Personal Information" (DNSMPI) requirements. It focuses on detecting opt-out signals (e.g., Global Privacy Control - GPC), processing flows, handling opt-outs persistently, and logging for audits. Designed for web applications (client/server-side), it's extensible for mobile/apps.
Key Assumptions & Best Practices:
- Honor opt-outs for 12 months (renewable).
- Apply globally across domains/services (e.g., via shared cookie domain or backend flag).
- Never log PII (e.g., emails, IDs) in opt-out logs.
- Test with tools like GPC Chrome Extension or PrivacyTests.io.
- Integrate with analytics (e.g., GA4 opt-out) and ad tech (e.g., block sale/share pixels).
- Legal note: Consult counsel; this is technical guidance only.
1. Signals Detection
Detect opt-out signals automatically. Prioritize GPC (Sec-GPC: 1), fallback to US Privacy String (UPS), manual links, or cookies.
Client-Side (JavaScript)
// signals.js - Detect and emit signals
export function detectSignals() {
const signals = {
gpc: navigator?.doNotTrack === '1' || (navigator?.globalPrivacyControl ?? false), // GPC boolean API (Chrome 148+)
secGpc: getHeader('Sec-GPC') === '1', // Simulated for client; use service worker for real headers
usPrivacy: getCookie('usprivacy') || getQueryParam('usprivacy'), // e.g., '1NNN' (1=CA, N=opt-out status)
manualOptOut: getCookie('dnspmpi_optout') === '1',
};
// Emit event for flows
window.dispatchEvent(new CustomEvent('dnsmpi-signal', { detail: signals }));
return signals;
}
// Helpers
function getCookie(name) {
const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
return match ? match[2] : null;
}
function getQueryParam(name) {
return new URLSearchParams(window.location.search).get(name);
}
function getHeader(name) { /* Use service worker or fetch headers */ }
Server-Side (Node.js/Express Example)
// server-signals.js
app.use((req, res, next) => {
const signals = {
gpc: req.get('Sec-GPC') === '1',
usPrivacy: req.get('Uspr') || req.cookies.usprivacy, // UPS header/cookie
optOutCookie: req.cookies.dnspmpi_optout === '1',
};
req.dnsmpiSignals = signals;
next();
});
Supported Signals:
| Signal | Source | Priority | Description |
|---|
GPC (Sec-GPC: 1) | Browser header | Highest | Universal opt-out (GPC.org standard). |
globalPrivacyControl=true | Navigator API | High | Emerging browser API. |
usprivacy=1--- (last - = opt-out) | Cookie/Header | Medium | IAB TCF/US standard. |
?dnspmpi=1 or /opt-out | Query/URL | Low | Manual link. |
__dnspmpi=1 | Cookie | Fallback | Your persistent flag. |
2. Compliance Flows
Step-by-step workflows. Use state machine for robustness.
Flow Diagram (Mermaid)
flowchart TD
A[Request Incoming] --> B{Detect Signals?}
B -->|No| C[Proceed Normally<br/>(Allow Sell/Share)]
B -->|Yes| D[Set Opt-Out Flag<br/>(12mo Cookie + Backend)]
D --> E[Apply Restrictions<br/>- Block ad pixels<br/>- Anonymize analytics<br/>- No data sale/share]
E --> F[Redirect/Respond<br/>(e.g., /opt-out success)]
C --> G[Log: No Action]
F --> H[Log: Opt-Out Applied]
Client-Side Flow
// flows-client.js
detectSignals(); // On load/pageview
window.addEventListener('dnsmpi-signal', (e) => {
const { gpc, usPrivacy, manualOptOut } = e.detail;
if (gpc || usPrivacy?.endsWith('N') || manualOptOut) {
setOptOut(true); // Handle opt-out
// Block trackers immediately
blockAnalytics();
}
});
function setOptOut(value) {
document.cookie = `__dnspmpi=1; path=/; domain=.example.com; max-age=${31_557_600 * 12}; SameSite=Lax; Secure`;
localStorage.setItem('dnspmpi', '1'); // Fallback
}
function blockAnalytics() {
window['ga-disable-UA-XXXXX-X'] = true; // Google Analytics
// Add: Facebook Pixel, etc.
}
Server-Side Flow (Node.js)
// flows-server.js
app.get('/opt-out', (req, res) => {
const signals = req.dnsmpiSignals;
if (signals.gpc || signals.optOutCookie || req.query.dnspmpi) {
setOptOut(req, res, true);
logOptOut(req, 'applied');
res.send('Opt-out successful. Honored for 12 months.');
} else {
res.redirect('/');
}
});
function setOptOut(req, res, value) {
res.cookie('dnspmpi_optout', value ? '1' : '0', {
maxAge: 31_557_600 * 12 * 1000, // 12mo
path: '/',
domain: '.example.com', // Shared domain
secure: true,
sameSite: 'lax',
});
// Backend: Set user flag in DB (anon ID only)
setUserFlag(req.anonId, 'dnspmpi_optout', true);
}
// Middleware: Enforce on every req
app.use((req, res, next) => {
const isOptOut = req.dnsmpiSignals?.optOutCookie || getUserFlag(req.anonId);
if (isOptOut) {
// Block sale/share: e.g., no ad serving, anonymize
req.noSellShare = true;
}
next();
});
Toggle Flow: Add /opt-back-in to unset (required for "Do Not Sell").
3. Opt-Out Handling
- Persistence: Cookie (12mo) + backend flag (tied to hashed/anon user ID).
- Propagation:
- Use
.example.com domain cookie.
- Sync to CDNs/databases via API (e.g., post to
/api/optout).
- Vendors: Send USP string (
1---) to ad partners.
- Edge Cases:
| Case | Action |
|---|
| Incognito | Honor per-session (localStorage). |
| Re-ident? | Use anon IDs only. |
| Opt-back-in | Unset flag after confirmation. |
| Children | Default opt-out if COPPA. |
- Confirmation: Always respond with "Opt-out applied" page (no tracking).
4. Logging System
Audit-ready, GDPR/CCPA compliant. No PII. Use structured logs (e.g., JSON to ELK/CloudWatch).
Log Schema
{
"timestamp": "2024-01-01T12:00:00Z",
"event": "dnsmpi_optout", // or "dnsmpi_signal_detected", "dnsmpi_enforced"
"action": "applied", // applied, ignored, toggled
"signals": ["gpc", "usprivacy"], // Array
"userAgentHash": "sha256_hash_of_ua", // Anonymized
"ipHash": "sha256_hash_of_ip", // Anonymized (last octet zeroed)
"sessionId": "anon_session_uuid",
"outcome": "success",
"ttl": "2025-01-01" // Opt-out expiry
}
Implementation (Node.js Winston Example)
// logger.js
const winston = require('winston');
const logger = winston.createLogger({ /* CloudWatch/S3 */ });
function logOptOut(req, action) {
const log = {
timestamp: new Date().toISOString(),
event: 'dnsmpi_optout',
action,
signals: Object.keys(req.dnsmpiSignals).filter(k => req.dnsmpiSignals[k]),
userAgentHash: hash(req.get('User-Agent')),
ipHash: hash(req.ip.replace(/\.\d+$/, '.0')), // Anonymize
sessionId: req.sessionID,
};
logger.info('DNSMPI', log);
}
function hash(str) {
return require('crypto').createHash('sha256').update(str).digest('hex').slice(0, 16);
}
Retention: 12+ months for audits. Queryable by date/signal.
Integration Checklist
Deploy this as NPM package (npm i dnsmpi-toolkit) or copy-paste. For customizations, ping Trailblazer Labs! 🕵️