Windows Advanced Features

创建Branch实例

创建 Branch Instance 需要 Branch Key 和应用信息。
使用特定于您的应用的设置来初始化 AppInfo。

// Set AppInfo properties as necessary
BranchIO::AppInfo _appInfo;

_branchInstance = BranchIO::create("key_live_xxx", &_appInfo);

创建Branch会话

创建Branch会话需要一个可选的链接参数和一个回调。

_branchInstance->openSession("", myCallback);

持久身份

通常,您可能拥有自己的用户 ID,或者希望引荐和事件数据在各个平台上保持不变或进行卸载/重新安装。如果您知道用户可以从不同的设备访问服务,这将很有帮助。我们在这里介绍“身份(identity)”的概念。

要识别用户,只需调用:

_branchInstance->setIdentity("user id", myCallback);

注销

如果您在应用中提供注销功能,请确保在注销完成后清除用户。这将确保清除所有存储的参数,并将所有事件正确地归属于正确的标识。

_branchInstance->logout(myCallback):

📘

注意

Neither setIdentity nor logout can be called before openSession. This will generate an error and have no other effect. Once set or removed, the identity or lack of one is persistent.

追踪用户操作和事件

标准事件

使用 BranchIO::StandardEvent 类别(class)可以追踪特殊的用户操作或特定于应用的事件,而不仅仅是应用的安装,打开和共享。您可以追踪事件,例如用户何时将商品添加到在线购物车中或搜索关键字等。StandardEvent 提供了添加内容的界面,以便将内容与事件相关联。您可以在 Branch 操作后台 (Dashboard)查看针对您触发的 StandardEvent 的分析。

BranchIO::StandardEvent枚举最常追踪的事件以及可与 StandardEvent 一起使用以获得最佳结果的事件参数。您始终可以使用自定义事件名称和事件参数。

#include <BranchIO/Event/StandardEvent.h>

using namespace BranchIO;

StandardEvent event(StandardEvent::Type::PURCHASE);
event.setCoupon("TestCoupon")
     .setCurrency("USD")
     .setDescription("Test Description")
     .setRevenue(99.99)
     .setSearchQuery("Some Search Query")
     .setShipping(1.99)
     .setTax(.99)
     .setTransactionId("Transaction123");

_branchInstance->sendEvent(event, new StandardEventCallback);

自订活动

使用 BranchIO::CustomEvent 类别(class)追踪除标准 Branch 事件之外的特殊用户操作或特定于应用的事件。自定义事件也将出现在 Branch 操作后台 (Dashboard)分析中。

#include <BranchIO/Event/CustomEvent.h>

using namespace BranchIO;

CustomEvent event(L"MyCustomEvent");
event.setAdType(Event::AdType::BANNER);
event.addCustomDataProperty(L"foo", L"Bar");

_branchInstance->sendEvent(event, new CustomEventCallback);

启用或禁用用户追踪

如果您需要按照 GDPR 的目的遵循用户不被追踪的请求,或者认为用户不应该被追踪,请利用此字段来防止 Branch 发送网络请求。此设置也可以在所有用户的特定链接或 Branch Link 中被启用。

_branchInstance->getAdvertiserInfo().disableTracking();

To enable tracking again once it's been disabled, call enableTracking instead of disableTracking

_branchInstance->getAdvertiserInfo().enableTracking();
/*
 * When reenabling tracking, it's necessary to open a new session afterward.
 */
_branchInstance->openSession("", myCallback);

📘

注意

When reenabling tracking, a new session must be created using Branch::openSession before any further SDK calls may be made.

To default to tracking disabled on first launch, add a REG_DWORD registry value trackingDisabled with value 1 to the key HKEY_CURRENT_USER\SOFTWARE\BranchIO\<Branch key>\advertiser. This prevents deferred deep linking or install attribution. After SDK initialization, call disableTracking() to reenable.

988988

生成Branch链接

Branch links can be created in-app (as well as in many other ways - see:
Branch link creation guide.
When they are, and setIdentity has been called to associate a User ID with the current user session, Branch links will
be associated with that User ID.

// you can access this data from any instance that installs or opens the app from this link

BranchIO::LinkInfo linkInfo;
linkInfo
    .addTag("Tag1")
    .setChannel("Sharing_Channel_name")
    .setFeature("my_feature_name")
    .addControlParameter("$android_deeplink_path", "custom/path/*")
    .addControlParameter("$ios_url", "http://example.com/ios")
    .setDuration(100);

// Add some additional control parameters
linkInfo
    .addControlParameter("$canonical_identifier", "item/12345")
    .addControlParameter("$canonical_url", https://branch.io/deepviews")
    .addControlParameter("$og_title", "My Content Title")
    .addControlParameter("$og_description", "my_product_description1")
    .addControlParameter("$og_image_url", "https://example.com/mycontent-12345.png");

// Generate a long branch link, synchronously.
string url = linkInfo.createLongUrl(_branchInstance);

// Create a short branch link, asynchronously (requires a server round trip).
// Falls back to a long URL in case of request failure.
linkInfo.createUrl(_branchInstance, _myCallback);

📘

注意事项

  • The LinkInfo destructor blocks until the asynchronous URL request completes. Use LinkInfo::cancel() to force immediate termination of the asynchronous request.
  • You can customize the Facebook OG tags of each URL if you want to dynamically share content by using the following
    optional keys in the data dictionary. Please use this
    Facebook tool to debug the OG tags.

Key

"$og_title"

您希望的标题显示在社交媒体中的链接中。

"$og_description"

您希望'的描述出现在社交媒体中的链接中。

"$og_image_url"

您希望在社交媒体中显示的链接的图像的URL。

"$og_video"

视频的网址。

"$og_url"

您希望显示的URL。

"$og_app_id"

The OG app ID. Optional and rarely used.

另外,您可以通过在字典中插入以下可选 key 来进行自定义重定向:

Key

"$desktop_url"

在台式机或笔记本电脑上发送用户处。默认情况下,它是 Branch 托管的 text-me 服务。

"$android_url"

Play Store 的替代 URL,用于在用户没有该应用的情况下向其发送。仅当您想要移动网站启动时才需要

"$ios_url"

App Store 的替代 URL,用于在用户没有该应用的情况下向其发送。仅在您想要移动网站启动时才需要

"$ipad_url"

与上述相同,但适用于iPad Store。

"$fire_url"

与上述相同,但适用于Amazon Fire Store。

"$blackberry_url"

与上述相同,但适用于Blackberry Store。

"$windows_phone_url"

与上述相同,但适用于Windows Store。

通过在字典插入以下可选 key,您可以控制每个链接的直接深度链接:

Key

"$deeplink_path"

您希望我们附加到 URI 的深度链接路径的值。例如,您可以指定 "$deeplink_path": "radio/station/456",我们将使用 URI "theapp://radio/station/456?link_click_id=branch-identifier" 打开应用。这主要是为了支持旧版深度链接基础结构。

"$always_deeplink"

true or false. (default is not to deep link first) This key can be specified to have our linking service force try to open the app, even if we're not sure the user has the app installed. If the app is not installed, we fall back to the respective app store or $platform_url key. By default, we only open the app if we've seen a user initiate a session in the app from a Branch link (has been cookied and deep linked by Branch).


这个页面对您有帮助吗?