Application Browse and Tap Integration on
Android
iOS

Application Browse and Tap Integration


Add the Button SDK


To get started, add the Button SDK to your build.gradle file in the dependencies.


    implementation 'com.usebutton:android-sdk:6+'

Next, import and configure the Button SDK in either the Application subclass (preferred), or initial Activity upon initialization.


    import com.usebutton.sdk.Button
    
    class MyApplication : Application() {
      override fun onCreate() {
        super.onCreate()
    
        // Debugging enabled (do not include in production)
        if (BuildConfig.DEBUG) {
          Button.debug().loggingEnabled = true
        }
    
        // Replace app-xxxxxxxxxxxxxxxx with your App ID from the 
        // Button Dashboard https://app.usebutton.com
        Button.configure(this, "app-xxxxxxxxxxxxxxxx")
      }
    }


    import com.usebutton.sdk.Button;
    
    public class MyApplication extends Application {
      @Override
      public void onCreate() {
        super.onCreate();
    
        // Debugging enabled (do not include in production)
        if (BuildConfig.DEBUG) {
          Button.debug().setLoggingEnabled(true);
        }
    
        // Replace app-xxxxxxxxxxxxxxxx with your App ID from the Button Dashboard https://app.usebutton.com
        Button.configure(this, "app-xxxxxxxxxxxxxxxx");
      }
    }


Proguard Rules


If your app is using Proguard, make sure it includes rules for the Button SDK. This file is usually located in yourapp/proguard-rules.pro, or its location is specified in build.gradle, look for proguardFiles in your default or variant configuration (note: this can be multiple files).

Here is an example proguard-rules.pro snippet including the Button SDK


    -keepattributes Exceptions,InnerClasses,EnclosingMethod
    -keep class com.usebutton.** { *; }
    -keepclassmembers class * implements android.os.Parcelable {
        static ** CREATOR;
    }
    -keep class com.google.android.gms.ads.identifier.AdvertisingIdClient { public *; }


Configure User Attribution


User attribution ensures downstream commerce activity is associated with a unique user identifier. We recommend anonymizing this identifier before reporting it to Button (e.g. providing a uuid for the user, or hashed email via sha-256). Once your user finalizes a purchase, we’ll notify you using this identifier.

Warning! Never send personally identifiable information (PII) as the identifier. If you’re unsure about this, please reach out to your Button representative who can help guide you to follow our security & privacy best practices.

After your Publisher application launches and has been configured with the Button SDK, you can configure user attribution. If a user is already logged in, you can pass your application’s User ID to the Button.user.setIdentifier method. If a user has not yet logged in, be sure to do so first before calling Button.user.setIdentifier.


    Button.user().setIdentifier("YOUR_LOGGED_IN_USERS_ID")


    Button.user().setIdentifier("YOUR_LOGGED_IN_USERS_ID");

Similarly, after your user has successfully logged out of your Publisher application, invoke the Button SDK’s logout feature by calling the Button.clearAllData method.


    Button.clearAllData()


    Button.clearAllData();


Handle Link Routing When A User Taps


Next its time to handle link routing when a user taps on an offer. This is done by setting up a Button Purchase Path wherever your Android mobile application routes your user to a Brand.

Creating a Purchase Path is done by passing a Brand URL into the PurchasePathRequest. Upon passing the PurchasePathRequest into the Button.purchasePath.fetch method, the Button SDK will first validate that the PurchasePathRequest is valid. If it is, then the Button SDK will initialize the Purchase Path flow.

If Button can exchange the given url for a fully attributed action, the fetch will complete with a PurchasePath. Starting a purchasePath will pass control to the Button SDK which will open the Brand app, install flow, or web checkout.

