Pular para o conteúdo

Inline in-apps in the Android SDK

Este conteúdo ainda não está disponível no seu idioma.

An inline slot is a view you place in your app’s own layout, for example under a carousel on the home screen. Marketers fill it with a banner from an inline block campaign in the Control Panel, using the same slot ID that you give the view. The SDK requests the slot’s banner, draws it, sizes the slot to it, and reports shows, taps, and closes.

Prerequisites

Anchor link to
  • Pushwoosh Android SDK 6.17.3 or later, integrated as described in the Android SDK guide.

  • The pushwoosh-inapp-ui module of the same version as the main library:

    implementation 'com.pushwoosh:pushwoosh-inapp-ui:6.+'

Add a slot

Anchor link to

Pick a slot ID for each place in the app that should show a banner, for example home_promo. Marketers enter the same ID in the campaign, letter case included, so send them the list of IDs and the screen each one is on.

Add a PushwooshInlineView to the layout and set the slot ID in app:pw_slotId:

<com.pushwoosh.inline.PushwooshInlineView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:pw_slotId="home_promo" />

To create the view in code, pass the slot ID to the constructor:

val slot = PushwooshInlineView(context, "home_promo")
container.addView(
slot,
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT),
)

The view is 0 high while the slot has no banner. When a banner arrives, a wrap_content view takes the banner’s height and pushes its neighbors. A banner taller than its maximum height is clipped. If your layout sizes the view itself, follow the height the banner needs with setOnHeightChangeListener.

How the SDK fills a slot

Anchor link to

You don’t need to call anything to load banners. The SDK requests:

  • A slot the first time it appears on screen, together with other new slots that appear within 0.5 seconds.
  • All slots it knows at the start of a session: the first time the app comes to the foreground, or a return after 30 minutes in the background.
  • All slots again once the server confirms a user change.

The SDK keeps the last banner of each slot on disk, so the slot shows it again after a relaunch without a network connection. An empty answer collapses the slot.

The SDK reports a show once at least half of the banner’s height has stayed on screen for 0.3 seconds while the app is in the foreground and nothing covers the slot. It counts once per banner version and user. For a user in the global control group, the slot stays empty. When the slot’s place is on screen, the SDK reports a control show instead: a control event for the banner the user would have seen. Pushwoosh doesn’t count it as a show.

When the user closes the banner, the slot collapses at once and then gets the next banner in its queue. The closed banner doesn’t come back for this user until its campaign ends, or for 90 days if the campaign has no end date.

Request slots manually

Anchor link to

To refresh slots right away, for example after a purchase changes what the user should see, call requestSlots with up to 10 slot IDs:

PushwooshInline.requestSlots(Arrays.asList("home_promo", "cart_offer"), error -> {
if (error != null) {
Log.w("Inline", "Inline slots were not refreshed", error);
}
});

Manual requests are limited to 5 per session start, then one every 3 minutes. A request over the limit fails with PushwooshInlineException.RATE_LIMITED, and one made before the server confirms a user change fails with OWNER_CHANGED. When a request fails, the slots keep their banners.

Follow slot events

Anchor link to

Set a listener to know when a slot changes, for example to log analytics events of your own. In Java, extend PushwooshInlineListenerAdapter and override only the callbacks you need. All callbacks run on the main thread:

PushwooshInline.setListener(new PushwooshInlineListenerAdapter() {
@Override
public void onSlotShown(String slotId, PushwooshInlineBanner banner) { }
@Override
public void onSlotClicked(String slotId, PushwooshInlineBanner banner, String elementId) {
// elementId: the tapped element, null for the banner itself
}
});

The other callbacks are onSlotUpdated (the banner changed, null when the slot became empty) and onSlotDismissed. The SDK holds the listener strongly, so set it to null when it should no longer be called.

Match the app’s theme

Anchor link to

Banners follow the app’s theme (PushwooshInlineColorScheme.APP, the default). To change it, set PushwooshInline.setColorScheme() to SYSTEM for the device setting, or to LIGHT or DARK. Banners already on screen restyle at once.