Windows C++ Basic Integration

Adding the Branch SDK to a Windows Solution

Conan Package Manager

The Branch C++ SDK has dependencies on Poco for JSON and Network libraries. Poco itself has
dependencies on OpenSSL and other packages. Solving dependency issues is a thorny problem and to be able to produce an
SDK that works on any platform (including Windows, Mac, Linux) a package manager is recommended.

The C++ Branch SDK is fully compatible with Conan. Conan is a C/C++ Package manager for developers
and has integrations with Visual Studio to make it even easier to integrate quickly.

  1. Install Conan, if you haven't already.
  2. Install the Conan Extension for Visual Studio

Adding the Branch SDK

  • Once Conan is configured, it is just a matter of adding a conanfile.txt to your project.
    An example would look like this:
    [requires]
    BranchIO/[email protected]/stable
    

That's it! The Conan dependency manager will solve all of the problems with getting Branch and the Branch dependency
chain. Should Branch need to provide patches, it is just a simple step to update to (say) version 1.0.1.


Integrating the Branch SDK

I. Create project in visual studio

  • Open Visual Studio and create a new Blank App (Windows Desktop Application) project

II. Add the Branch SDK

  • Add a conanfile.txt to your project. Use the example above to get started.

The Conan Extension will automatically pick up the dependency on Branch, and pull in the necessary
files needed.

III. Create a Branch Instance

Creating a Branch instance should be done as early as possible in the Application lifecycle.
For example, in WinMain().

#define BRANCH_KEY "key_live_xxx"

    BranchIO::Branch* _branchInstance;
    BranchIO::AppInfo _appInfo;

    void initializeBranch() {
        _appInfo
            .setAppVersion("1.0")
            .setCountryCode("US")
            .setDeveloperIdentity("My Company")
            .setEnvironment("FULL_APP")
            .setLanguage("en");

        _branchInstance = BranchIO::Branch::create(BRANCH_KEY, &_appInfo);
    }

IV. Initialize a Branch Session

A Branch Session is typically defined as starting when the user interface first appears, and finishing when the last
user interface goes away. Multiple views may be shown during a single session. A session must be created
before doing any analytic events.

On Windows, this typically means creating a Branch Session in WM_CREATE and closing the session in WM_DESTROY in the
application WndProc.

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_CREATE:
        // Start the Branch Session
        _branchInstance->openSession("", _myOpenCallback);
        break;

    case WM_DESTROY:
        // End the Branch Session
        _branchInstance->closeSession(_myCloseCallback);

        PostQuitMessage(0);
        break;

    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

Note that opening a session with Branch will notify of any pending deep links in the callback.

V. Register app to handle deep links

To enable your Windows application for deep linking, please follow Microsoft's documentation on enabling apps for websites using app URI handlers.

VI. Configuring

  • You may configure your app with these classes:
    • BranchIO::AppInfo - Application Information, such as version and language.
    • BranchIO::AdvertiserInfo - Advertiser Information, including the ability to disable tracking.

Example to disable ad tracking:

_branchInstance->getAdvertiserInfo().disableTracking();

Example code

To help you get started, there are a number of examples for learning how to effectively use the Branch C++ SDK

Hello Branch

The most basic console application. This sample creates a couple of attribution events and waits until they have all completed.

Console Example

A more detailed console application. This sample puts up a simple menu and allows the user to initialize sessions,
enable and disable tracking, and more. This is most useful for examining how Branch works in an isolated environment
and provides an easy framework to extend to try out other requests that are pertinent to the problems that you are trying to solve.
Adding new menu items is trivial and is immensely useful for a debugging tool.

This example also has the ability to print out details of the environment that it is running on, such as the OS,
OS Version, SDK version, etc.

Windows Color Picker

Basic Windows Win32 application to demonstrate the Branch SDK in a Windows environment. This sample will also demonstrate basic deep linking functionality and creating links to share.

Updated 5 months ago

Windows C++ Basic Integration


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.