6. Getting Mobile App Installation Source

Via AppsFlyer

If you want to start tracking the source a user installed a mobile app from, for example, to evaluate the efficiency of a promotion campaign, just follow this guide:

  1. Add the AppsFlyer library
  2. Initialize the AppsFlyer SDK.
    Create functions to initialize the AppsFlyer SDK and handle install data:
import appsFlyer from 'react-native-appsflyer';

// ... Some code here

// Function for processing conversion data
const handleConversionData = (data) => {
  console.log('onInstallConversionData data:');
  for (const key in data) {
    if (data.hasOwnProperty(key)) {
      console.log(`${key} : ${data[key]}`);
    }
  }

  const status = data.af_status;
  if (status) {
    if (status === 'Non-organic') {
      const sourceID = data.media_source;
      const campaign = data.campaign;
      console.log(`This is non-organic install. Source: : ${sourceID}  Campaign: ${campaign}`);
    } else {
      console.log('This is an organic install.');
    }

    const isFirstLaunch = data.is_first_launch === 'true' || data.is_first_launch === true;
    if (isFirstLaunch) {
      console.log('First launch of the application.');
    } else {
      console.log('Not the first launch of the application.');
    }
  }
};

// Function for initializing AppsFlyer SDK
const initializeAppsFlyer = () => {
  const options = {
    devKey: 'YOUR_AF_DEV_KEY', // Replace with your AppsFlyer Dev Key (by platform)
    appId: 'YOUR_APP_ID',      // Replace with your app ID (only iOS)
    isDebug: true,
    onInstallConversionDataListener: true,
    timeToWaitForATTUserAuthorization: 3,
  };

  appsFlyer.initSdk(
    options,
    (result) => {
      console.log('AppsFlyer SDK initialized successfully:', result);
    },
    (error) => {
      console.error('AppsFlyer SDK initialization error:', error);
    }
  );

  // Registering conversion data handler
  const onInstallConversionDataCanceller = appsFlyer.onInstallConversionData(handleConversionData);

  return () => {
    onInstallConversionDataCanceller();
  };
};

useEffect(() => {
  const cleanupAppsFlyer = initializeAppsFlyer();

  return () => {
    cleanupAppsFlyer();
  };
}, []);
  1. The received sourceID line must be sent to the custom field of an action in Maestra.
MindboxSdk.executeAsyncOperation({
  operationSystemName: 'sourceID',
  operationBody: {}
})

See React Native AppsFlyer SDK example for more details.

General information

  1. Error 404 indicates an incorrect afDevKey or appID.
  2. Error 403 indicates you’re on the AppsFlyer Zero plan and cannot view installation information.