setEnabled()

Enable or disable the SDK dynamically. Useful for GDPR consent flows.

Method Signature#

Mobana.setEnabled(enabled: boolean): void

Usage#

// Disable SDK (e.g., user opts out)
Mobana.setEnabled(false);

// Re-enable SDK (e.g., user opts back in)
Mobana.setEnabled(true);

Parameters#

ParameterTypeDescription
enabledRequiredbooleanWhether the SDK should be enabled (true) or disabled (false).

Behavior#

When disabled:

When re-enabled:

  • • Queued conversions are flushed and sent to the server
  • • Attribution and flows work normally again

GDPR Consent Example#

consent.tsx
// Example GDPR consent flow
async function handleConsentChoice(hasConsent: boolean) {
  if (hasConsent) {
    // User accepted - initialize and enable SDK
    await Mobana.init({ appId: 'a1b2c3d4' });
    Mobana.setEnabled(true);
    
    // Now you can track
    const attribution = await Mobana.getAttribution();
  } else {
    // User declined - disable SDK
    Mobana.setEnabled(false);
  }
  
  // Store consent preference
  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',
    enabled: hasConsent,  // Initialize with consent state
  });
}

You can also pass enabled: false directly to init() to start in a disabled state.

setEnabled() vs init({ enabled })#

  • init() ({ enabled }): Set initial state during SDK initialization.
  • setEnabled(): Change state dynamically after initialization (e.g., when user updates consent).