Docs
Build formsAttribution and hidden fields
View as Markdown(opens in a new tab)

Attribution and hidden fields

Every response records where the person came from, so a form linked from twenty pages tells you which page sent them, and a campaign isn't lost when the visitor browses before filling it in:

Stored as Example
The page with the form (origin and path, no query string) meta.pageUrl https://acme.com/demo
The page on your site that led to the form, or the other site that linked straight to it meta.referrer /pricing, or https://news.ycombinator.com
The first page of the visit, when it isn't the form's page meta.landingPage /blog/launch
The other site the visit arrived from, when the form's page wasn't the first meta.entryReferrer https://www.google.com
Campaign tags from the form's page, else from the landing page meta.utm { "source": "google", "medium": "cpc" }

It shows on each response (Came from, Landing page, Visit came from), in Slack and email notifications ("From /pricing · via google / cpc · landed on /blog/launch"), in Insights (Where people come from, Pages that led here), in the CSV and API exports (page_url, referrer, landing_page, entry_referrer, utm_*), and in webhooks and database rows (meta).

Record it on every page (optional)

A page with a form records it by itself. To also know the pages a visitor saw before reaching the form (which page sent them, where the visit started), add MirioAttribution once to the root layout. It's optional: a choice for the site owner, since it runs on every page. It takes no props and renders nothing, so a Next.js server layout can render it:

// app/layout.tsx
import { MirioAttribution } from '@trymirio/mirio/attribution';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <MirioAttribution />
        {children}
      </body>
    </html>
  );
}

Import it from @trymirio/mirio/attribution (0.2.1 and later): that entry holds only MirioAttribution and startAttribution, about 4 KB before compression, so pages without a form don't load the form components. MirioAttribution from @trymirio/mirio works the same, but that entry is the whole component library (the styled components, the form hook and validation, tailwind-merge); in a root layout, every page may load it unless your bundler drops the unused parts.

Without either, responses still carry the form's own page, the site that linked straight to it and its campaign tags.

Only on some pages, or without React

startAttribution() is the same thing as a function, from @trymirio/mirio/client (no React, no components; it's what createClient calls) or @trymirio/mirio/attribution. Call it in the browser once per page load, on the pages you want counted: say, the landing pages your campaigns point at and the pages that link to the form, if you'd rather not run it everywhere.

// app/(marketing)/layout.tsx: only the marketing pages
'use client';
import { useEffect } from 'react';
import { startAttribution } from '@trymirio/mirio/client';

export default function MarketingLayout({ children }: { children: React.ReactNode }) {
  useEffect(() => startAttribution(), []);
  return children;
}

Outside React, call it from a script on the page: import { startAttribution } from '@trymirio/mirio/client'; startAttribution();. It's safe to call more than once, and it does nothing on the server.

What "some pages" means:

  • The visit starts on the first page that calls it, so that page is the landing page, and the site the visitor came from is still read from document.referrer.
  • Once it has started, it follows client-side navigation (Next.js, React Router) for the rest of that page load, on every page, not only the ones that call it; a full page load stops that until a page calls it again.
  • A page that never calls it, opened with a full page load, isn't recorded. The form's page always is: createClient starts it, unless attribution: false.

Privacy

  • Other sites are recorded as their origin only (https://www.google.com), never their path or query, which can hold search terms or tokens. Pages on your site are recorded as paths, without query strings. Mirio's API trims whatever a client sends to this, including older versions that send the full document.referrer.
  • The visit record lives in the visitor's own sessionStorage for that tab, until the tab closes. It's sent only with a submission. No cookies, nothing shared across sites.
  • Turn it off with createClient({ projectId, attribution: false }) in mirio/client.ts: responses then carry only what the form's page knows.
  • Consent. In the EU and UK, keeping data in a visitor's browser and sending it later can need consent under the ePrivacy rules, even without cookies, when it isn't strictly necessary for the form. The site owner decides. If your site asks for consent for analytics, treat attribution the same way: pass attribution: false until the visitor agrees, or leave it off. Mention Mirio in your privacy notice either way (what Mirio stores).

Hidden fields

A hidden field isn't shown; its value comes from the URL, like Typeform's hidden fields. Link to /demo?plan=pro&partner=acme and:

fields: [
  { key: 'plan', type: 'hidden', label: 'Plan' },                                    // ?plan=…
  { key: 'partner', type: 'hidden', label: 'Partner', prefill: { query: 'partner' } }, // any parameter name
  { key: 'source', type: 'hidden', label: 'Source', defaultValue: 'website' },         // a fixed value
]

A hidden field reads the parameter named after its key, or prefill.query. When the form's page doesn't have the parameter, it reads it from the landing page of the visit, so acme.com/?plan=pro → /pricing → /demo still fills plan (with MirioAttribution in the layout). prefill.query works on visible fields too, and initialValues on <Form> sets values from code (it wins over the URL). Hidden values are stored and delivered like any answer.

Triage doesn't read hidden fields unless the field says review: true: then the value goes to triage (and drafted replies) as context the site attached, so a pricing page's ?plan=enterprise shapes the fit. See what triage reads. To send notifications by a hidden value, give an email or Slack destination a filter on answers: npx @trymirio/mirio destinations add slack --form demo --where plan=enterprise.