Button SDK impression tracking works by adding an
ImpressionView as a subview to the views that you use to display offers to your users. Impression views are transparent and do not accept user interaction. They are used strictly to detect the visibility of the offer and track "viewable impressions" as users interact with your app.
This feature will be tracking what are known as “viewable impressions” as defined by the Interactive Advertising Bureau (IAB), where a viewable impression is one that meets the following criteria:
In this guide, we'll go over:
You add impression views to your app's offer views just as you would add any other view. You can add them with a few lines of code in Interface Builder.
When you create an impression view, you specify a "creative type" to indicate where in your app an impression originated. The
ImpressionView class exposes
creativeType as an enumerated type in code, but it can be specified as a string in your layout or in Interface Builder.
In Interface Builder, you can add impression views and set the
creativeType in the Attributes Inspector for the
let impressionView = ImpressionView(creativeType: .hero) myOfferView.addSubview(impressionView)
BTNImpressionView *impressionView = [[BTNImpressionView alloc] initWithCreativeType:BTNCreativeTypeHero]; [myOfferView addSubview:impressionView];
When you populate your offer views with data you’re displaying to the user, call
track(…) on the
ImpressionView that you added to that view in the previous step.
track(…) method takes the following arguments:
url(string): The same URL you’ll use when fetching a Purchase Path from the Button SDK.
visibleRateType(enum): the rate type displayed to your user. Accepted values are "percent" or "fixed".
visibleRate(double): the visible rate displayed to your user, e.g. "5" to represent an offer of 5%.
offerId(string): If you’re using Button’s Personalized Rates API, the
offers.idassociated with the offer. In the case of a Brand with multiple categories/rates, please use the
best_offer_idvalue. If you are not using the Rates API, do not include this value in the
// Track the new data on the associated ImpressionView myOfferView.impressionView.track(withURL: URL(string: "https://example.com")! // The URL for the Brand offer, visibleRateType: .percent, // or .fixed (a percentage or fixed rate offer) visibleRate: 5, // The rate visible to the user on your offer view. In this example, it's a 5% offer. offerId: "offer-abc123def456abc1") // Only relevant if using Button's Personalized Rates API. If not, pass `nil` here.
// Track the new data on the associated ImpressionView [impressionView trackWithURL:[NSURL URLWithString:@"https://example.com"], // The URL for the Brand offer, visibleRateType:BTNVisibleRateTypePercent, // or BTNVisibleRateTypeFixed (a percentage or fixed rate offer) visibleRate:5, // The rate visible to the user on your offer view. In this example, it's a 5% offer. offerId:@"offer-abc123def456abc1"]; // Only relevant if using Button's Personalized Rates API. If not, pass `nil` here.