Build a browser pixel

Receive reviewed, consented canonical events in a sandboxed pixel frame or, for reviewed integrations, the page runtime.

A browser pixel is a storefront_embeds entry with kind: "pixel" that receives the events declared for the browser transport of server_events. Its consent category decides which shoppers get it and which events it receives. The app configuration file has complete declarations for both runtimes.

Sandbox runtime#

A sandboxed pixel consists of a version-pinned frame document (frame_url) and pixel script (script_url) on the same app-controlled HTTPS origin. The storefront adds the frame as a hidden iframe with sandbox="allow-scripts allow-same-origin" and referrerpolicy="no-referrer". The release freezes the frame URL, not the app-hosted document or its dependencies: those bytes remain mutable and are not integrity-verified. Keep versioned assets immutable on your host. Because the frame is cross-origin, the browser's same-origin policy keeps it away from the storefront DOM, cookies, JavaScript objects and storage; it may use its own origin's storage when a provider SDK needs it. The storefront posts messages only to your frame's exact origin, so a frame that navigated elsewhere receives nothing.

Page runtime#

With browser_runtime: "page", the storefront adds your script_url to the merchant's page as a deferred script. It runs with ordinary page privileges: it can read the whole page, including what shoppers type into forms, and send it anywhere. The declared events, fields and consent purpose are what Tringify hands the script, not a limit on what it can do. Use it only when the provider's SDK needs the merchant's first-party cookies or the landing page's click IDs, which a cross-origin frame cannot reach.

  • Review. A release declaring a page-runtime pixel needs a separate staff confirmation of the privileged runtime. Development and private installs of such a release are refused (APP_PIXEL_PAGE_RUNTIME_UNREVIEWED) until it has been through review.

  • Integrity. The release pins script_integrity, the sha384- Subresource Integrity hash of the exact bytes at script_url. On submission Tringify fetches script_url (HTTPS, no redirects, at most 512 KiB, 10 seconds), requires Access-Control-Allow-Origin: *, and compares the hash. The storefront adds integrity and crossorigin="anonymous" to the tag, so the browser refuses any other bytes. Serve the file with that header and never change it in place.

  • Merchant acknowledgement. Merchants see the pixel marked Full page access and must confirm a warning before turning it on (APP_PIXEL_PRIVILEGED_ACK_REQUIRED without it).

  • Checkout. On checkout and order confirmation, where shoppers enter contact, address and payment details, a page-runtime pixel runs in its frame_url, exactly like a sandboxed pixel (the frame gets the minimised context and the projected events, never the page), unless the release declares checkout_runtime: "page". Then the same script runs in those pages too, with the page's full address, its first-party cookies and the landing click IDs, which keeps checkout and purchase events matched to the visit. checkout_runtime takes only "page", only on a page-runtime pixel, and is reviewed with the release; the merchant's Full page access confirmation covers it, and the pixel shows Runs on checkout. A page-runtime pixel with neither a frame_url nor checkout_runtime does not run on those pages.

Where pixels run#

Page

Which pixels

When they start

Themed storefront pages

Every enabled pixel the shopper's consent allows.

After the page has loaded or is idle, or at the shopper's first interaction.

Checkout and order confirmation

Sandboxed app pixels, merchants' custom pixels, and the Tringify organization's page-runtime pixels.

Immediately.

Checkout editor previews, bot and crawler visits

None.

Never.

A pixel that cannot be read or built for a page is left out of that page and logged; checkout and order confirmation never fail because of a pixel. Merchants' own custom pixels use the same tringify.pixel API as the frame runtime below, inside an opaque-origin sandbox without app involvement; see Pixels in the merchant Help.

Themed pages keep pixel code and visitor initialization out of shared HTML. The bridge obtains setup in the private event-confirmation response, with a private runtime endpoint as fallback, and starts the pixels at load/idle or first interaction. Declarations use bounded, content-version-keyed caches; checkout and confirmation retain immediate private initialization. A page runs at most 64 pixel runtimes (first-party apps take priority) and 512 KiB of custom code; omissions emit storefront.pixel.omitted.

Host the frame document#

pixel-frame.html html
<!doctype html>
<meta charset="utf-8">
<script src="/v1/pixel-frame.js"></script>

frame_url must be HTTPS, carry a version or content hash in its path, have no query or fragment, and use the origin of script_url. Both must be on an origin the app already registered (admin_ui_url, app_bridge_allowed_origins, redirect_uris or webhook_url), never a Tringify platform or storefront domain.

