Naar inhoud springen
Analytics & Attributie · · 5 min leestijd

Server-naar-server-attributie: architectuurgids

Door Tolinku-team
|
Server-naar-server-attributie: architectuurgids

Server-to-server (S2S) attributie verplaatst de attributielogica van de client (de app-SDK) naar je server. In plaats van dat de attributie-SDK op het toestel beslissingen neemt, ontvangt je server events van de app, vraagt de API's van advertentienetwerken op, voert de attributiematch uit en stuurt postbacks. Je houdt zo meer controle, de privacy is beter en je bent niet afhankelijk van SDK's van derden.

Deze gids behandelt de architectuur van S2S-attributie. Voor server-side deferred matching, zie server-side deferred matching: architectuurgids. Voor postback-URL's, zie postback-URL's voor mobiele attributie.

Waarom server-to-server

Voordelen

Voordeel Toelichting
Privacycontrole Gebruikersdata blijft op je server. Geen SDK van derden die data naar buiten stuurt.
Onafhankelijk van SDK's Geen attributie-SDK in je app. Kleinere app en minder kans op SDK-conflicten.
Eigendom van data Je bezit de ruwe attributiedata zelf, niet een externe aanbieder.
Flexibiliteit Eigen attributielogica, eigen vensters en eigen frauderegels.
Beveiliging Communicatie tussen servers gebruikt API-sleutels, niet client-side tokens.

Afwegingen

Afweging Toelichting
Ontwikkelkosten Je bouwt en onderhoudt het attributiesysteem zelf.
Integratie met SAN's Self-attributing networks (Meta, Google) hebben complexe S2S-API's.
Onderhoud SDK-updates voor platformwijzigingen (ATT, Privacy Sandbox) zijn je eigen verantwoordelijkheid.
Geen beheerdashboard Je bouwt je eigen rapportage (of gebruikt een BI-tool).

Architectuur

┌─────────────┐     ┌──────────────┐     ┌──────────────┐
│  Mobiele app│────→│  Je server   │────→│ Ad-netwerken │
│  (minimaal) │     │  (attributie │     │  (postbacks) │
│             │     │   logica)    │     │              │
└─────────────┘     └──────────────┘     └──────────────┘
                           │
                           ↓
                    ┌──────────────┐
                    │ Clickstore   │
                    │  (Redis/DB)  │
                    └──────────────┘

Onderdelen

  1. Mobiele app. Stuurt minimale events naar je server: eerste open, registratie, aankoop, enzovoort. Geen attributie-SDK nodig.

    Eindpunt voor clicktracking. Ontvangt clicks van advertentiecampagnes. Slaat clickdata (device-ID, campagne, tijdstip) op in de clickstore.

    Attributiemotor. Zodra een eerste-open-event binnenkomt, zoekt de engine in de clickstore naar passende clicks en past de attributielogica toe.

    Postbackverzender. Stuurt attributieresultaten naar advertentienetwerken via hun postback-URL's.

    Clickstore. Snelle key-value-opslag (Redis) om clicks op te zoeken. Geïndexeerd op device-ID.

    Implementatie

    Clicktracking

    Wanneer een gebruiker op een advertentie klikt, stuurt het advertentienetwerk die klik via je eindpunt voor clicktracking door:

    // 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
      };
    
      // Klik opslaan
      await clickStore.record(click);
    
      // Doorsturen naar de app store of Universal Link
      const redirectUrl = req.query.redirect_url as string;
      res.redirect(302, redirectUrl);
    });
    

    Eerste-open-event

    Wanneer de app voor het eerst wordt geopend, stuurt die een lichtgewicht event naar je server:

    // iOS: stuur het first_open-event
    func sendFirstOpenEvent() {
        let event: [String: Any] = [
            "event": "first_open",
            "device_id": getDeviceId(),
            "idfa": getIDFA(), // nil als ATT niet is toegestaan
            "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()
    }
    

    Attributiemotor

    interface AttributionResult {
      attributed: boolean;
      source: 'paid' | 'organic';
      networkId?: string;
      campaignId?: string;
      clickId?: string;
      matchType: 'deterministic' | 'probabilistic' | 'organic';
    }
    
    async function attributeInstall(event: InstallEvent): Promise<AttributionResult> {
      // Stap 1: deterministische match (device ID)
      if (event.deviceId) {
        const clicks = await clickStore.getByDeviceId(event.deviceId, { within: '7d' });
    
        if (clicks.length > 0) {
          const bestClick = selectBestClick(clicks); // Last-click-model
          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'
            };
          }
        }
      }
    
      // Stap 2: probabilistische match (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'
        };
      }
    
      // Stap 3: organisch
      return {
        attributed: false,
        source: 'organic',
        matchType: 'organic'
      };
    }
    

    Postbacks versturen

    Na de attributie stuur je de resultaten naar het advertentienetwerk:

    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);
        // Zet in de wachtrij voor een nieuwe poging
        await retryQueue.add({ url, result, attempt: 1 });
      }
    }
    

    Integratie met self-attributing networks

    SAN's (Meta, Google, TikTok) hebben een speciale S2S-integratie nodig, omdat ze geen standaard clicktracking gebruiken:

    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 // Mobiel advertentie-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)
        }
      );
    }
    

    Gegevensopslag

    Schema van de clickstore

    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: verwijder clicks ouder dan 30 dagen
    

    Schema van het attributielog

    CREATE TABLE attributions (
      id TEXT PRIMARY KEY,
      device_id TEXT,
      event_type TEXT NOT NULL,
      attributed BOOLEAN NOT NULL,
      source TEXT NOT NULL, -- 'paid' of 'organic'
      network_id TEXT,
      campaign_id TEXT,
      click_id TEXT,
      match_type TEXT, -- 'deterministic', 'probabilistic' of '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 voor S2S-attributie

    Tolinku biedt server-side clicktracking en attributie via zijn API. Deep link-clicks worden server-side bijgehouden, en attributiedata is beschikbaar via het dashboard en de API. Zo krijg je S2S-attributie voor deep link-campagnes zonder de volledige infrastructuur zelf te bouwen.

    Voor mobiele attributie, zie mobiele attributie: een gids voor developers. Voor server-side deferred matching, zie server-side deferred matching: architectuurgids.

Ontvang deep linking-tips in je inbox

Eén e-mail per week. Geen spam.

Klaar om deep linking aan je app toe te voegen?

Stel Universal Links, App Links, deferred deep linking en analytics in enkele minuten in. Gratis om te beginnen.