I get the error
Sending
onInstallConversionDataLoadedwith no listeners registered
when trying to unmount the InstallConversion listener from AppsFlyer. Here is my code:
import React, { useEffect } from 'react';
import appsFlyer from 'react-native-appsflyer';
import NonRenderOnChangeData from '../nonRenderOnChangeData/NonRenderOnChangeData';
import { useFocusEffect } from '@react-navigation/native';
function AppsFlyerHandler({ navigation }) {
useFocusEffect(() => {
// Configure listeners before initializing SDK
const onInstallConversionDataCanceller = appsFlyer.onInstallConversionData(
(res) => {
console.log("res", res);
if (JSON.parse(res.data.is_first_launch) == true) {
if (res.data.af_status === 'Non-organic') {
if (NonRenderOnChangeData.userIsEligableForCampaign()) {
this.props.navigation.navigate('LoadingPage', {entitlementID: res.data.campaign});
}
console.log('This is first launch and a Non-Organic install. Media source: ' + media_source + ' Campaign: ' + campaign);
} else if (res.data.af_status === 'Organic') {
console.log('This is first launch and a Organic Install');
}
} else {
console.log('This is not first launch');
}
}
);
const onAppOpenAttributionCanceller = appsFlyer.onAppOpenAttribution((res) => {
if ("deep_link_value" in res.data) {
if (NonRenderOnChangeData.userIsEligableForCampaign()) {
this.props.navigation.navigate('LoadingPage', {entitlementID: res.data.deep_link_value});
}
}
});
// Initialize AppsFlyer here
appsFlyer.initSdk(
{
devKey: 'xxxxxxxx',
isDebug: true,
appId: 'xxxxxxx',
onInstallConversionDataListener: true,
},
(result) => {
console.log("AppsFlyer Init",result);
},
(error) => {
console.error("AppsFlyer Init",error);
}
);
return () => {
onInstallConversionDataCanceller();
onAppOpenAttributionCanceller();
};
});
return null;
}
export default AppsFlyerHandler;
I have tried following all guides and documentation but still seem to get this warning no matter how I do it. I have tried to remove the listener the same way as the documentation, like down below, but still get the same warning. Does anybody know a solution?
if (onInstallConversionDataCanceller) {
onInstallConversionDataCanceller();
console.log('unregister onInstallConversionDataCanceller');
onInstallConversionDataCanceller = null;
}
if (onAppOpenAttributionCanceller) {
onAppOpenAttributionCanceller();
console.log('unregister onAppOpenAttributionCanceller');
onAppOpenAttributionCanceller = null;
}
If you actually want to disable this feature and you want the yellow warning to go away, you can set the
initSdkoptionsoptiononInstallConversionDataListenertofalselike so:You can also probably learn a lot more about this from the demo app: https://github.com/AppsFlyerSDK/appsflyer-react-native-plugin/blob/df985ace2f67f829811880a3a971ad6352d4272c/demos/appsflyer-react-native-app/components/AppsFlyer.js