When the storefront renders the frame it appends the reserved tringify_store_id query parameter, the public ID of the store. Use it to answer with installation-specific headers, such as a Content-Security-Policy whose frame-ancestors lists that store's storefront origins, or ignore it. Keep every executable URL versioned or content-addressed so an approved release remains reproducible.

Frame messages#

The storefront page talks to your frame with postMessage, targeting its exact origin. Every message is an object with a __tf type:

Message

When

Data

pixel-init

Once, right after the frame's load event.

context: the page context below.

pixel

Once per event ID and pixel, after pixel-init.

event: {event_id, type, schema_version, payload, ts}, plus session_id where allowed.

pixel-context

After a soft navigation, or when your app_attribution arrives after pixel-init.

The whole context, with the new minimised url or with app_attribution. Replace your copy.

Until the frame has loaded, the page holds its messages in a bounded queue of 200 and then sends them in order; past the limit the oldest are dropped. Events that happened before the frame loaded are therefore delivered after pixel-init, not lost. Install your listener while the frame document loads.

Install the frame runtime#

pixel-frame.js javascript
(() => {
  "use strict";
  // Install the listener while this document loads (a classic script in the
  // head, not async or deferred): the storefront sends pixel-init right after
  // the frame's load event, then the events it held until then.
  const BUFFER_LIMIT = 200;
  let context = null;
  let started = false;
  const subscribers = [];
  const buffered = [];
  const seen = new Set();

  window.tringify = { pixel: {
    context: () => structuredClone(context || {}),
    subscribe: (callback) => {
      if (typeof callback !== "function") return () => {};
      subscribers.push(callback);
      for (const event of buffered) callback(event);
      return () => {
        const index = subscribers.indexOf(callback);
        if (index >= 0) subscribers.splice(index, 1);
      };
    }
  }};

  addEventListener("message", (message) => {
    // Only the storefront page that framed this document talks to it.
    if (message.source !== parent) return;
    const data = message.data;
    if (!data || typeof data !== "object") return;
    if (data.__tf === "pixel-init" && !started) {
      context = data.context || {};
      started = true;
      const script = document.createElement("script");
      script.src = "/v1/pixel.js";
      document.head.appendChild(script);
      return;
    }
    if (data.__tf === "pixel-context" && data.context) {
      // Soft navigation: same page view, new minimised address.
      context = data.context;
      return;
    }
    if (data.__tf !== "pixel" || !data.event) return;
    if (seen.has(data.event.event_id)) return;
    seen.add(data.event.event_id);
    if (buffered.length >= BUFFER_LIMIT) buffered.shift();
    buffered.push(data.event);
    for (const callback of subscribers) {
      try { callback(data.event); } catch (error) { console.error(error); }
    }
  });
})();

Subscribe in the pixel script#

pixel.js javascript
const pixel = window.tringify?.pixel;
if (!pixel) throw new Error("Tringify pixel runtime is unavailable");

const context = pixel.context();
const unsubscribe = pixel.subscribe((event) => {
  // Map only the declared event and payload fields to your provider.
  provider.track(event.type, event.payload, { eventId: event.event_id });
});

Page context#

pixel-init and tringify.pixel.context() carry:

Field

Value

store_id

The store.

url

Sandboxed pixels get the store origin and path plus only these query parameters: utm_*, gclid, gbraid, wbraid, dclid, fbclid, msclkid, ttclid, twclid, li_fat_id, epik, sccid, variant and page, with no fragment. Checkout, order confirmation, account and password-reset pages are reduced to /checkout, /order-confirmation, /account and /account/reset. Click ID parameters that apps declared are removed: each app receives its own in app_attribution.

referrer

The referring origin only.

locale, currency, country

The shopper's language, currency and country for the page.

page_type

The kind of page, such as product; checkout on checkout and order_confirmation on order confirmation.

consent

The shopper's consent choices for the page.

browser_id, attribution

Advertising pixels only: the pseudonymous advertising browser ID and the campaign attribution.

customer_match

Advertising pixels of a release that declared customer_match, while the shopper allows Advertising and Advertising data.

app_attribution

The advertising frame pixel of a release that declared server_events.attribution, while the shopper allows Advertising: click_ids (each with value and captured_at) and cookies, the declared values the shopper has. Never sent to another app's pixel or to a custom pixel.

pixel-context.json json
{
  "attribution": {
    "utm_source": "newsletter"
  },
  "browser_id": "4f0d8c1e-2b7a-4c5d-9e3f-6a1b2c3d4e5f",
  "consent": {
    "advertising": true,
    "advertising_data": false,
    "analytics": true,
    "personalization": true,
    "personalized_advertising": false
  },
  "country": "DE",
  "currency": "EUR",
  "locale": "en",
  "page_type": "product",
  "referrer": "https://www.google.com",
  "store_id": "f192d1f9-b01f-48c2-9300-3f3bf14716b0",
  "url": "https://shop.example/products/canvas-print?utm_source=newsletter"
}

