getAttribution()

Retrieve attribution data for this install. Returns cached result if available.

Method Signature#

Mobana.getAttribution<T>(options?: GetAttributionOptions): Promise<AttributionResult<T>>

Usage#

App.tsx
const { status, attribution, error } = await Mobana.getAttribution();

if (status === 'matched' && attribution) {
  console.log('Source:', attribution.utm_source);
  console.log('Campaign:', attribution.utm_campaign);
  console.log('Confidence:', attribution.confidence);
} else if (status === 'no_match') {
  // Organic install — no attribution data
} else {
  // status === 'error'
  if (error?.type === 'sdk_not_configured') {
    // init() was never called
  } else if (error?.type === 'tracking_disabled') {
    // Tracking is disabled (enableTracking: false)
  } else {
    // network/timeout/server issue — SDK will retry on next call
  }
}

Never throws. The returned status field tells you exactly what happened: 'matched' (attribution found), 'no_match' (organic install), or 'error' — which covers network/server failures as well as SDK misconfiguration (sdk_not_configured, tracking_disabled). Check error.type to distinguish them.

With the default autoAttribute: true config, attribution is fetched in the background when init() is called. By the time you call getAttribution(), the result is usually already cached and returns instantly.

Parameters#

ParameterTypeDescription
timeoutnumber= 10000Timeout in milliseconds for the attribution request.
const { status, attribution } = await Mobana.getAttribution({
  timeout: 5000,  // 5 second timeout (default is 10 seconds)
});

Return Value#

Returns an AttributionResult object with three fields:

PropertyTypeDescription
status'matched' | 'no_match' | 'error''matched' — attribution data found. 'no_match' — organic install (no match found). 'error' — network/server failure or SDK misconfiguration; check error.type for details.
attributionAttribution<T> | nullThe attribution object. Only present when status is 'matched'.
errorAttributionError | undefinedError details. Only present when status is 'error'. Contains type ('network' | 'timeout' | 'server' | 'sdk_not_configured' | 'tracking_disabled' | 'unknown') and optional status (HTTP status code for server errors).

The attribution object fields (when status === 'matched'):

PropertyTypeDescription
utm_sourcestring | undefinedTraffic source (e.g., 'facebook', 'google', 'tiktok')
utm_mediumstring | undefinedMarketing medium (e.g., 'cpc', 'social', 'email')
utm_campaignstring | undefinedCampaign name
utm_contentstring | undefinedAd content identifier
utm_termstring | undefinedSearch keywords
referrer_domainstring | undefinedReferring domain that sent the user to the tracking link (e.g., 'facebook.com')
dataT | undefinedCustom deeplink data passed through the redirect URL
confidencenumberMatch confidence score (0.0 - 1.0). 1.0 = deterministic match, <1.0 = probabilistic match.

TypeScript Generics#

Use generics to get type-safe access to your custom deeplink data:

App.tsx
// Define your custom data type
interface MyDeeplinkData {
  promo?: string;
  referrerId?: string;
  productId?: number;
}

// Use generics for type-safe data access
const { status, attribution } = await Mobana.getAttribution<MyDeeplinkData>();

if (status === 'matched' && attribution?.data?.promo) {
  applyPromoCode(attribution.data.promo);  // Type-safe!
}

Understanding Confidence Scores#

The confidence field indicates how certain the attribution match is:

const { status, attribution } = await Mobana.getAttribution();

if (status === 'matched' && attribution) {
  if (attribution.confidence === 1.0) {
    // Deterministic match via Android Install Referrer
    console.log('100% certain this user came from:', attribution.utm_source);
  } else if (attribution.confidence > 0.8) {
    // High confidence probabilistic match
    console.log('Likely came from:', attribution.utm_source);
  } else {
    // Lower confidence - use with caution
    console.log('Possible source:', attribution.utm_source);
  }
}
  • 1.0 (Deterministic): Match via Android Install Referrer. 100% accurate.
  • <1.0 (Probabilistic): Match based on IP address, timezone, screen size, and language. Accuracy depends on signal quality.

Caching Behavior#

  • In-memory cache: Results are cached in memory for instant access on subsequent calls.
  • Persistent cache: Results are also stored in AsyncStorage for app restarts.
  • Idempotent: Multiple calls return the same cached result. The server also caches by install ID.

Call getAttribution() as many times as you need — it's efficient due to caching. You won't incur additional API calls or billing.

Analytics Integration#

App.tsx
const { status, attribution } = await Mobana.getAttribution();

if (status === 'matched' && attribution) {
  // Send to your analytics provider
  Amplitude.setUserProperties({
    'install_source': attribution.utm_source,
    'install_campaign': attribution.utm_campaign,
    'install_medium': attribution.utm_medium,
  });
  
  // Or Mixpanel
  Mixpanel.people.set({
    '$utm_source': attribution.utm_source,
    '$utm_campaign': attribution.utm_campaign,
  });
} else if (status === 'error') {
  // Log to your error tracking (Sentry, Datadog, etc.)
  Sentry.captureMessage('Attribution failed', { extra: error });
}
AI agents: for complete Mobana SDK & API documentation, get full context here or visit llms.txt