In order to help with tracking this Purchase Path, Publishers can optionally set a value to the PurchasePathRequest's pubRef property. The pubRef (Publisher Reference) accepts a string value with a maximum length of 512, and is made available downstream in Button Webhooks as pub_ref . Publishers usually populate this value with click IDs, campaign IDs, and other identifiers to help with measuring performance.


    // Step 1 - Create a Purchase Path request
    val url = "https://www.example.com/"
    val request = PurchasePathRequest(url)
    
    // Optionally associate a unique token (e.g. campaign Id)
    // request.pubRef = "abc123"
    
    // Step 2 - Fetch a Purchase Path object
    Button.purchasePath().fetch(request) { purchasePath, throwable ->
    
        // Step 3 - Start Purchase Path flow
        purchasePath?.start(context)
    }


    // Step 1 - Create a Purchase Path request
    String url = "https://www.example.com/";
    PurchasePathRequest request = new PurchasePathRequest(url);
    
    // Optionally associate a unique token (e.g. campaign Id)
    // request.setPubRef("abc-123");
    
    // Step 2 - Fetch a Purchase Path object
    Button.purchasePath().fetch(request, new PurchasePathListener() {
        @Override
        public void onComplete(@Nullable PurchasePath purchasePath,
                @Nullable Throwable throwable) {
    
            // Step 3 - Start Purchase Path flow
            if (purchasePath != null) {
                purchasePath.start(context);
            }
        }
    });

Now that you’ve set up a Purchase Path, you’ll be able to track taps and deep links visited within the Button Dashboard.


Report Impression Views


It is critical to implement Impression Views within your app UI. Without this data, your integration will have an incomplete view of the user behavior funnel.

Impression views are programmatically wrapped subviews around your offer views which enable viewable impressions. In specific, they meet the following criteria:

  • Pixel Requirement: Greater than or equal to 50% of the pixels (Density- Independent) in the offer were on an in-focus browser or a fully downloaded, opened, initialized application, on the viewable space of the device.
  • Time Requirement: The time the pixel requirement is met was greater than or equal to one continuous second, post offer render. The clock starts once the pixel requirement is met.

Implementation can be done in code or statically in a View layout. If you’re writing code, utilize Button’s ImpressionView ​ class and supply a string value to the exposed enumerated creativeType​. The available creativeType​ values are: hero​, carousel​, list​, grid​, detail​, other​. ​​ ​​The following example shows how an Impression View is added to an Offer View.


    // Retrieve reference to the container layout
    val contentLayout : LinearLayout = ...
    
    // Create and ImpressionView and specify the type
    val impressionView = ImpressionView(context)
    impressionView.creativeType = HERO
    
    // Append the ImpressionView to the container view
    contentLayout.addView(impressionView, LayoutParams(LayoutParams.MATCH_PARENT,
                                                       LayoutParams.MATCH_PARENT))



    LinearLayout contentLayout = ...;
    
    ImpressionView impressionView = new ImpressionView(getContext());
    impressionView.setCreativeType(HERO);
    contentLayout.addView(impressionView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

If you’d like to implement an Impression View using a View layout, set your View layout layout_width and layout_height to match_parent.


    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="100dp">
    
      <!-- all your other view setup -->
    
      <com.usebutton.sdk.impression.ImpressionView
          android:id="@+id/color_impression_view"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:btn_creativeType="hero"
          />
    
    </LinearLayout>

After creating your Impression Views, implement tracking by calling the track method and supplying the following arguments:

PropertyTypeDescription
urlstringThe URL destination of the offer rendered. This is the same URL used when fetching a Purchase Path using the Button SDK
visibleRateTypeenumThe rate type displayed to your user. Valid options are percent or fixed
visibleRatedoubleThe visible rate displayed to your user. For example a value of 5 represents an offer shown to the user of 5%
offerIdstringThis is the id associated with the offer fetched from the Button Personalization API. If a Brand item being displayed contains multiple categories/rates, you may use the best_offer_id instead.

Remember to always call track whenever your Offer Views are updated with new data, such as when making another fetch to the Button Personalization API.


    // Track the new data on the associated ImpressionView
    myOfferView.impressionView.track(
      "https://example.com", // The URL for the Brand offer
      PERCENT, // or FIXED (a percentage or fixed rate offer)
      5, // The rate visible to the user on your offer view. 
         // In this example, it's a 5% offer.
      "offer-abc123def456abc1") // Only relevant if using Button's 
                                // Personalization API. If not, pass `null` here.


    // Track the new data on the associated ImpressionView
    myOfferView.impressionView.track("https://example.com", // The URL for the Brand offer
                                     VisibleRateType.PERCENT, // or VisibleRateType.FIXED (a percentage or fixed rate offer)
                                     5, // The rate visible to the user on your offer view. In this example, it's a 5% offer.
                                     "offer-abc123def456abc1");