BranchMetrics / cordova-ionic-phonegap-branch-deep-linking-attribution

The Branch Cordova Ionic Phonegap SDK for deep linking and attribution. Branch helps mobile apps grow with deep links / deeplinks that power paid acquisition and re-engagement campaigns, referral programs, content sharing, deep linked emails, smart banners, custom user onboarding, and more.
https://docs.branch.io/apps/cordova-phonegap-ionic/
MIT License
234 stars 144 forks source link

Apple search Ads on Cordova 9 #641

Closed cordovian22 closed 4 years ago

cordovian22 commented 4 years ago

The problem is that we don't see any data on Apple search Ads dashboard.

node: v10.16.3 cordova: 9.0.0 xcode: 11.3.1

The plugin version is 4.1.3 but with the following changes in order to be able to build with CLI:

Removed from: src/ios/BranchNPM.h #define BRANCH_NPM true

And added at plugin.xml and from xcode after building the framework is there <framework src="iAd.framework" weak="true"/>

I tried both with and without use-frameworks="true" with no difference.

The Branch service initialisation: function init() { return $window.Branch.delayInitToCheckForSearchAds() .then($window.Branch.initSession).then(linkHandler); }

Sebschock commented 4 years ago

@cordovian22 did you find a solution?

echo-branch commented 4 years ago

Sorry for not commenting on this earlier. I somehow didn't see the original issue report.

The issue is that JS starts up too late to check for ASA, so the JS level api for apple search ads always fails. The workaround is to make the call at the native code layer. We should have marked this API as deprecated and a noop.

BranchJShek commented 4 years ago

This method has since been deprecated from our SDK following the note above. Please reach out to support@branch.io if you have any questions.

romandrahan commented 3 years ago

@echo-branch, @BranchJShek, is the any example of calling delayInitToCheckForSearchAds() from native code in Cordova/Ionic app?

echo-branch commented 3 years ago

Within Xcode, you can locate an AppDelegate.m file. You can enable early lifecycle calls here.

In this example, I enable logging to confirm ASA is working, remove it for production as it is very verbose. I then enable search ads and the longer delay as Cordova has a long launch time.

#import "AppDelegate.h"
#import "MainViewController.h"
#import "Branch.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    [Branch.getInstance enableLogging];
    [Branch.getInstance delayInitToCheckForSearchAds];
    [Branch.getInstance useLongerWaitForAppleSearchAds];

    self.viewController = [[MainViewController alloc] init];
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end

You should see the Search Ad base 64 encoded in the install json. On test devices, Apple provides a test payload so you should always see this while debugging.

"search_ad_encoded" = "eyJWZXJzaW9uMy4xIjp7ImlhZC1wdXJjaGFzZS1kYXRlIjoiMjAyMS0wMS0yMlQxODozMDozNVoiLCJpYWQta2V5d29yZCI6IktleXdvcmQiLCJpYWQtYWRncm91cC1pZCI6IjEyMzQ1Njc4OTAiLCJpYWQtY3JlYXRpdmVzZXQtaWQiOiIxMjM0NTY3ODkwIiwiaWFkLWNyZWF0aXZlc2V0LW5hbWUiOiJDcmVhdGl2ZVNldE5hbWUiLCJpYWQtY2FtcGFpZ24taWQiOiIxMjM0NTY3ODkwIiwiaWFkLWxpbmVpdGVtLWlkIjoiMTIzNDU2Nzg5MCIsImlhZC1vcmctaWQiOiIxMjM0NTY3ODkwIiwiaWFkLWNvbnZlcnNpb24tZGF0ZSI6IjIwMjEtMDEtMjJUMTg6MzA6MzVaIiwiaWFkLWtleXdvcmQtaWQiOiIxMjMyMzIyMiIsImlhZC1jb252ZXJzaW9uLXR5cGUiOiJEb3dubG9hZCIsImlhZC1jb3VudHJ5LW9yLXJlZ2lvbiI6IlVTIiwiaWFkLW9yZy1uYW1lIjoiT3JnTmFtZSIsImlhZC1jYW1wYWlnbi1uYW1lIjoiQ2FtcGFpZ25OYW1lIiwiaWFkLWNsaWNrLWRhdGUiOiIyMDIxLTAxLTIyVDE4OjMwOjM1WiIsImlhZC1hdHRyaWJ1dGlvbiI6InRydWUiLCJpYWQtYWRncm91cC1uYW1lIjoiQWRHcm91cE5hbWUiLCJpYWQta2V5d29yZC1tYXRjaHR5cGUiOiJCcm9hZCIsImlhZC1saW5laXRlbS1uYW1lIjoiTGluZU5hbWUifX0=";

If you wish to ignore the Apple test payload call this method.

[Branch.getInstance ignoreAppleSearchAdsTestData];
felipeclopes commented 3 years ago

@echo-branch how does this helps getting the data in Branch dashboard? Does it transfer the parameters to the Cordova app?

echo-branch commented 3 years ago

This works by setting the Branch SDK to lookup Apple Search Ads before the install event. This will ensure we have it show up properly on the dashboard, we also return it in the callback to the JS code.

This is not possible from JS alone, cause the Cordova JS environment starts up after the initial install. Which means we probably sent the install without the ASA data payload.