» » In-app invite personalization using AppsFlyer

In-app invite personalization using AppsFlyer

Everyone who has built user interaction with the application knows what a difficult process it is. One of the mechanisms of such interaction is Deep Linking. Push notifications, user acquisition and retention depend on its work.

Next, I’ll talk about some of the AppsFlyer tools and their use using the example of a feature for inviting users, which will help make registration more personalized.

SDK integration and getting attribution

AppsFlyer is a mobile traffic attribution and analytics platform with many paid and free services. To implement the feature of inviting to the application, we will use attribution after installation and a tool for creating short links.

First of all, we integrate the SDK into the project - the documentation has detailed instructions.

After integration, you can check how attribution comes after installation. To do this, add a onConversionDataSuccesssimple log to the method.

override fun onConversionDataSuccess(map: MutableMap<String, Any>?) {
Timber.d("Attribution - ${map ?: "empty"}")  if (map.isNullOrEmpty()) {  return  }  //handle attribution here

After that, on the test device, you need to open a specially generated link . Since the application is not installed on the smartphone, it will be redirected to the store for installation.

Most likely, after installation and launch, “Attribution - empty” will be displayed. There may be several reasons for this:
  1. The project is set up incorrectly in AppsFlyer.
  2. The package name is different from the one used in AppsFlyer, for example if you use an extra suffix for debug builds.
  3. Your device is not added to the test.

If everything is done correctly, then attribution will come from AppsFlyer, it looks something like this (for clarity, I filtered out empty values through debbuger):


Approximately such data lies inside map. There are a lot of interesting things here, for example, the http_referrer field shows where the link came from, and is_first_launch can be used to track the first launch. 

Now the af_dp field is the most important - it receives information about the content of the link, in a particular case, this is a meme with id - hSPRMKbU8. We use this id to make opening the application more organic - with this transition, the meme will be the first in the feed.

It seems that everything is fine, but there are pitfalls.

  1. Installation data will be received each time the application is launched. This is a small safety net in case the attribution fails the first time around. Therefore, if you have logic that should work only on the first run, it is worth supporting it separately. For example, through a flag in prefs or any other mechanism.
  2. The time that elapses from application launch to method call can vary, especially on first run. On test runs, it varied from 2 to 15 seconds. If the code in the method does not affect the UI, then this is not a problem, but if you need to collect a screen based on attribution, everything gets worse. There is no good solution here, because each of them will block the user for some time after the application starts, or they are difficult to implement. 

So, now we can get information about the installation, great! Don't forget to please analysts with this data.

short link service

Analytics shows that short links are most likely to be opened. Perhaps this is due to the fact that for ordinary people the parameters in the link look scary and incomprehensible. Probably, short links look more organic on the screen due to the lack of hyphenation, but the fact remains that short links are preferable for our users. 

AppsFlyer already has an API for generating such links, but it's not free. Do not give up if you are not ready to pay, there is an analogue in the SDK for clients. Its name is LinkGenerator .

with(generator) {  setReferrerName("user nick")  setReferrerUID("user unique id")  setReferrerImageURL("user avatar url")  addParameter("is_retargeting", true.toString())  addParameter("af_dp", "link for content in application")  addParameter("af_web_dp", "additional link for web page")  generateLink(context, listener)
}

Now, when you click on a short link, you will be redirected to the site, then to Google Play, and finally to the application.

It seems to work, but let's try to open the link on a device with an installed application. The whole chain of transitions will repeat again - it does not look very beautiful, it would be great to open links immediately through the application. It turns out that this can also be done.

First, you need to add the appropriate intent-filter to your application manifest.

<intent-filter anroid:autoVerify="true">  <action android:name="android.intent.action.VIEW" />  <category android:name="android.intent.category.DEFAULT" />  <category android:name="android.intent.category.BROWSABLE" />  <data android:scheme="https"        android:host="${oneLinkAppHost}"        android:prefix="/${oneLinkPathPrefix}" />
</intent-filter>

Secondly, handling the link in the onAppOpenAttribution method. All data that was closed by a short link will come here.

override fun onAppOpenAttribution(map: MutableMap<String, String>?) {  if (map.isNullOrEmpty()) {    return  }  val data = AppsFlyerConversionAttrs.init(map as Map<String, Any>)  if (!TextUtils.isEmpty(data.afDeeplink)) {    handleDeeplink(data.afDeeplink)  }
}

Since the participation of the server is required, there is also a delay in receiving data, but unlike the onConversionDataSuccess method, it is not as significant. 

Feature to invite new users

Now we are ready to implement the feature from the beginning of the article. In a simplified form, it looks like this: the client must be able to create special invitation links containing data about the client. This data should be used on new installations to display a special personalized login screen. 

After decomposition, we obtain two subtasks:

  1. Creation and sharing of invitation links.
  2. Handling invitation links after installation.

Let's go in order. In fact, we already have everything we need to create an invitation link. We add data about the user who fumbles the link: his id, name and avatar.

private val inviteLinkPlaceholder = "Click this link to add %1$s as friend"

private val listener = object : CreateOneLinkHttpTask.ResponseListener {  override fun onResponse(inviteLink: String?) {    if (!TextUtils.isEmpty(inviteLink)) {      generatedLinkSubject.onNext(String.format(inviteLinkPlaceholder,                                                 authSessionManager.authSession.nick,                                                inviteLink))    } else {      generatedLinkSubject.onNext("")    }  }    override fun onResponseError(p0: String?) {    generatedLinkSubject.onNext(p0 ?: "")  }
}

fun generate(content: Content): Observable<String> {    generatedLinkSubject = PublishSubject.create()  with(generator) {    setReferrerName(authSessionManager.authSession.nick)    setReferrerUID(authSessionManager.authSession.uid)    setReferrerImageURL(authSessionManager.authSession.photoUrl)    addParameter("is_retargeting", true.toString())    addParameter("af_dp", content.link)    addParameter("af_web_dp", content.webLink)    generateLink(context, listener)  }  return generatedLinkSubject
}

The finished link with text for sharing looks like this: Click this link to add Rick_Rick as friend in ABPV https://abpv.onelink.me/nWMv/344e6258 , all that remains is to transfer it to sharing.

Great, the link has gone free floating, now anyone who installs the app after the transition will be considered an invitee and will automatically follow the author of the link.

Now you can implement the second part with support for post-install prompts.

Let's add the processing of invitation links to the onConversionDataSuccess method. They can be distinguished from regular links by the media_source field, which should contain the af_app_invites value.

if (data.afMediaSource == "af_app_invites") {    //handle data from invite link  onInstallationAttributionSubject.onNext(ACTION_PERFORMED) }

Further, the data is passed to onInstallationAttributionSubject, the state of the invitation screen changes depending on the value of this subject.


Conclusion 

The described case is quite simple, but it can be used to make registration more personalized, which, with the right approach and audience, can increase conversion.

This example can be used as a foundation for the further development of a full-fledged referral system, or come up with something else.
In addition to short links and post-install attribution, AppsFlyer provides a lot of other tools, such as fraud protection or audience management, but that's another story.

Related Articles

Add Your Comment

reload, if the code cannot be seen

All comments will be moderated before being published.