iOS user invite
Overview
Implement and attribute user invite links for when existing users refer others to your app.
For an introduction, see user invite.
Want to see a full example? check out the recipe:
Implement user-invites
Before you begin: Sync with the marketer to find out the exact use cases they want for the links and to get a list of the parameters they want to be implemented.
To implement user invite attribution, complete the following steps:
- Set up invite link generation to generate invite links.
- Optional Log the invite link creation.
- Set up Unified Deeplinking (UDL)
- Optional Retrieve referrer data from user invite links.
- Optional Set up referrer rewards.
The following code is based on the marketer example.
Set up invite link generation
To enable users to invite their friends to your app, you need a way to generate invitation links. This is done using AppsFlyerLinkGenerator
.
To set up invite link generation:
-
Make sure you import
AppsFlyerLib
:import com.appsflyer.AppsFlyerLib;
-
In
AppDelegate
, set a OneLink template usingappInviteOneLinkID
(The template ID is provided by the marketer):AppsFlyerLib.shared().appInviteOneLinkID = "H5hv" // Set the OneLink template ID for userinvitation links
Note
- Make sure to set
appInviteOneLinkID
before callingstart
- The OneLink template must be related to the app.
- Make sure to set
-
Call
AppsFlyerShareInviteHelper.generateInviteUrl
and pass it anAppsFlyerLinkGenerator
and acompletionHandler
:AppsFlyerShareInviteHelper.generateInviteUrl( linkGenerator: { (_ generator: AppsFlyerLinkGenerator) -> AppsFlyerLinkGenerator in generator.addParameterValue(<TARGET_VIEW>, forKey: "deep_link_value") generator.addParameterValue(<PROMO_CODE>, forKey: "deep_link_sub1") generator.addParameterValue(<REFERRER_ID>, forKey: "deep_link_sub2") // Optional; makes the referrer ID available in the installs raw-data report generator.addParameterValue(<REFERRER_ID>, forKey: "af_sub1") generator.setCampaign("summer_sale") generator.setChannel("mobile_share") // Optional; Set a branded domain name: generator.brandDomain = "brand.domain.com" return generator }, completionHandler: { (_ url: URL?) -> Void in if url != nil { NSLog("[AFSDK] AppsFlyer share-invite link: \(url!.absoluteString)") } else { print("url is nil") } } )
Depending on the user flow you and the marketer want to achieve, configure
generator
as follows:- Set attribution parameters using setters.
- Set deep linking parameters, using
AppsFlyerLinkGenerator.addParameterValue
:deep_link_value
: The app experience the referred user should be deep linked into.deep_link_sub1
: A customizable parameter. In this example, used to pass the promo code received by the invitee.deep_link_sub2
: Referrer identifier. Can be used to reward the referrer.
-
In the
completionHandler
, check if the URL was created successfully (url
notnil
), and retrieve the generated user invite link. -
Enable users to share generated links. For example, copy it to their clipboard.
Set the shortlink ID
Optional
The shortlink ID can be determined by the developer, by adding the paramter af_custom_shortlink
to the LinkGenerator
instance.
generator.addParameterValue(<value>, forKey:"af_custom_shortlink")
Log invite link creation events
Optional
To log the invite link creation event:
Send an event indicating that a user has generated an invite link using logInvite
:
AppsFlyerShareInviteHelper.logInvite(<CHANNEL>, parameters: [
"campaign" : "summer_sale",
"referrerId" : <REFERRER_ID>,
]);
logInvite
results in an af_invite
in-app event.
Note
If you don't want to use a channel, you can use
logEvent
instead.
Set up UDL for user invite attribution
Optional
To set up UDL for user invite attribution:
-
Set up Unified Deep Linking (UDL).
-
In
DeepLinkDelegate.didResolveDeepLink
, retrieve the deep linking parameters created during the link generation step. In this example, the following properties are retrieved:deep_link_value
, usingDeepLink.deeplinkValue
deep_link_sub1
, usingDeepLink.clickEvent["deep_link_sub1"]
deep_link_sub2
, usingDeepLink.clickEvent["deep_link_sub2"]
See code: Swift.
-
Once you retrieve the referrer ID, it's up to you how it is stored and used.
Reward referrers
Optional
In the following scenarios, User A invites User B to your app.
Reward referrers on install
Scenario: User B installs your app via User A's invite link.
User A's referrer ID is available in the UDL didResolveDeepLink
(in this example, under DeepLink.clickEvent["deep_link_sub2"]
). Once you retrieve the ID, add it to the list of referrer IDs to be rewarded. It's up to you how to store and retrieve the list.
Reward referrers on in-app events
Scenario: User B makes a purchase. You want to reward User A, who initially referred User B to your app, for the action.
To reward User A for User B's action:
- Retrieve user A's referrer ID and add it to one of the customizble in-app event parameters (for example,
af_param_1
):AppsFlyerLib.shared().logEvent(AFEventPurchase, withValues: [ AFEventParamRevenue: 200, AFEventParamCurrency:"USD", AFEventParam1: <REFERRER_ID> ]);
- On your backend, retrieve in-app event data.
- Add the found referrer IDs to a list of users to be rewarded.
- When User A launches the app, check if their referrer ID is on the list of users to be rewarded and reward them if it is.
Note
- Steps 2-3 are not carried out by the mobile developer. Step 4 depends on how steps 2-3 are implemented.
- A purchase event is just an example. This applies to any type of in-app event.
Updated about 1 month ago