L'attribuzione server-to-server (S2S) sposta la logica di attribuzione dal client (l'SDK nell'app) al server. Invece di lasciare che l'SDK sul dispositivo prenda le decisioni, il tuo server riceve gli eventi dall'app, interroga le API dei network pubblicitari, esegue il matching dell'attribuzione e invia i postback. Così hai più controllo, più privacy e non dipendi da SDK di terze parti.
Questa guida descrive l'architettura dell'attribuzione S2S. Per il deferred matching lato server, vedi deferred matching lato server: guida all'architettura. Per gli URL di postback, vedi URL di postback per l'attribuzione mobile.
Perché server-to-server
Vantaggi
| Vantaggio | Spiegazione |
|---|---|
| Controllo della privacy | I dati degli utenti restano sul tuo server. Nessun SDK di terze parti che comunica con l'esterno. |
| Indipendenza dagli SDK | Nessun SDK di attribuzione nella tua app. Riduce le dimensioni dell'app ed evita conflitti tra SDK. |
| Proprietà dei dati | I dati grezzi di attribuzione sono tuoi, non di un provider terzo. |
| Flessibilità | Logica di attribuzione, finestre e regole antifrode personalizzate. |
| Sicurezza | La comunicazione server-to-server usa le API key, non token lato client. |
Compromessi
| Compromesso | Spiegazione |
|---|---|
| Costo di sviluppo | Sei tu a costruire e mantenere il sistema di attribuzione. |
| Integrazione SAN | I self-attributing network (Meta, Google) hanno API S2S complesse. |
| Manutenzione | Gli aggiornamenti degli SDK per i cambiamenti di piattaforma (ATT, Privacy Sandbox) sono a tuo carico. |
| Nessuna dashboard gestita | Costruisci il tuo sistema di reporting (o usa uno strumento BI). |
Architettura
┌────────────────┐ ┌────────────────┐ ┌────────────────┐
│ App mobile │────→│ Tuo server │────→│ Ad network │
│ (minimale) │ │ logica di │ │ (postback) │
│ │ │ attribuzione │ │ │
└────────────────┘ └────────────────┘ └────────────────┘
│
↓
┌────────────────┐
│ Click Store │
│ (Redis/DB) │
└────────────────┘
Componenti
App mobile. Invia pochi eventi essenziali al tuo server: primo avvio, registrazione, acquisto e così via. Non serve nessun SDK di attribution.
Endpoint per il tracciamento dei click. Riceve i click dalle campagne pubblicitarie. Salva i dati del click (device ID, campagna, timestamp) nel click store.
Motore di attribution. Quando arriva un evento di primo avvio, cerca nel click store i click corrispondenti ed esegue la logica di attribution.
Invio dei postback. Invia i risultati di attribution alle reti pubblicitarie tramite i loro URL di postback.
Click store. Key-value store veloce (Redis) per la ricerca dei click. Indicizzato per device ID.
Implementazione
Tracciamento dei click
Quando un utente clicca un annuncio, la rete pubblicitaria lo reindirizza al tuo endpoint di tracciamento dei click:
// GET /track/click?network=facebook&campaign=CAMP-123&device_id=...&click_id=... app.get('/track/click', async (req, res) => { const click: Click = { id: generateId(), networkId: req.query.network as string, campaignId: req.query.campaign as string, adGroupId: req.query.ad_group as string, creativeId: req.query.creative as string, deviceId: req.query.device_id as string, clickId: req.query.click_id as string, ip: req.ip, userAgent: req.headers['user-agent'] || '', timestamp: Date.now(), referrer: req.query.referrer as string }; // Salva il click await clickStore.record(click); // Reindirizza all'app store o allo Universal Link const redirectUrl = req.query.redirect_url as string; res.redirect(302, redirectUrl); });Evento First Open
Alla prima apertura dell'app, questa invia un evento leggero al tuo server:
// iOS: invia l'evento first_open func sendFirstOpenEvent() { let event: [String: Any] = [ "event": "first_open", "device_id": getDeviceId(), "idfa": getIDFA(), // nil se l'utente non ha dato il consenso ATT "idfv": UIDevice.current.identifierForVendor?.uuidString ?? "", "os": "ios", "os_version": UIDevice.current.systemVersion, "app_version": Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "", "timestamp": Date().timeIntervalSince1970, "locale": Locale.current.identifier, "timezone": TimeZone.current.identifier ] URLSession.shared.dataTask(with: buildRequest("/v1/events", body: event)).resume() }Motore di attribuzione
interface AttributionResult { attributed: boolean; source: 'paid' | 'organic'; networkId?: string; campaignId?: string; clickId?: string; matchType: 'deterministic' | 'probabilistic' | 'organic'; } async function attributeInstall(event: InstallEvent): Promise<AttributionResult> { // Passo 1: match deterministico (device ID) if (event.deviceId) { const clicks = await clickStore.getByDeviceId(event.deviceId, { within: '7d' }); if (clicks.length > 0) { const bestClick = selectBestClick(clicks); // Modello last-click const fraudCheck = await checkFraud(event, bestClick); if (!fraudCheck.isFraud) { return { attributed: true, source: 'paid', networkId: bestClick.networkId, campaignId: bestClick.campaignId, clickId: bestClick.clickId, matchType: 'deterministic' }; } } } // Passo 2: match probabilistico (IP + User Agent) const probClicks = await clickStore.getByIPAndUA( event.ip, event.userAgent, { within: '24h' } ); if (probClicks.length > 0) { const bestClick = selectBestClick(probClicks); return { attributed: true, source: 'paid', networkId: bestClick.networkId, campaignId: bestClick.campaignId, clickId: bestClick.clickId, matchType: 'probabilistic' }; } // Passo 3: organico return { attributed: false, source: 'organic', matchType: 'organic' }; }Invio dei postback
Dopo l'attribution, invia i risultati alla rete pubblicitaria:
async function sendPostback(result: AttributionResult, event: InstallEvent): Promise<void> { if (!result.attributed || !result.networkId) return; const network = await getNetworkConfig(result.networkId); if (!network.postbackUrl) return; const url = network.postbackUrl .replace('{click_id}', result.clickId || '') .replace('{event}', 'install') .replace('{timestamp}', String(event.timestamp)) .replace('{device_id}', event.deviceId || ''); try { const response = await fetch(url, { method: 'GET' }); await logPostback(result, response.status); } catch (error) { await logPostbackError(result, error); // Metti in coda il nuovo tentativo await retryQueue.add({ url, result, attempt: 1 }); } }Integrazione con i Self-Attributing Network
Le SAN (Meta, Google, TikTok) richiedono un'integrazione S2S dedicata, perché non usano il tracciamento standard dei click:
Meta Conversions API
async function sendMetaConversion(event: InstallEvent): Promise<void> { const payload = { data: [{ event_name: 'app_install', event_time: Math.floor(event.timestamp / 1000), user_data: { client_ip_address: event.ip, client_user_agent: event.userAgent, madid: event.deviceId // Mobile Advertiser ID }, app_data: { application_tracking_enabled: event.attConsented ? 1 : 0, advertiser_tracking_enabled: event.attConsented ? 1 : 0 } }] }; await fetch( `https://graph.facebook.com/v18.0/${PIXEL_ID}/events?access_token=${ACCESS_TOKEN}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) } ); }Google Measurement Protocol
async function sendGoogleConversion(event: InstallEvent): Promise<void> { const payload = { client_id: event.deviceId, events: [{ name: 'first_open', params: { campaign: event.attributedCampaign, source: 'google', medium: 'cpc' } }] }; await fetch( `https://www.google-analytics.com/mp/collect?measurement_id=${GA_ID}&api_secret=${API_SECRET}`, { method: 'POST', body: JSON.stringify(payload) } ); }Archiviazione dei dati
Schema del Click Store
CREATE TABLE clicks ( id TEXT PRIMARY KEY, network_id TEXT NOT NULL, campaign_id TEXT, ad_group_id TEXT, creative_id TEXT, device_id TEXT, click_id TEXT, ip_address TEXT, user_agent TEXT, timestamp BIGINT NOT NULL, INDEX idx_device_id (device_id), INDEX idx_ip_ua (ip_address, user_agent), INDEX idx_timestamp (timestamp) ); -- TTL: elimina i click più vecchi di 30 giorniSchema del log di attribuzione
CREATE TABLE attributions ( id TEXT PRIMARY KEY, device_id TEXT, event_type TEXT NOT NULL, attributed BOOLEAN NOT NULL, source TEXT NOT NULL, -- 'paid' o 'organic' network_id TEXT, campaign_id TEXT, click_id TEXT, match_type TEXT, -- 'deterministic', 'probabilistic', 'organic' event_timestamp BIGINT NOT NULL, attribution_timestamp BIGINT NOT NULL, postback_sent BOOLEAN DEFAULT FALSE, INDEX idx_device (device_id), INDEX idx_campaign (campaign_id) );Tolinku per l'attribuzione S2S
Tolinku fornisce tracciamento dei click e attribution lato server tramite la sua API. I click sui deep link vengono tracciati lato server, e i dati di attribution sono disponibili nella dashboard e tramite l'API. Così ottieni attribution S2S per le campagne deep link senza dover costruire l'infrastruttura completa.
Per l'attribuzione mobile, vedi attribuzione mobile: guida per sviluppatori. Per il matching deferred, vedi deferred matching lato server: guida all'architettura.
Ricevi consigli sul deep linking nella tua casella di posta
Una email a settimana. Niente spam.