浏览器支持
- Branch Web SDK需要本机浏览器Javascript,并且已经在所有具有sessionStorage功能的现代浏览器中进行了测试。无需第三方库即可使用SDK,因为它是100%本机Javascript。
Chrome | 火狐浏览器 | 苹果浏览器 | IE浏览器 |
---|---|---|---|
✔ | ✔ | ✔ | 9、10、11 |
Bower或Npm兼容性
- 使用
bower install branch-sdk
或npm install branch-sdk
CommonJS和RequireJS兼容性
- 加
require('branch')
或define(['branch'], function(branch) { ... });
Branch初始化选项
-
您可以传递的属性
branch.initSession()
键 | 值 |
---|---|
branch_match_id | 可选—string 。当前用户的 browser-fingerprint-id。此参数的值应与?branch_match_id(点击链接后由 Branch 自动附加)的值相同。 _仅在由于流中的多个重定向而丢失?_branch_match_id 时才有必要。 |
branch_view_id | 可选 - string 。如果要在激活旅程之前测试旅程在页面上的呈现方式,则可以将此参数的值设置为要测试的视图的ID。 仅在测试与旅程相关的视图时才需要。 |
no_journeys | 可选 - boolean 。如果为true,则防止“journeys”出现在当前页面上。 |
disable_entry_animation | 可选 - boolean 。为true时,将阻止Journeys输入动画。 |
disable_exit_animation | 可选 - boolean 。如果为true,则防止Journeys退出动画。 |
open_app | 可选 - boolean 。是否尝试通过Journeys被动打开应用程序(而不是在用户点击时打开应用程序);默认为false。 |
nonce | 可选 - string 。将在Branch的任何脚本或样式标签中包含的现时值添加到您的网站。用于在内容安全策略中将这些标签列入白名单。 |
测试读取深度链接接
-
用于读取深度链接
-
进行深度链接接重定向到您的网站
https://example.app.link/kJNbhZ1PrF?$fallback_url=https://example.com
- 网站将以
_branch_match_id
打开$fallback_url
https://example.app.link/kJNbhZ1PrF?$fallback_url=https://www.website.com/&_branch_match_id=418480444086051524
- 从该
$fallback_url
网站中读取_branch_match_id
branch.init('key_live_YOUR_KEY_GOES_HERE', function(err, data) {
console.log(err, data);
});
Journey (路径图谱)不坚持导航
-
选择 Journey -> Edit -> Configure Views -> Banner -> Page Placement(Journeys(路径图谱) -> 编辑 -> 配置视图 -> 条幅广告 -> 页面放置)
-
横幅滚动=
sticky
-
新闻资讯
Save & Close
-
在导航中添加以下 div
<div class="branch-journeys-top"></div>
创建调用性用语
- ( 不推荐使用 )建议改用分享深度链接
<a href="#" onclick="branch.deepviewCta()">deep link</a>
<button onclick="branch.deepviewCta()">deep link</button>
var linkData = {
campaign: String(Date.now())
};
var linkOptions = {
make_new_link: false, // don't create a new deep link if one already exists (e.g. _branch_match_id is in the address bar)
open_app: true // will attempt to open the app if install (URI Scheme deep linking only - will not work with Safari)
};
branch.deepview(linkData, linkOptions, function(err, data) {
console.log(err, data);
});
无访问控制错误
- 确保Branch链接在深度链接接和网站内相同
XMLHttpRequest cannot load https://api2.branch.io/v1/open. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 400.
浏览器指纹ID
- 如果您需要访问用户'的浏览器指纹ID来删除用户,请使用以下功能。
branch.getBrowserFingerprintId(function(err, data) { console.log(data); });
违反内容安全政策
- 生成动态随机数值,并将该值作为内容安全政策中的
script-src
和style-src
例外包括在内 - 将相同的值传递给
branch.init()
branch.init(YOUR_BRANCH_KEY, {'nonce': 'GENERATED_NONCE_VALUE' });
Updated 11 months ago
推荐的后续步骤
Web SDK 常见问题解答 |