How to implement referral program in mobile Apps for both Android and iPhone

67,750

Solution 1

We are doing a similar type of referral system in our app which provides certain amount of Reward Points to the referrer (one who actually shared the link to app) on successful install of the app by new user (one who received the link).

I will try to explain our implementation using your scenario: So according to your user story:

  • Every new user (E.g John) is given a unique referral link, which he/she can share it to his friends using FB/TW/Email or SMS.

  • When John's friend clicks on the link, he is re-directed first to a Servlet which eventually redirects him to respective AppStore based on his platform (Android/iPhone) to download the app.

  • Note that we can find out the IP address, user agent and device model of the user who clicked the link using a Servlet.

  • We already know that the referral link belongs to John and hence the servlet maps the IP address,user agent and/or device model of John's friend to John's entry in database.

  • The moment John's friend installs the app, and opens the app, the application sends the IP address, user agent and/or device model to the server.

  • The server checks the entry against all the user to find the referrer and if it finds him, in our case John, John gets rewarded accordingly..

Thats it. We implemented this in the last month itself and it does increased our downloads. Let me know if that's helpful.

Solution 2

If anyone is still looking for solution to this question. I read a lot of blogs and documents for the same problem, and arrived at following conclusion:-

IP Address + User Agent + Device Model is not enough to identify a device uniquely. So, I think it will be better to use dynamic links. You can create dynamic links containing a unique id. And that data will survive url redirection to app store and even after installation your app can get the unique id from dynamic link.Google's firebase can be used for creating dynamic links :-

https://firebase.google.com/docs/dynamic-links/

Or if you want to use a ready to use solution then you can refer branch.io

Solution 3

Android

On android you can create an install broadcast listener, where you can get and save the referrer part of the link to SharedPreferences

https://play.google.com/store/apps/details?id=com.example.app&referrer=example_referral_code_here

For this check
Android - Is it possible to get install referrer programmatically
and
Get referrer after installing app from Android Market

and

https://developer.android.com/google/play/installreferrer/library.html

iOS

For now (Jan 2016) It is not possible to get the install referrer code in your app, like with android.

Options i had for ios were:

  1. user frameworks/3rd party services like alau.me
  2. a workaround with fingerprinting, similar to what Puru Pawar suggests
  3. just make the user enter the referral code inside your app

Solution 4

Disclaimer: not being satisfied with the original accepted answer, I'm providing an alternative solution back to this "popular" thread.

On Android, this is not an issue at all. Google will let you access the referrer param sent at install time by registering a receiver, you can also leverage their install referrer API.

