Example:
const options = {
devKey: '<AF_DEV_KEY>',
isDebug: true,
};
if (Platform.OS === 'ios') {
options.appId = '123456789';
}
appsFlyer.initSdk(
options,
(result) => {
console.log(result);
},
(error) => {
console.error(error);
}
);
With Promise:
try {
var result = await appsFlyer.initSdk(options);
} catch (error) {}
Accessing AppsFlyer Attribution / Conversion Data from the SDK (Deferred Deeplinking). Read more: Android, iOS
Example of onInstallConversionDataLoaded
:
{
status: 'success',
type: 'onInstallConversionDataLoaded',
data: {
af_status: 'Organic',
af_message: 'organic install',
},
}
Example of onAppOpenAttribution
:
{
status: 'success',
type: 'onAppOpenAttribution',
data: {
af_sub1: 'some custom data',
link: 'https://rndemotest.onelink.me/7y5s/f78c46d5',
c: 'my campaign',
pid: 'my media source',
},
}
The code implementation fro the conversion listener must be made prior to the initialization code of the SDK
Example:
this.onInstallConversionDataCanceller = appsFlyer.onInstallConversionData((data) => {
console.log(data);
});
this.onAppOpenAttributionCanceller = appsFlyer.onAppOpenAttribution((data) => {
console.log(data);
});
appsFlyer.initSdk(/*...*/);
//...
The appsFlyer.onInstallConversionData
returns function to unregister this event listener. Actually it calls NativeAppEventEmitter.remove()
Example:
state = {
appState: AppState.currentState,
};
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}
_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/active|foreground/) && nextAppState === 'background') {
if (this.onInstallConversionDataCanceller) {
this.onInstallConversionDataCanceller();
console.log('unregister onInstallConversionDataCanceller');
}
if (this.onAppOpenAttributionCanceller) {
this.onAppOpenAttributionCanceller();
console.log('unregister onAppOpenAttributionCanceller');
}
}
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
if (Platform.OS === 'ios') {
appsFlyer.trackAppLaunch();
}
}
this.setState({appState: nextAppState});
};
In order to track retargeting and use the onAppOpenAttribution callbacks in iOS, the developer needs to pass the User Activity / URL to our SDK, via the following methods in the AppDelegate.m file:
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
[[AppsFlyerTracker sharedTracker] continueUserActivity:userActivity restorationHandler:restorationHandler];
return YES;
}
// Reports app open from deep link from apps which do not support Universal Links (Twitter) and for iOS8 and below
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation {
[[AppsFlyerTracker sharedTracker] handleOpenURL:url sourceApplication:sourceApplication withAnnotation:annotation];
return YES;
}
// Reports app open from URL Scheme deep link for iOS 10
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
options:(NSDictionary *) options {
[[AppsFlyerTracker sharedTracker] handleOpenUrl:url options:options];
return YES;
}
AppsFlyer enables you to track app uninstalls. To handle notifications it requires to modify your AppDelegate.m
. Use didRegisterForRemoteNotificationsWithDeviceToken to register to the uninstall feature.
Example:
@import AppsFlyerLib;
...
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// notify AppsFlyerTracker
[[AppsFlyerTracker sharedTracker] registerUninstall:deviceToken];
}
Read more about Uninstall register: Appsflyer SDK support site
Updates Firebase device token so it can be sent to AppsFlyer
Example:
appsFlyer.updateServerUninstallToken(newFirebaseToken, (success) => {
//...
});
Read more about Android Uninstall Tracking: Appsflyer SDK support site
This plugin has a demo
project bundled with it. To give it a try , clone this repo and from root a.e. react-native-appsflyer
execute the following:
npm run setup
- Run
npm run demo.ios
ornpm run demo.android
will run for the appropriate platform. - Run
npm run ios-pod
to runPodfile
underdemo
project
Basic code implementation example of implementing the AppsFlyer React-Native plugin in the cross-platform App.js
file:
- Run
npm run demo2.ios
ornpm run demo2.android
will run for the appropriate platform. - Run
npm run ios-pod2
to runPodfile
underdemo2
project