Search code examples
androidinstall-referrer

How to confirm if application has been installed from deeplink / referlink?


I'd like to know if there is a way maybe with firebase or appsFLyer etc or natively to know if user came from a deeplink and installed my application is there a way to know the deeplink ?

Basically i'd like an intent passed to me after the user installs the app from the play store (assuming the user got to the play store from a deepLink or some referer link).

Lets imagine the user did not have my automobile app but saw an ad about cars that i had put up. he then clicks that ad and is directed to install my app. after installing my app i'd like the user to see the car they were looking at initially in the ad.


Solution

  • Good example was described in that post

    You have to create specific BroadcastReceiver

    Add in Manifest:

    <receiver android:name="your.package.InstallListener" android:exported="true">
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>
    

    and create BroadcastReceiver class which will catch deeplink

    public class InstallListener extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            String rawReferrerString = intent.getStringExtra("referrer");
            if (rawReferrerString != null) {
                Log.i("MyApp", "Received the following intent " + rawReferrerString);
            }
        }
    }
    

    And add referrer parameter to url using js like this:

    var fallbackFunction = function() {
        window.location.replace('market://details?id=io.branch.testbed&referrer=specialparam');
    };
    var addIFrame = function() {
        var iframe = document.createElement("iframe");
        iframe.style.border = "none";
        iframe.style.width = "1px";
        iframe.style.height = "1px";
        iframe.src = 'your_uri_scheme://';
        document.body.appendChild(iframe);
    };
    addIFrame();
    setTimeout(fallbackFunction, 250);
    

    By the way if that method does not work you can try to get specific parameter of phone in js (like vendor, model, etc) and save it in cloud database like firebase. Then after user installed application (PACKAGE_INSTALLED BroadcastReceiver or just first launch) you can check database for last data for his specific parameter and get his deeplink. If you dont have too much users that will work correctly enough.