Skip to main content

Multi-tenancy

If you’re building a platform that serves multiple customers, use the tenant parameter to tag traffic by client.

Set the tenant

Add ?tenant= to the pixel URL:
(function() {
  var s = document.createElement('script');
  s.src = 'https://p.midbound.net/mdb_pxl_XXXXX?tenant=customer_123';
  s.async = true;
  document.head.appendChild(s);
})();
The tenant ID can be any string - use your internal customer ID.

Receive it in webhooks

The tenant ID is included in the session data:
{
  "id": "evt_01KHEWXAPDWJ60WGQ9MXMK280W",
  "type": "identity.session.finalized",
  "created": 1771100351147,
  "data": {
    "attribution": {
      "type": "website",
      "pixelId": "mdb_pxl_01KGP4D7S5HR7825H71RCF5PKH",
      "vid": "01KHETKHB5YCF27VJW1XJDZERK",
      "sessionId": "01KHEWP4PB3SJN5JS0XM1ZHG39"
    },
    "session": {
      "tenant": "customer_123",
      "createdAt": 1771100115659,
      "endedAt": 1771100350842,
      ...
    }
  }
}

Filter in the dashboard

In the Console, filter traffic and events by tenant ID to view data for specific customers.

Examples

Dynamic tenant from your app

(function() {
  var s = document.createElement('script');
  s.src = 'https://p.midbound.net/mdb_pxl_XXXXX?tenant=' + window.CUSTOMER_ID;
  s.async = true;
  document.head.appendChild(s);
})();

Route webhooks by tenant

import { webhooks } from '@midbound/cloud';

app.post('/webhooks/midbound', (req, res) => {
  const event = webhooks.constructEvent(
    req.body,
    req.headers['x-midbound-signature'],
    process.env.MIDBOUND_WEBHOOK_SECRET!
  );

  const tenant = event.data.session?.tenant;

  // Route to customer-specific handler
  if (tenant) {
    await sendToCustomer(tenant, event);
  }

  res.status(200).send('OK');
});

PHP with tenant

<?php
$pixelId = 'mdb_pxl_YOUR_PIXEL_ID';
$tenant = $customer->id;
?>
<script async src="https://p.midbound.net/<?= $pixelId ?>?tenant=<?= $tenant ?>"></script>