For iOS it is a bit trickier as it's not officially supported. As proposed here you can do fingerprinting but that's cumbersome and comes with a high degree of inaccuracy. There are two more elegant solutions I came across:

  1. Cookie based tracking that is explained in details here
  2. URL copied to clipboard (Firebase seems to do both clipboard and cookie approach but that's based on personal observation - no official source).
    • When user visits your webpage (ie: example.com/invite/123), display a web page before redirecting to the App Store.
    • In that page make the user push a button so that you can copy a string to the clipboard/pasteboard with document.execCommand('copy') after having selected some string residing in an hidden input via focus() and setSelectionRange()
    • After install, when the user lands in the app you can do two things:
      1. Catch clipboard/pasteboard content via UIPasteboard.general.string (swift) and do some parsing or API calls
      2. Redirect the user back (via its default browser to avoid Cookies not present) on a page on the same domain as in the initial link (ie: mydomain.com/retrieve) so that the page will receive the initially set cookies (in step 1.) gently shared by the browser upon visit. You can then redirect the user back to your original link as the app is now installed and Universal Linking will now work as intended.

Solution 5

Gradle File

 implementation 'com.android.installreferrer:installreferrer:1.0'

PUT CODE IN ACTIVITY WHERE IT NEED TO RECIEVE REFFERAL CODE

 InstallReferrerClient mReferrerClient;

 mReferrerClient = InstallReferrerClient.newBuilder(this).build();

 mReferrerClient.startConnection(new InstallReferrerStateListener() {
 @Override
 public void onInstallReferrerSetupFinished(int responseCode) {
            switch (responseCode) {
                case InstallReferrerClient.InstallReferrerResponse.OK:
                    // Connection established
                    try {
                        ReferrerDetails response = 
 mReferrerClient.getInstallReferrer();
                        if (!response.getInstallReferrer().contains("utm_source"))
                            edtPRferelCode.setText("" + 
 response.getInstallReferrer());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    mReferrerClient.endConnection();
                    break;
                case 
 InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
                    // API not available on the current Play Store app
                    break;
                case 
 InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
                    // Connection could not be established
                    break;
            }
        }

        @Override
        public void onInstallReferrerServiceDisconnected() {
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
        }
    });

SHARE LINK EXAMPLE

https://play.google.com/store/apps/details?id=com.yourpackage&referrer=9BE46300

Share:
67,750

Related videos on Youtube

James Khoo
Author by

James Khoo

Updated on July 05, 2022

Comments

  • James Khoo
    James Khoo almost 2 years

    We have a mobile app that's available in both Google Play Store and Apple AppStore, we want to implement a referral program to get more users to install and use our App.

    Here's the user story:

    • Every new user (E.g John) is given to a unique referral link, where he/she can share to FB/TW/Email or SMS.
    • When John friend clicks the link, they are directed to respective AppStore base on their device.
    • The moment John's friend install the app and open the app, our server should get notified, and we shall know that the referral is from John, John will be rewarded accordingly.

    We have evaluated a number of Mobile App Install Tracking Tools, most of the tools are the best use in the Publisher/ Mobile Advertisement.

    Appreciate any comments, suggestions

    Cheers James

    • portfoliobuilder
      portfoliobuilder almost 9 years
      Branch.io Metrics might be of use. The documentation is poor but the service is a decent referral code service
    • John Sardinha
      John Sardinha almost 8 years
      @portfoliobuilder I'm trying to implement it but I can't seem to get it right, do you have a working sample? Or perhaps can you take a look at my question? stackoverflow.com/questions/39181681/…
  • James Khoo
    James Khoo about 10 years
    Hi Puru Thanks for your answer, I am interest on the point 3, you are in a way implementing a "device fingerprinting method", but the question is does the IP Address + User Agent + Device Model enough to identify a unique Device?
  • jowie
    jowie almost 10 years
    What happens if the IP address changes? For example, if someone clicked the referral link while on 3G, but runs the app later for the first time on WiFi?
  • Admin
    Admin over 9 years
    Branch - branch.io - has built this solution end to end and give it away for free. They even built a credit rewarding system that allows you to award credits to the referrer and referee based on actions taken by the referrer.
  • acingersoll
    acingersoll almost 9 years
    You can read about fingerprinting accuracy and the edge cases here dev.branch.io/recipes/matching_accuracy -- lets you customize the fingerprinting experience based on how accurate you need it to be (ex. modifying the time before fingerprint expiry). @JamesKhoo
  • Objectif
    Objectif over 7 years
    You can use Firebase as long as you are using Google Sign In for iOS, while you don't need Google Sign in for Android.
  • King Friday
    King Friday over 7 years
    This is awesome to explain this! I thought this wasn't possible to get a direct link in the app store metrics and I was right but this explains how to work around that which is very smart. Thank you so much. You saved my butt.
  • Vishnu Prabhu
    Vishnu Prabhu almost 6 years
    Do you have any sample? can you share if any, please.
  • Chandan Kumar
    Chandan Kumar almost 6 years
    We used branch.io for our solution. That is handled in app side. Firebase documents says that it works only with google login.
  • Vishnu Prabhu
    Vishnu Prabhu almost 6 years
    Can you please, share the link, which says that it will work only with google login. It will help me to convince my manager. Also is Branch.io is free or paid?
  • Chandan Kumar
    Chandan Kumar almost 6 years
    Firebase is working with some corner cases. You can see the docs for more details firebase.google.com/docs/dynamic-links/use-cases/… And branch.io is free upto certain number of users and then it's paid
  • Sharad Paghadal
    Sharad Paghadal almost 6 years
    Do we have any other option as this answer is posted in 2014, there might be better solution provided by apple for app store.
  • monstermac77
    monstermac77 over 5 years
    Does granting points/unlocking content via a referral method not violate Apple's 3.1.1 guideline? They mandate that points, levels, content, etc. only be granted by in-app purchase.
  • Rumit Patel
    Rumit Patel about 5 years
    The simplest answer I found among all. Simple and without any problem. This simply helped me a lot. Thank you.
  • Umar Farooque
    Umar Farooque over 4 years
    It seems firebase is the only known sdk with such capabilities
  • Yogesh Choudhary Paliyal
    Yogesh Choudhary Paliyal about 4 years
    how can i test this