[android] Integrated AppsFlyer conversion listener to handle deep link on first launch

This commit is contained in:
Александр Зацепин 2019-04-10 17:42:26 +03:00 committed by yoksnod
parent 882ada89cc
commit fa7ae2e4ae
5 changed files with 95 additions and 6 deletions

View file

@ -92,7 +92,8 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:3.7.0'
// Java concurrency annotations
implementation 'net.jcip:jcip-annotations:1.0'
implementation 'com.appsflyer:af-android-sdk:4.8.7'
implementation 'com.appsflyer:af-android-sdk:4.9.0'
implementation 'com.android.installreferrer:installreferrer:1.0'
implementation ("ru.mail:libnotify:0.1.177-notify-support-v107-sdk-26@aar") {
transitive = true
changing = true

View file

@ -21,6 +21,7 @@
# appsFlyer
-keep class com.appsflyer.** { *; }
-dontwarn com.appsflyer.**
-dontwarn com.android.installreferrer
# myTarget
# Remove this dontwarn when MyTarget is updated to 4.6.15

View file

@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
@ -473,6 +474,7 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
else
{
mAreResourcesDownloaded = true;
mMapTaskToForward = processIntent();
showMap();
}
}
@ -491,6 +493,10 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
if (intent == null)
return null;
MwmApplication application = (MwmApplication) getApplicationContext();
String firstLaunchDeeplink = application.getMediator().retrieveFirstLaunchDeeplink();
if (!TextUtils.isEmpty(firstLaunchDeeplink))
intent.setData(Uri.parse(firstLaunchDeeplink));
MapTask mapTaskToForward;
for (IntentProcessor ip : mIntentProcessors)
{

View file

@ -0,0 +1,26 @@
package com.mapswithme.maps.analytics;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.Map;
class AppsFlyerUtils
{
private AppsFlyerUtils()
{
// Utility class.
}
static boolean isFirstLaunch(@NonNull Map<String, String> conversionData)
{
String isFirstLaunch = conversionData.get("is_first_launch");
return Boolean.parseBoolean(isFirstLaunch);
}
@Nullable
static String getDeepLink(@NonNull Map<String, String> conversionData)
{
return conversionData.get("af_dp");
}
}

View file

@ -7,6 +7,7 @@ import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.text.TextUtils;
import com.appsflyer.AppsFlyerConversionListener;
import com.appsflyer.AppsFlyerLib;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.core.CrashlyticsCore;
@ -32,6 +33,7 @@ import com.my.target.common.MyTargetPrivacy;
import io.fabric.sdk.android.Fabric;
import java.io.IOException;
import java.util.Map;
public class ExternalLibrariesMediator
{
@ -47,6 +49,8 @@ public class ExternalLibrariesMediator
private boolean mEventLoggerInitialized;
@Nullable
private AdvertisingInfo mAdvertisingInfo;
@Nullable
private String mFirstLaunchDeepLink;
public ExternalLibrariesMediator(@NonNull Application application)
{
@ -82,12 +86,9 @@ public class ExternalLibrariesMediator
private void initAppsFlyer()
{
// There is no necessary to use a conversion data listener for a while.
// When it's needed keep in mind that the core can't be used from the mentioned listener unless
// the AppsFlyer sdk initializes after core initialization.
AppsFlyerLib.getInstance().init(PrivateVariables.appsFlyerKey(),
null /* conversionDataListener */);
AppsFlyerLib.getInstance().init(PrivateVariables.appsFlyerKey(), new FirstLaunchDeeplinkListener());
AppsFlyerLib.getInstance().setDebugLog(BuildConfig.DEBUG);
AppsFlyerLib.getInstance().setResolveDeepLinkURLs();
AppsFlyerLib.getInstance().startTracking(mApplication);
}
@ -201,6 +202,60 @@ public class ExternalLibrariesMediator
MyTargetPrivacy.setUserConsent(false);
}
@Nullable
public String retrieveFirstLaunchDeeplink()
{
String firstLaunchDeepLink = mFirstLaunchDeepLink;
mFirstLaunchDeepLink = null;
return firstLaunchDeepLink;
}
private class FirstLaunchDeeplinkListener implements AppsFlyerConversionListener
{
@Override
public void onInstallConversionDataLoaded(Map<String, String> conversionData)
{
if (conversionData == null || conversionData.isEmpty())
return;
for (String attrName : conversionData.keySet())
{
LOGGER.d(TAG, "onInstallConversion attribute: " + attrName + " = "
+ conversionData.get(attrName));
}
if (!AppsFlyerUtils.isFirstLaunch(conversionData))
return;
mFirstLaunchDeepLink = AppsFlyerUtils.getDeepLink(conversionData);
}
@Override
public void onInstallConversionFailure(String errorMessage)
{
LOGGER.e(TAG, "onInstallConversionFailure: " + errorMessage);
}
@Override
public void onAppOpenAttribution(Map<String, String> conversionData)
{
if (conversionData == null || conversionData.isEmpty())
return;
for (String attrName : conversionData.keySet())
{
LOGGER.d(TAG, "onAppOpenAttribution attribute: " + attrName + " = "
+ conversionData.get(attrName));
}
}
@Override
public void onAttributionFailure(String errorMessage)
{
LOGGER.d(TAG, "onAttributionFailure: " + errorMessage);
}
}
private static class GetAdInfoTask extends AsyncTask<Void, Void, AdvertisingInfo>
{
@NonNull