在应用程序安装后使用带有 react-native 的分支引用识别发件人

Posted

技术标签:

【中文标题】在应用程序安装后使用带有 react-native 的分支引用识别发件人【英文标题】:Identify the sender after the app installation with branch referrals with react-native 【发布时间】:2020-06-04 06:33:03 【问题描述】:

在我的 React-Native 应用程序中,我使用 branch.io 来处理引用。深层链接通过应用成功生成,并可以分享给其他人。

问题是,如果接收者还没有安装应用,一旦收到动态链接,点击后,他会去appstore/playstore安装应用。

安装后,我想识别深层链接的发件人。我的订阅分支是这样的。

BranchIO.subscribe(async ( error, params ) => 
    if (error) 
      console.log('Error from Branch: ', error);
      return;
    

    if (params['+non_branch_link']) return;

    if (!params['+clicked_branch_link']) return;

    if (params.$canonical_identifier === DeepLinkTypes.referral) 
      store.dispatch(setReferralKey(params.referralKey));
    

    const lastParams = await BranchIO.getLatestReferringParams(); 
    const installParams = await BranchIO.getFirstReferringParams(); 

    console.log(lastParams);
    console.log(installParams);

    navigatePath(params.$deeplink_path);
  );

在新安装应用程序后,我应该如何访问这些参数?我的意思是,一旦接收者点击链接并进入 playstore/appstore,分支会跟踪吗?加载完成后的应用程序,我们是否应该通过参数访问相关数据?

【问题讨论】:

【参考方案1】:

是的,Branch 支持延迟深度链接。对于 React Native,您可以像这样读取参数 - \

branch.subscribe((error, params, uri) => 
if (error) 
console.error('Error from Branch: ' + error)
return


// params will never be null if error is null
)

let lastParams = await branch.getLatestReferringParams() // params from last open
let installParams = await branch.getFirstReferringParams() // params from original install

确保在调用 branch.subsribe() 后获得参数。这是相同的文档 - https://help.branch.io/developers-hub/docs/react-native#section-read-deep-link

【讨论】:

但是 installParams 不包含我设置的属性。只有参数有。所以如果我应该使用 installParams,我如何在没有我设置的属性的情况下唯一标识发件人?

以上是关于在应用程序安装后使用带有 react-native 的分支引用识别发件人的主要内容,如果未能解决你的问题,请参考以下文章

在 React-Native 应用程序中使用带有授权标头的 Axios GET

将 react-native 添加到 monorepo 后,React apollo hooks 失败

带有 react-native 的编程式屏幕触摸

使用 react-native 在 iOs 上处理同一个应用程序的多个环境的深层链接

React-Native 将标题从 Navigator 传递到 NavigatorIOS

React-native:如何在 React-native 中使用(和翻译)带有 jsx 的 typescript .tsx 文件?