Recipes

Separate marketing site and app, with a waitlist

Credit partners when visitors land on a marketing site, join a waitlist and later sign up in an app on another subdomain, with or without cookies.

A common SaaS setup: partners share example.com/?via=<code>, the marketing site has a waitlist, and the product lives at app.example.com with its own backend (here, Convex). This recipe keeps the partner across all of it, with consent respected.

On the marketing site#

Two layers: the code is always carried for the current visit (no cookie needed), and the 90-day cookie is added only after consent.

Attribution.tsx
"use client";
import { useEffect } from "react";

const KEY = "via";
const valid = (r?: string | null) => {
  const v = (r ?? "").trim().toLowerCase();
  return /^[a-z0-9-]{3,40}$/.test(v) ? v : null;
};

/** The partner code for this visit: this tab first, then the Intrio cookie. */
export function partnerRef(): string | null {
  try {
    const stored = valid(sessionStorage.getItem(KEY));
    if (stored) return stored;
  } catch {}
  try {
    const m = document.cookie.match(/(?:^|; )pp_attr=([^;]*)/);
    return m ? valid(JSON.parse(decodeURIComponent(m[1]!)).ref) : null;
  } catch {
    return null;
  }
}

export function Attribution({ sdkKey, domain, consented }: { sdkKey: string; domain: string; consented: boolean }) {
  useEffect(() => {
    const q = new URLSearchParams(location.search);
    const fromUrl = valid(q.get("via") ?? q.get("pp_ref"));
    try {
      if (fromUrl && !sessionStorage.getItem(KEY)) sessionStorage.setItem(KEY, fromUrl);
    } catch {}

    // Carry the code into the app on any link to a subdomain.
    const decorate = (e: MouseEvent) => {
      const a = (e.target as HTMLElement | null)?.closest?.("a[href]") as HTMLAnchorElement | null;
      const ref = a && partnerRef();
      if (!a || !ref) return;
      const u = new URL(a.href);
      if (u.hostname.endsWith("." + domain) && !u.searchParams.has("via")) {
        u.searchParams.set("via", ref);
        a.href = u.toString();
      }
    };
    document.addEventListener("click", decorate, true);
    return () => document.removeEventListener("click", decorate, true);
  }, [domain]);

  useEffect(() => {
    if (!consented || document.getElementById("intrio-sdk")) return;
    const s = document.createElement("script");
    s.id = "intrio-sdk";
    s.async = true;
    s.src = "https://intrio.co/sdk.js";
    s.setAttribute("data-key", sdkKey);
    s.setAttribute("data-domain", domain); // share the cookie with app.example.com
    document.head.appendChild(s);
  }, [consented, sdkKey, domain]);

  return null;
}

Send the code with the waitlist sign-up, so it's stored on your side even if the person converts weeks later:

Waitlist form
await fetch("/api/waitlist", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ email, via: partnerRef() }),
});

In the app#

At sign-up, read ?via= from the URL (or the pp_attr cookie, or the waitlist record) and save it on the account. From then on report events from your backend with the account id as customer.id. This needs an API key, so Growth and above.

convex/intrio.ts
import { v } from "convex/values";
import { internalAction } from "./_generated/server";

/** Partner codes are short slugs; anything else is dropped. */
export const cleanRef = (ref?: string | null) => {
  const r = (ref ?? "").trim().toLowerCase();
  return /^[a-z0-9-]{3,40}$/.test(r) ? r : undefined;
};

export const report = internalAction({
  args: {
    id: v.string(),
    type: v.union(v.literal("signup"), v.literal("payment"), v.literal("refund")),
    accountId: v.string(),
    ref: v.optional(v.string()),
    name: v.optional(v.string()),
    amount: v.optional(v.number()),
    currency: v.optional(v.string()),
    refunds: v.optional(v.string()),
  },
  handler: async (_ctx, a) => {
    const key = process.env.INTRIO_API_KEY;
    if (!key) return { sent: false }; // not configured (local, staging)
    const body = {
      id: a.id,
      type: a.type,
      programme: process.env.INTRIO_PROGRAMME ?? "app",
      ref: a.ref,
      customer: { id: a.accountId, name: a.name },
      amount: a.amount,
      currency: a.currency?.toUpperCase(),
      refunds: a.refunds,
    };
    for (let attempt = 0; attempt < 3; attempt++) {
      try {
        const res = await fetch("https://intrio.co/api/v1/conversions", {
          method: "POST",
          headers: { "content-type": "application/json", authorization: `Bearer ${key}` },
          body: JSON.stringify(body),
        });
        if (res.ok) return { sent: true };
        if (res.status < 500 && res.status !== 429) return { sent: false, status: res.status }; // final answer
      } catch {}
      await new Promise((r) => setTimeout(r, 1000 * 2 ** attempt));
    }
    return { sent: false };
  },
});

Schedule it from your mutations so reporting never blocks sign-up or billing:

Convex
// After creating the account
await ctx.scheduler.runAfter(0, internal.intrio.report, {
  id: `signup:${accountId}`, type: "signup", accountId, ref: cleanRef(args.via), name: args.name,
});

// In your Stripe webhook, for invoice.paid on a referred account
await ctx.scheduler.runAfter(0, internal.intrio.report, {
  id: invoice.id, type: "payment", accountId, amount: invoice.amount_paid, currency: invoice.currency,
});

// For charge.refunded: one report per refund, with its own id and amount
// (charge.amount_refunded is cumulative, so it would reverse earlier partial refunds again)
for (const refund of (await stripe.refunds.list({ charge: charge.id })).data) {
  if (refund.status !== "succeeded") continue;
  await ctx.scheduler.runAfter(0, internal.intrio.report, {
    id: refund.id, type: "refund", accountId, refunds: invoiceId, amount: refund.amount,
  });
}

Last updated 20 November 2026. Building with an AI assistant? Point it at /docs/llms-full.txt.