Titanium

Integrate Branch

  • Configure Branch

  • Configure App

    • iOS

      • Add your Branch key and register a URI scheme

        • In your project’s tiapp.xml file, insert the snippet below. Change yourapp to the URI scheme you’ve selected.
         <ios>
             <plist>
               <dict>
                 <!-- Add branch key as key-value pair -->
                 <key>branch_key</key>
                 <string>key_live_xxxxxxxxxxxxxxx</string>
                 <!-- Add unique string for direct deep links -->
                 <key>CFBundleURLTypes</key>
                 <array>
                   <dict>
                     <key>CFBundleURLSchemes</key>
                     <array>
                       <string>yourapp</string>
                     </array>
                   </dict>
                 </array>
                 <!-- Add domains to support Universal Links -->
                 <key>com.apple.developer.associated-domains</key>
                 <array>
                     <string>applinks:xxxx.app.link</string>
                     <string>applinks:xxxx-alternate.app.link</string>
                     <string>applinks:xxxx.test-app.link</string>
                     <string>applinks:xxxx-alternate.test-app.link</string>
                 </array>
                 <!-- Required step for Universal Links on cold start -->
                 <key>NSUserActivityTypes</key>
                 <array>
                   <string>io.branch.testbed.universalLink</string>
                 </array>
               </dict>
             </plist>
           </ios>
        
    • Android

      • Add your Branch Key and register a URI Scheme

        • Open your tiapp.xml and add the following tag:

              <application>
                  <!-- Other existing entries -->
                  <meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_xxxxxxxxxxxxxxx" />
              </application>
          

        • Within your Deep Link Activity's definition, insert the intent filter provided below. Change yourapp under android:scheme to the URI scheme you’ve selected.

            <intent-filter>
              <data android:scheme="yourapp" android:host="open" />
              <action android:name="android.intent.action.VIEW" />
              <category android:name="android.intent.category.DEFAULT" />
              <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
        
  • Initialize Branch

    • Initialize the SDK by inserting the following snippet into your index.js file:

      $.initialize = function(params) {
             $.window.open();
      
             $.initializeViews();
             $.initializeHandlers();
      
             Ti.API.info("start initSession");
             branch.initSession();
             branch.addEventListener("bio:initSession", $.onInitSessionFinished);
      
             if (OS_ANDROID) {
                 Ti.Android.currentActivity.addEventListener("newintent", function(e) {
                     Ti.API.info("inside newintent: " + e);
                     $.window.open();
                     branch.initSession();
                 });
             }
      
             if (OS_IOS) { // Don't forget this condition.
                var activity = Ti.App.iOS.createUserActivity({
                    activityType:'io.branch.testbed.universalLink'
                });
      
                activity.becomeCurrent();
      
                Ti.App.iOS.addEventListener('continueactivity', function(e) {
                    if (e.activityType === 'io.branch.testbed.universalLink') {
                        branch.continueUserActivity(e.activityType, e.webpageURL, e.userInfo);
                    }
                });
            }
         };
      
         $.onInitSessionFinished = function(data) {
             Ti.API.info("inside onInitSessionFinished");
             for (key in data) {
                 if ((key != "type" && key != "source" && key != "bubbles" && key != "cancelBubble") && data[key] != null) {
                     Ti.API.info(key + data["key"]);
                 }
             }
         }
      
    • Create a deep link from the Branch Marketing Dashboard

    • Delete your app from the device

    • Compile your app

    • Paste deep link in Apple Notes

    • Long press on the deep link (not 3D Touch)

    • Click Open in "APP_NAME" to open your app (example)

    • Create a deep link from the Branch Dashboard

    • Delete your app from the device

    • Compile your app

    • Paste deep link in Google Hangouts

    • Click on the deep link to open your app

Implement features

  • Create content reference

    • The Branch Universal Object encapsulates the thing you want to share

    • Uses the Universal Object Properties listed below:

      Key Type Meaning
      canonicalIdentifier string The identifier of the object
      title string The title of the object
      contentDescription string The short description of the object
      contentImageUrl string URL of the image used by the object
      contentIndexingMode string Indexing mode of the object. Set as "private" or "public".
      contentMetadata dictionary Custom keys and values as metadata of the object
          var branchUniversalObject = branch.createBranchUniversalObject({
              "canonicalIdentifier" : "content/12345",
              "title" : "My Content Title",
              "contentDescription" : "My Content Description",
              "contentImageUrl" : "https://example.com/mycontent-12345.png",
              "contentIndexingMode" : "public",
              "contentMetadata" : {
                  "product_picture" : "12345",
                  "user_id" : "6789"
              },
          });
      
  •     branchUniversalObject.generateShortUrl({
          "feature" : "sample-feature",
          "channel" : "sample-channel",
          "stage" : "sample-stage"
        }, {
          "$desktop_url" : "http://desktop-url.com",
        }, function (res) {
            Ti.API.info('Completed link generation');
            Ti.API.info(res);
        });
    
    • The event listener bio:generateShortUrl returns a string object containing the generated link:
          branchUniversalObject.addEventListener("bio:generateShortUrl", $.onGenerateUrlFinished);
      
    • Will generate a Branch deep link and tag it with the channel the user selects

    • Needs a Branch Universal Object

    • Uses Deep Link Properties

        branchUniversalObject.showShareSheet({
          "feature" : "sample-feature",
          "channel" : "sample-channel",
          "stage" : "sample-stage",
        }, {
          "$desktop_url" : "http://desktop-url.com",
        });
    
    • Android only (Callbacks in iOS are ignored. There is no need to implement them as the events are handled by UIActivityViewController)
        branchUniversalObject.shareLinkDialogLaunched(function () {
          console.log('Share sheet launched');
        });
    
        branchUniversalObject.shareLinkDialogDismissed(function () {
         console.log('Share sheet dimissed');
       });
    
        branchUniversalObject.shareLinkResponse(function (res) {
          console.log('Share link response: ' + JSON.stringify(res));
        });
    
        branchUniversalObject.shareChannelSelected(function (res) {
          console.log('Channel selected: ' + JSON.stringify(res));
        });
    
  • Track content

        branchUniversalObject.registerView();
    
  • Track users

    • Sets the identity of a user (email, ID, UUID, etc) for events, deep links, and referrals

    • Validate with the Branch Dashboard

          var userId = '123456';
          branch.setIdentity(userId);
      
    • Removes the identity of a user

          branch.logout();
      
  • Track events

    • Registers a custom event

    • Events named open, close, install, and referred session are Branch restricted

    • Best to Track users before Track events to associate a custom event to a user

    • Validate with the Branch Dashboard

        var eventName = 'clicked_on_this';
        branch.userCompletedAction(eventName);
    
  • Handle referral

        int value = 10;
        branch.redeemRewards(value);
    
    • Load credits
        var bucket = 'this_bucket'
        branch.loadRewards(bucket);
    
        branch.loadRewards();
    

    To implement the callback, you must add a listener to the event bio:loadRewards. The event returns a dictionary object containing the balance.

  • Load history

    branch.getCreditHistory();

    Implement the callback, by adding a listener to the event bio:getCreditHistory.

Troubleshoot issues

Comments