如何在 React.js Cordova 应用程序上调用 Branch 侦听器

发布于 2025-01-14 03:09:18 字数 343 浏览 0 评论 0原文

我正在 Cordova 框架中使用 React.js 应用程序。

由于文档不太清楚,我想了解如何在我的应用程序中调用 Branch.io 侦听器,以便我可以捕获单击 Branch.io 链接的位置、由谁单击以及单击的确切 URL。必须有一种方法可以从 React 本身调用 Branch.io 事件(否则,你如何监听应用程序内部的事件?)。我在我的 index.js 文件中尝试了以下内容,但没有成功,因为 React 应用程序的构建失败(因为 cordova 仅在运行时可用)。

从“branch-cordova-sdk”导入{Branch}

任何帮助将不胜感激!提前致谢!

I am using a React.js app in a Cordova framework.

As the docs are not really clear, I would like to understand how to call a Branch.io listener in a my app, so that I can capture where the Branch.io link was clicked, by whom and what exact URL was clicked. There must be a way to call the Branch.io events from React itself (otherwise, how can you be listening to the event inside the app?). I tried the following in my index.js file but was not successful because the build of the React app failed (as cordova is only available during runtime).

import {Branch} from "branch-cordova-sdk"

Any help would be appreciated! Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悸初 2025-01-21 03:09:18

对于到达此页面的其他人:

如果您尝试在 React.js 应用程序(非 React Native)中生成和访问 Branch.io 的分支,并且您已将其嵌入到 Cordova 应用程序中,则必须遵循以下文档:< a href="https://help.branch.io/developers-hub/docs/web-basic-integration" rel="nofollow noreferrer">https://help.branch.io/developers-hub/docs/web -基本集成

作为快速要点:

  1. 您必须在 index.html 文件中调用分支,如文档中所述:
<!doctype html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <script>
    // load Branch
    (function(b,r,a,n,c,h,_,s,d,k){if(!b[n]||!b[n]._q){for(;s<_.length;)c(h,_[s++]);d=r.createElement(a);d.async=1;d.src="https://cdn.branch.io/branch-latest.min.js";k=r.getElementsByTagName(a)[0];k.parentNode.insertBefore(d,k);b[n]=h}})(window,document,"script","branch",function(b,r){b[r]=function(){b._q.push([r,arguments])}},{_q:[],_v:1},"addListener applyCode autoAppIndex banner closeBanner closeJourney creditHistory credits data deepview deepviewCta first getCode init link logout redeem referrals removeListener sendSMS setBranchViewData setIdentity track validateCode trackCommerceEvent logEvent disableTracking".split(" "), 0);
    // init Branch
    branch.init('key_live_YOUR_KEY_GOES_HERE');
  </script>
</head>
<body>
</body>
</html>
  1. 然后,在您的 React.js 应用程序上,直接添加分支侦听器:
    function onResume() {
      let branch = window.branch;
      // Whatever else you want to do when you receive your branch information.
    }

只需定义您的内容想要从那里开始处理你的分支。

For anybody else arriving at this page:

If you are trying to generate and access branches from Branch.io in your React.js app (not React native) and you have embedded it into a Cordova app, you have to follow these documentation: https://help.branch.io/developers-hub/docs/web-basic-integration

As quick bullet points:

  1. You have to call the branch in your index.html file, as mentioned in the docs:
<!doctype html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <script>
    // load Branch
    (function(b,r,a,n,c,h,_,s,d,k){if(!b[n]||!b[n]._q){for(;s<_.length;)c(h,_[s++]);d=r.createElement(a);d.async=1;d.src="https://cdn.branch.io/branch-latest.min.js";k=r.getElementsByTagName(a)[0];k.parentNode.insertBefore(d,k);b[n]=h}})(window,document,"script","branch",function(b,r){b[r]=function(){b._q.push([r,arguments])}},{_q:[],_v:1},"addListener applyCode autoAppIndex banner closeBanner closeJourney creditHistory credits data deepview deepviewCta first getCode init link logout redeem referrals removeListener sendSMS setBranchViewData setIdentity track validateCode trackCommerceEvent logEvent disableTracking".split(" "), 0);
    // init Branch
    branch.init('key_live_YOUR_KEY_GOES_HERE');
  </script>
</head>
<body>
</body>
</html>
  1. Then, on your React.js app, add the branch listener directly:
    function onResume() {
      let branch = window.branch;
      // Whatever else you want to do when you receive your branch information.
    }

Just define what you want to do with your branch from there onwards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文