setTrackingEnabled()
Enable or disable attribution and tracking dynamically. Flows (startFlow, prefetchFlow) are unaffected — they work regardless of tracking consent.
Method Signature#
Mobana.setTrackingEnabled(enabled: boolean): voidUsage#
// Disable tracking (e.g., user opts out)
Mobana.setTrackingEnabled(false);
// Re-enable tracking (e.g., user opts back in)
Mobana.setTrackingEnabled(true);Parameters#
| Parameter | Type | Description |
|---|---|---|
enabledRequired | boolean | Whether attribution and tracking should be enabled (true) or disabled (false). |
Behavior#
When tracking is disabled:
- • getAttribution() returns
{ status: 'error', error: { type: 'tracking_disabled' } } - • trackConversion() is a no-op — conversions are silently dropped, not queued
- • Any conversions pending in the local queue (from before opt-out) are discarded
- • startFlow() and prefetchFlow() work normally — flows are app functionality, not tracking
- • Flow events (view, completion, step tracking) are suppressed — no install ID is sent with flow requests
- • No attribution or conversion network calls are made
When re-enabled:
- • Attribution and conversion tracking resume normally for future events
- • No backfill — conversions that occurred while tracking was disabled are gone
- • Flow events resume being sent (flows were uninterrupted)
Why flows are unaffected
Flows are remote UI — onboarding screens, paywalls, surveys. Disabling them when a user opts out of tracking would break app functionality. Only attribution data collection and conversion tracking are gated behind consent. When tracking is disabled, flow requests omit the install ID so no session data is recorded server-side.
GDPR Consent Example#
consent.tsx
// 1. On app start: initialize with tracking disabled before showing any consent UI.
// autoAttribute: false prevents any network attribution activity until tracking is enabled.
Mobana.init({ appId: 'a1b2c3d4', appKey: 'your-app-key', enableTracking: false, autoAttribute: false });
// Flows work immediately — MobanaProvider can be mounted and startFlow() called
// regardless of consent status.
// 2. Show your consent dialog, then call this with the user's choice
async function handleConsentChoice(hasConsent: boolean) {
// Enable or disable tracking based on user's decision
Mobana.setTrackingEnabled(hasConsent);
if (hasConsent) {
// Attribution is fetched now that tracking is enabled
const { status, attribution } = await Mobana.getAttribution();
}
// Persist the preference so it survives app restarts
await AsyncStorage.setItem('tracking_consent', String(hasConsent));
}Respecting Stored Consent#
App.tsx
// On app start, check stored consent
async function initializeApp() {
const consent = await AsyncStorage.getItem('tracking_consent');
const hasConsent = consent === 'true';
await Mobana.init({
appId: 'a1b2c3d4',
appKey: 'your-app-key',
enableTracking: hasConsent, // Initialize with consent state
});
}You can also pass enableTracking: false directly to init() to start with tracking disabled.
setTrackingEnabled() vs init({ enableTracking })#
- init() ({ enableTracking }): Set initial tracking state during SDK initialization.
- setTrackingEnabled(): Change tracking state dynamically after initialization (e.g., when user updates consent in Settings).
AI agents: for complete Mobana SDK & API documentation, get full context here or visit llms.txt