Your click IDs and cookies in the frame#

When your release declares server_events.attribution, the storefront never writes your values into the page. Before it sends pixel-init, the page asks Tringify for your installation's values with a short-lived token that names only your installation, then adds them to the pixel-init context as app_attribution. It waits at most 3 seconds; an answer that comes later arrives as a pixel-context message with the whole context, now including app_attribution. Tringify checks the shopper's consent when it answers. This works the same on checkout and order confirmation, where your frame is the only place app code runs.

pixel-context-app-attribution.json json
{
  "app_attribution": {
    "click_ids": {
      "exclid": {
        "captured_at": "2026-08-10T21:14:03Z",
        "value": "Cj0KCQjw-example"
      }
    },
    "cookies": {
      "_exa": "ex.1.1786302843000.4821930457",
      "_exc": "ex.1.1786302843000.Cj0KCQjw-example"
    }
  }
}

A page-runtime pixel does not receive app_attribution: it runs in the page and reads the landing URL and its own cookies itself. Its frame on checkout and order confirmation does receive it.

Search events carry the shopper's raw search text in payload.query. Shoppers sometimes type personal details into search: treat it as sensitive, and declare query only if the destination needs it.

pixel-event.json json
{
  "event_id": "019f0000-0000-7000-8000-000000000002",
  "payload": {
    "currency": "EUR",
    "price": "1499.00",
    "product_id": 4821,
    "sku": "CANVAS-A4",
    "slug": "canvas-print",
    "title": "Canvas Print",
    "variant_id": 9102
  },
  "schema_version": 1,
  "ts": 1786406400000,
  "type": "product_viewed"
}

Page-runtime contract#

A page-runtime pixel's script tag carries data-tf-context (the context above, with the full page URL and referrer), data-tf-events (the declared event types), data-tf-fields (the declared payload fields per type), data-tf-purpose (the pixel's consent category) and data-tf-session-id. Subscribe with window.tringify.events.subscribe(type, callback, { purpose }), which is defined before your script runs, and forward only the declared fields.

page-pixel.js javascript
(() => {
  "use strict";
  // Runs in the merchant's page. Read the attributes of this script tag.
  const script = document.currentScript;
  const context = JSON.parse(script.dataset.tfContext || "{}");
  const types = JSON.parse(script.dataset.tfEvents || "[]");
  const fields = JSON.parse(script.dataset.tfFields || "{}");
  const purpose = script.dataset.tfPurpose || "";

  for (const type of types) {
    window.tringify.events.subscribe(type, (event) => {
      // Forward only the payload fields the release declared.
      const payload = {};
      for (const key of fields[type] || []) payload[key] = event.payload[key];
      provider.track(event.type, payload, { eventId: event.event_id, page: context.url });
    }, { purpose });
  }
})();

Delivery and retries#

Browser delivery is best effort. Use event_id as the deduplication key with the destination; the server transport carries the same ID for the same event, so a destination that deduplicates counts it once.

  • Observed events (page views, product views, searches and similar) are published once the platform has confirmed them. The page retries a failed confirmation up to 3 times with the same event IDs.

  • begin_checkout, payment_info_added and purchase are replayed from committed platform state on checkout and order confirmation pages. A replay stays pending for 30 minutes until the page acknowledges it; reloading the page before then replays the same event IDs again. payment_info_added reaches browser pixels on the next checkout or order confirmation page, with the same ID as the server event.

  • A purchase replayed on order confirmation carries the consent the shopper gave at the time of sale.

  • Each page keeps the last 500 events per consent category, and the frame relay delivers each event ID to a pixel once.

Soft navigation#

When the storefront swaps content in place (filters, sorting, pagination, variant links) it is not a new page view: no event is published. Sandboxed pixels receive pixel-context with the new minimised url. Provider SDKs on the page runtime observe history changes themselves, and their own settings decide whether they count one as a page view.

Each event carries the consent purposes allowed when it happened, and the page delivers it only to pixels whose category was allowed then and is allowed now. When a shopper withdraws a category, delivery to its pixels stops at once, events queued for them are dropped and its sandboxed frames are removed. If a page-runtime pixel of the withdrawn category is on the page, or a newly allowed category has pixels that are not on the page, the page reloads. The shopper's other open tabs of the store follow within a second. Your frame can therefore disappear at any time: send events as they arrive rather than on unload.