如何读取 Branch.io 快速链接中的 URL 参数
这应该非常简单,但无法让它工作...
我有 Branch.io 的 Web SDK 实现,如 https://help.branch.io/developers-hub/docs/web-full-reference。我创建了一个快速链接,当用户单击该快速链接时,可以在 JavaScript 中访问 Branch.init()
及其回调 window.branch
。但是,我看不到单击时必须发送的查询参数。
假设我的快速链接是: https://appname.test-app.link/LinkCode?customName=customValue
如何在 JavaScript 中访问 customName
和 customValue
?我已尝试使用 window.branch
但仍然看不到参数。
提前致谢!
This should be quite straightforward but can't get it to work...
I have a web SDK implementation of Branch.io, like in https://help.branch.io/developers-hub/docs/web-full-reference. I have created a quick link and can access the Branch.init()
and its callback, window.branch
, in JavaScript when the quick link is clicked by the user. However, I can't see the query params that must have been sent through at clicking.
Let's say my quick link is:https://appname.test-app.link/LinkCode?customName=customValue
How can I access the customName
and customValue
in JavaScript? I have tried with window.branch
but can't still see the parameters.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以告诉你我是怎么做到的。我不确定这是否是最好/正确的方法,但它对我有用。
要实现此功能,需要两个部分:a) 将数据添加到快速链接上,b) 从快速链接中读取数据。
将数据添加到快速链接
您如何将
customName=customValue
添加到快速链接?它并不像仅将?customName=customValue
添加到快速链接 URL 那样简单(这也是我尝试的第一件事)。相反,您可以使用 Branch 仪表板或 Branch API。
无论哪种方式,您都需要将字段添加到快速链接的数据属性,这是仪表板中快速链接的“链接数据”部分。
建议将包含所需查询参数的 URL 添加到
$canonical_url
字段。然而,我发现使用$custom_meta_tags
字段更容易,它接受序列化的 JSON 字符串。从快速链接读取数据
文档:
所以这对我有用:
I can tell you how I did this. I'm not sure if it's the best/correct way, but it worked for me.
There's two parts to getting this to work: a) getting the data onto the quick link, and b) reading the data from the quick link.
Getting the data onto the quick link
How are you adding
customName=customValue
to the quick link? It's not as simple as just adding?customName=customValue
to the quick link url (that was the first thing I tried, too).Instead, you can use either the Branch dashboard or the Branch API.
Either way, you'll need to add fields to the quick link's data property, which is the "Link Data" part of the quick link in the dashboard.
The recommendation is to add a url with your desired query params to the
$canonical_url
field. I found it easier, however, to use the$custom_meta_tags
field, which accepts a serialised JSON string.Reading the data from the quick link
There's an easy-to-miss line in the docs:
So this works for me:
对于 React JS 应用程序来说,解决方案似乎有点复杂。我的应用程序嵌入在 Cordova 框架中。下面的解决方案可让您捕获由服务器端代码动态生成的 Branch.io 链接。
步骤如下:
解决方案:
希望它可以帮助其他正在寻找解决方案的人!
It seems the solution was a bit more complex in the case of a React JS app. My app is embedded in a Cordova framework. The solution below lets you catch Branch.io links dynamically generated by your server-side code.
Steps to follow:
Solution:
Hope it helps anyone else looking for a solution to this!