mustafasencer
mustafasencer

Reputation: 773

Facebook deferred deep linking not working when ad preview is clicked

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="sensorLandscape">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>


        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <!-- Accepts URIs that begin with "memoryc://cerebrotrial” -->
            <data
                android:host="cerebrotrial"
                android:scheme="memoryc" />
        </intent-filter>

    </activity>

When I test my ad from the Ad Helper in Facebook, the deferred link is successfully transmitted. But when I click the ad preview from the Facebook app, the deferred deep link is null. I try to catch the deep-link with the below implementations. I first try to get the deep link from the AppLinkData, then from the most basic getIntent() implementation and finally by the bolts.Applinks. The ApplinkData is null, the intent does not return anything and the targetUrl is null.

    // Suggested Facebook implementation
    FacebookSdk.setAutoInitEnabled(true);
    FacebookSdk.fullyInitialize();
    AppLinkData.fetchDeferredAppLinkData(this,
            new AppLinkData.CompletionHandler() {
                @Override
                public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
                    // Process app link data
                    if (appLinkData != null) {
                        ConfigAPI.setRefererURL(appLinkData.getTargetUri().toString());
                        JsonObject jsonParams = ConfigAPI.getPayLoad();
                        new CallAPI(jsonParams).execute();
                    }
                }
            }
    );


    //persist deep link data
    Intent intent = getIntent();
    Uri data = intent.getData();
    if (data != null) {
        Log.i("DEEP LINK", data.toString());
        ConfigAPI.setRefererURL(data.toString());
        JsonObject jsonParams = ConfigAPI.getPayLoad();
        new CallAPI(jsonParams).execute();
    }

    // using the bolts.Applinks
    Uri targetUrl = AppLinks.getTargetUrlFromInboundIntent(this, getIntent());
    if (targetUrl != null) {
        ConfigAPI.setRefererURL(targetUrl.toString());
        JsonObject jsonParams = ConfigAPI.getPayLoad();
        new CallAPI(jsonParams).execute();
    }

Upvotes: 2

Views: 947

Answers (1)

avinash pandey
avinash pandey

Reputation: 1381

I know I am super late to answer but was facing the same issue and finally figured out a way to solve.

  1. In your facebook ad manager select the ad which you want to test and then click on the preview option. enter image description here
  2. In the preview box that will appear click on Share.

enter image description here 3. Then click on Facebook mobile feed

enter image description here

Now if you will open the facebook app with same account as the one you are using for ad manager and refresh your feed you will be able to see your ad. If you click on this ad deferred link will work as intended.

Upvotes: 0

Related Questions