Attribution

handleInbound, resolveReferral, and applyCode — how referral codes reach the SDK on every platform

Three methods cover every way a referral code arrives. handleInbound handles the already-installed path (a deep link opens your app). resolveReferral handles the fresh-install path (deferred attribution) and reports the outcome. applyCode is the manual-entry fallback that makes attribution complete.

The method names and outcomes are identical everywhere; the machinery underneath is platform-specific — URL params and a first-party cookie on web, the clipboard handoff on iOS, the Play Install Referrer on Android. No fingerprinting on any platform. The full model lives in Attribution.

handleInbound

Extracts a referral code from an incoming URL and applies it. Returns immediately; validation happens in the background. Non-referral URLs are ignored, so it is safe to forward every incoming URL.

ParameterTypeDescription
urlURLThe incoming Universal Link / App Link / web URL.

Returns true if the URL contained a referral code the SDK will apply.

invitebase.handleInbound(url?: string): InboundReferral | null

On web this returns the parsed referral (or null) instead of a boolean, and url defaults to window.location.href. With autoResolve on, configure already handles the landing URL — call this yourself for client-side routing or custom entry points.

const inbound = invitebase.handleInbound();
if (inbound) {
  showWelcomeBanner(`You were invited by ${inbound.referrerName ?? 'a friend'}`);
}

resolveReferral

Runs (or reports) deferred attribution for a fresh install and returns one of three outcomes:

  • attributed — a code was recovered and applied; show your referee welcome moment.
  • needsManualEntry — automatic attribution missed. The signal tells you how confident to be: strong means a referral is likely (prompt prominently), soft means probably organic (offer a skippable field).
  • organic — no referral signal at all.

No parameters.

invitebase.resolveReferral(): Promise<ReferralResolution>
type ReferralResolution =
  | { status: 'attributed'; referral: InboundReferral }
  | { status: 'organic' };

On web there is no deferred-install gap, so this resolves from the URL/cookie state immediately — and needsManualEntry never occurs.

const resolution = await invitebase.resolveReferral();
if (resolution.status === 'attributed') {
  console.log('Referred with code', resolution.referral.code);
}

Resolve early — deferred-attribution signals are volatile between install and first launch — but surface any manual-entry UI at a contextual onboarding moment. Every branch emits telemetry, so your attribution funnel shows the measured rates.

applyCode

Applies a manually entered referral code — the fallback when automatic attribution misses. Validates against the API; invalid or expired codes throw an invalid_referral_code error, so your UI can keep the user in the entry flow instead of a dead end.

ParameterTypeDescription
codestringThe referral code, e.g. a1b2c3. Case-insensitive, whitespace-trimmed.

Returns an InboundReferral{ code, campaignId, referrerName, refereeOffer }, with referrerName privacy-safe and refereeOffer display-ready (e.g. "1 month free").

invitebase.applyCode(code: string): Promise<InboundReferral>
try {
  const referral = await invitebase.applyCode(inputValue);
  showConfirmation(`Invited by ${referral.referrerName} — ${referral.refereeOffer}`);
} catch (err) {
  if (err instanceof InvitebaseError && err.code === 'invalid_referral_code') {
    showFieldError('That code doesn’t look right — check it and try again.');
  }
}

What's next

On this page