Connected Advanced Features
初始化 Branch 功能
- 将 Branch 加载到您的应用中
- Uses Branch init options
const options = {
advertising_ids: {
SAMSUNG_IFA: 'xxxxx',
},
branch_match_id: 'xxxxx'
};
branch.init('key_live_YOUR_KEY_GOES_HERE', options, function (err, data) {
console.log(err, data);
});
- Returns the following inside the
data
object
Key | 值 | 类型 |
---|---|---|
data_parsed | 如果用户是从链接引荐过来的,并且该链接具有关联数据,则数据就传送到这里。 | object |
has_app | Does the user have the mobile app installed already, using Branch's persona data. | bool |
身份 | Unique string that identifies the user, if set from setIdentity | string |
referring_link | 点击引用链接(如果可用)。 | string |
referring_identity | 如果用户是从链接引荐过来的,并且该链接由具有身份的用户创建,则该身份就在此处。 | string |
创建深度链接
- 创建带有封装数据的深度链接 URL
- Uses Deep Link Properties
- Validate with the Branch Dashboard
const linkData = {
campaign: 'content 123',
channel: 'facebook',
feature: 'dashboard',
stage: 'new user',
tags: [ 'tag1', 'tag2', 'tag3' ],
alias: '',
data: {
'custom_bool': true,
'custom_int': Date.now(),
'custom_string': 'hello',
'$og_title': 'Title',
'$og_description': 'Description',
'$og_image_url':'http://lorempixel.com/400/400'
}
};
branch.link(linkData, function(err, link) {
console.log(link);
});
分享深度链接
- 生成 Branch 深度链接,并通过用户选择的渠道对其进行标签
- Uses Deep Link Properties
<!-- shareable elements -->
<button id="button">deep link</button>
<a id="anchor" href="#">deep link</a>
const linkData = {
campaign: 'content 123',
channel: 'facebook',
feature: 'dashboard',
stage: 'new user',
tags: [ 'tag1', 'tag2', 'tag3' ],
alias: '',
data: {
'custom_bool': true,
'custom_int': Date.now(),
'custom_string': 'hello',
'$og_title': 'Title',
'$og_description': 'Description',
'$og_image_url':'http://lorempixel.com/400/400'
}
};
branch.link(linkData, function(err, link) {
// bind elements
document.getElementById('button').onclick = function() {
window.open(link || err);
};
document.getElementById('anchor').href = link || err;
});
读取深度链接
- 从深度链接中提取 Branch 数据
- 最佳做法是从
listener
(to prevent a race condition) - Validate with Testing read deep link
- Listener
const options = {
advertising_ids: {
SAMSUNG_IFA: 'xxxxx',
}
};
branch.init('key_live_YOUR_KEY_GOES_HERE', options, function(err, data) {
console.log(err, data);
});
- 最新数据
branch.data(function(err, data) {
console.log(err, data);
});
- First data
branch.first(function(err, data) {
console.log(err, data);
});
创建二维码
QR Code Access Required
Access to Branch's QR Code API and SDK requires premium product access. Please reach out to your account manager or https://branch.io/pricing/ to activate.
- 生成包含唯一 Branch Link 的自定义二维码,您可以使用该 Branch Link 进行深度链接和追踪分析。
- Uses QR Code Settings (1st parameter)
- Uses Deep Link Properties (2nd parameter)
- Callback is a
qrCode
object which contains arawBuffer
or abase64()
function which base 64 encodes the raw buffer so that you can use to display the image directly
const qrCodeSettings = {
"code_color":"#000000",
"background_color": "#FFFFFF",
"margin": 5,
"width": 1000,
"image_format": "png"
};
const qrCodeLinkData = {
tags: [ 'tag1', 'tag2' ],
channel: 'sample app',
feature: 'create link',
stage: 'created link',
data: {
mydata: 'bar',
'$desktop_url': 'https://cdn.branch.io/example.html',
'$og_title': 'Branch Metrics',
'$og_description': 'Branch Metrics',
'$og_image_url': 'http://branch.io/img/logo_icon_white.png'
}
};
branch.qrCode(qrCodeLinkData, qrCodeSettings, function(err, qrCode) {
// qrCode.rawBuffer is the raw buffer
// qrCode.base64() is the encoded
//
// Example img tag:
// <img src="data:image/png;charset=utf-8;base64,' + qrCode.base64() + '" width="500" height="500">
});
For more information on the QR Code API, please reference this guide.
Setting a custom Deeplink Path when Canonical URL doesn't match App path taxonomy
- Branch automatically pulls meta tags for your convenience. If Canonical Url is set as a meta tag, it will default this as the Branch
$deeplink_path
. You can override this by setting$deeplink_path
to the path your app url taxonomy uses to deeplink.
<meta name="branch:deeplink:$deeplink_path" content="recipes/456789" />
const options = {
advertising_ids: {
SAMSUNG_IFA: 'xxxxx',
}
};
branch.init('BRANCH_KEY', options, function(err, data) {
if (document.querySelectorAll("meta[name='branch:deeplink:$deeplink_path']").length > 0) {
var meta = document.querySelector("meta[name='branch:deeplink:$deeplink_path']").getAttribute("content");
branch.setBranchViewData({
data:{
'$deeplink_path':meta"
}
});
}
});
For more information on the branch:deeplink:Keys you can use to customize your meta tags, please reference this table.
问题排查
- If you have Facebook App Links metatags on your site and working with your app, then you can skip these instructions. Branch will automatically fetch App Links tags and add them to your deep link data.
- 请勿使用 Google 追踪标签管理器(GTM)插入您的内容元标记。 GTM 需要在页面上加载 JavaScript,并且 Branch Link 数据抓取工具不支持 JavaScript 执行。
- If you need to whitelist the postback server IP addresses for security purposes, they are listed here.
追踪用户
Sending PII
Be sure to not send any PII through this method. For additional details, please view our guide on Best Practices to Avoid Sending PII to Branch
- Sets the identity of a user (ID, UUID, etc) for events, deep links, and referrals
- Validate with the Branch Dashboard
branch.setIdentity('123456');
branch.setIdentity('123456', function (err, data) {
console.log(err, data);
});
- 删除用户身份
branch.logout();
branch.logout(function(err, data) {
console.log(err, data);
});
追踪事件
默认情况下,Branch SDK 会自动(不需额外设置)追踪点击,打开,安装,重新安装和展示。
Please refer to our Event Tracking Docs for more information and examples:
启用/禁用用户追踪
In order to help our customers comply with GDPR and other laws that restrict data collection from certain users, we’ve updated our Connected SDK with a Do Not Track mode. This way, if a user indicates that they want to remain private on your app, or if you otherwise determine that a particular user should not be tracked, you can continue to make use of the Branch Connected SDK (e.g. for creating Branch links) while not tracking that user. This state is persistent, meaning that it’s saved for the user across sessions for the app. This setting can also be enabled across all users for a particular link, or across your Branch links.
- To enable Do Not Track Mode during initialization, include the
tracking_disabled
flag, with a value oftrue
, into the options during initialization:
const options = {
‘tracking_disabled’ : true
};
branch.init('key_live_YOUR_KEY_GOES_HERE', options, function (err, data) {
console.log(err, data);
});
- To enable Do Not Track Mode following initialization, call
disableTracking(true)
. If you calldisableTracking()
with no argument, it will default todisableTracking(true)
. UsedisableTracking(false)
to resume tracking.
const options = {
advertising_ids: {
SAMSUNG_IFA: 'xxxxx',
},
};
branch.init('key_live_YOUR_KEY_GOES_HERE', options, function (err, data) {
console.log(err, data);
});
branch.disableTracking(true);
Updated 3 months ago