Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch config plugin doesn't do deferred deep link checkPasteboardOnInstall #251

Open
jvgeee opened this issue Nov 11, 2024 · 8 comments
Open
Labels
bug Something isn't working

Comments

@jvgeee
Copy link

jvgeee commented Nov 11, 2024

Summary

To use deferred deep linking for Branch, you need to use IOS Branch's checkPasteboardOnInstall() method:

IOS SDK instructions: https://help.branch.io/developers-hub/docs/ios-advanced-features#nativelink-deferred-deep-linking

RN Instructions: https://help.branch.io/developers-hub/docs/react-native-advanced-features#nativelink-deferred-deep-linking

I've tried patching these methods into the config plugin but I can't get it to work, would appreciate some help here.

Config Plugin

@config-plugins/react-native-branch

What platform(s) does this occur on?

iOS

SDK Version

No response

Reproducible demo

NA, it's just missing from the list of available methods in the config swift file.

You can see in the Branch docs that for deferred deep linking to work on IOS (using their "nativelink" product), you need to call Branch.checkPasteboardOnInstall() in the IOS setup. This is not happening in the config plugin and not available as part of the SDK, so needs to be enabled to allow for all of Branch's functionality.

@jvgeee jvgeee added the bug Something isn't working label Nov 11, 2024
@IkeyBenz
Copy link

Running into the same issue.

@IkeyBenz
Copy link

@jvgeee After prebuild, I manually updated the development pod like so, ran the project, and got the desired outcome:
Screenshot 2024-11-12 at 4 15 03 PM

Do you know how we can make this "backward compatible" by only running that line based on some config property? Then we can make a PR with the fix

@IkeyBenz
Copy link

@jvgeee I used patch-package to apply that diff for now. Ran an eas build and all works perfectly now. Would be nice for someone more experienced with updating this package to put up a proper PR with it.

@jvgeee
Copy link
Author

jvgeee commented Nov 13, 2024

@IkeyBenz I've done this too, although it's not successfully getting it to work after a build.

image

On my end, I've added RNBranch.branch.checkPasteboardOnInstall() to node_modules/@config-plugins/react-native-branch/ios/ExpoAdapterBranch/BranchAppDelegate.swift, and I've also added this to a patch file for Bun:

image

Which development pod (and which file) are you editing in Xcode? And can you share your patch-package file? I'm obviously doing something wrong so want to get it right!

@jvgeee
Copy link
Author

jvgeee commented Nov 13, 2024

@IkeyBenz Also, are you getting a prompt on install saying [myApp] wants to access your pasteboard or similar? I'm not seeing anything when I install the app so I assume it's not working.

Update: It seems like Branch only runs the pasteboard check on (a) first install, and (b) when there's a branch URI copied to my phone's clipboard.

The missing piece for me seems to be that on my deep link's custom webpage, I need to be copying the branch URI to the phone's clipboard.

The next issue is that I have no way to read the URI on the clipboard, Branch isn't properly "receiving" it and it's not in firstReferringParams or latestReferringParams...

@jvgeee
Copy link
Author

jvgeee commented Nov 13, 2024

I just spoke to Branch support (they're terrible) and after over a month they told me that you're meant to enable it by adding a branch.json file with checkPasteboardOnInstall: true in it.

I had to google around and found this: https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/blob/master/docs/branch.json.md

Don't know how to get a branch.json file linked in with the Branch SDK via an expo config plugin though

@IkeyBenz
Copy link

IkeyBenz commented Nov 13, 2024

Here's my patch file:
(generated by using patch-package after manually adding that line)
Screenshot 2024-11-13 at 10 13 11 AM

some notable differences:

  1. I'm using v7.0.0, doubt that makes a difference that matters but worth confirming
  2. My diff path is relative to my node modules folder, because it patches the node module itself since my project is managed by expo and I rarely interact (or even have generated) the native iOS files

It seems like Branch only runs the pasteboard check on (a) first install

I'm not seeing anything when I install the app so I assume it's not working.

Yes, this is what I needed for my use case. You're right it's probably not working if it's not showing you that prompt. You need to enable native link in Branch's configuration tab https://dashboard.branch.io/configuration/general

Screenshot 2024-11-13 at 10 16 34 AM
This makes it so that when a user clicks your Branch link, if they don't have the app installed, it'll take them to an interstitial web screen that offers them a UI to copy the link to clipboard and go to the App Store. Then upon install it should try to read from it once you ask for Branch.getFirstReferringParams.

The next issue is that I have no way to read the URI on the clipboard, Branch isn't properly "receiving" it and it's not in firstReferringParams

So I have this fun code snippet from two years ago when Apple started asking people if they want to allow pasting from clipboard, before enabling Branch to read from it. That prompt was async causing my on-first-install attribution logic to mistakenly call Branch.getFirstReferringParams before it had access to the clipboard. Here is the snippet I used to make it wait for clipboard permissions prior to calling Branch.getFirstRefferingParams:

/**
 * This is a hack to delay our attribution handler by the amount of time it
 * takes the user to press "yes" on the iOS 16 prompt to enable clipboard pasting
 * in our app. Otherwise attribution info doesn't get recorded until subsequent app open.
 */
const waitForiOS16Paste = () => {
  return isFirstAppInstall().then((isFirstInstall) => {
    const timeout = () => new Promise((res) => setTimeout(res, 2000));
    if (isFirstInstall) {
      if (Platform.OS !== 'ios') {
        return timeout();
      }

      // on iOS, we want to wait until we have ability to read from their clipboard
      // before proceeding
      return Clipboard.hasString()
        .then((hasString: boolean) => {
          if (hasString) return Clipboard.getString();
        })
        .catch(() => {})
        .finally(() => timeout());
    }
  });
};

const isFirstAppInstall = () => {
  const key = 'IS_FIRST_APP_INSTALL' as const;
  return settings
    .get<boolean>(key)
    .then((val) => {
      if (val === null) {
        return settings.set(key, false).then(() => {
          return true; // must be first app install if this was never set
        });
      }
      return false;
    })
    .catch(() => false);
};

Notes:

  • I haven't verified that this is still required in the later versions, maybe Branch does this automatically now
  • settings is just a wrapper for async storage

@chrisbmar
Copy link

Here's my patch file: (generated by using patch-package after manually adding that line) Screenshot 2024-11-13 at 10 13 11 AM

This worked for me using patch-package, and I'm being prompted in the sim to allow the pasting and then redirected correctly to the deeplink. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants