Content Cards integration
In Android, the Content Cards feed is implemented as a fragment available in the Braze Android UI project. View Google’s Fragments for information on adding a fragment to an activity.
The ContentCardsFragment
class will automatically refresh and display the contents of the Content Cards and log usage analytics. The cards that can appear in a user’s ContentCards
are created on the Braze dashboard.
Content Cards data model
The Content Cards data model is available in the Android SDK.
Content Card model
Braze has three unique Content Cards card types that share a base model: banner, captioned image, and classic. Each type inherits common properties from a base model and has the following additional properties.
Base Content Card model properties
The base card model provides foundational behavior for all cards.
Property | Description |
---|---|
getId() |
Returns the card’s ID set by Braze. |
getViewed() |
Returns a boolean reflects if the card is read or unread by the user. |
getExtras() |
Returns a map of key-value extras for this card. |
getCreated() |
Returns the unix timestamp of the card’s creation time from Braze. |
getIsPinned |
Returns a boolean that reflects whether the card is pinned. |
getOpenUriInWebView() |
Returns a boolean that reflects whether Uris for this card should be opened in Braze’s WebView or not. |
getExpiredAt() |
Gets the expiration date of the card. |
getIsRemoved() |
Returns a boolean that reflects whether the end user has dismissed this card. |
getIsDismissible() |
Returns a boolean that reflects whether the card is pinned. |
Banner image card properties
Banner image cards are clickable full-sized images.
Property | Description |
---|---|
getImageUrl() |
Returns the URL of the card’s image. |
getUrl() |
Returns the URL that will be opened after the card is clicked. It can be a http(s) URL or a protocol URL. |
getDomain() |
Returns link text for the property URL. |
Captioned image card properties
Captioned image cards are clickable full-sized images with accompanying descriptive text.
Property | Description |
---|---|
getImageUrl() |
Returns the URL of the card’s image. |
getTitle() |
Returns the title text for the card. |
getDescription() |
Returns the body text for the card. |
getUrl() |
Returns the URL that will be opened after the card is clicked. It can be a http(s) URL or a protocol URL. |
getDomain() |
Returns the link text for the property URL. |
Classic card properties
A classic card without an image included will result in a text announcement card. If an image is included, you will receive a short news card.
Property | Description |
---|---|
getTitle() |
Returns the title text for the card. |
getDescription() |
Returns the body text for the card. |
getUrl() |
Returns the URL that will be opened after the card is clicked. It can be a http(s) URL or a protocol URL. |
getDomain() |
Returns the link text for the property URL. |
getImageUrl() |
Returns the URL of the card’s image, applies only to the classic Short News Card. |
Card methods
All Card
data model objects offer the following analytics methods for logging user events to Braze servers.
Method | Description |
---|---|
logImpression() |
Manually log an impression to Braze for a particular card. |
logClick() |
Manually log a click to Braze for a particular card. |
setIsDismissed() |
Manually log a dismissal to Braze for a particular card. If a card is already marked as dismissed, it cannot be marked as dismissed again. |
Custom Content Cards
If you would like to display the Content Cards in a completely custom manner, it is possible to do so by using your own views populated with data from our models. To obtain Braze’s Content Cards models, you will need to subscribe to Content Card updates and use the resulting model data to populate your views. You will also need to log analytics on the model objects as users interact with your views.
Part 1: Subscribing to Content Card updates
First, declare a private variable in your custom class to hold your subscriber:
1
2
// subscriber variable
private IEventSubscriber<ContentCardsUpdatedEvent> mContentCardsUpdatedSubscriber;
1
private var mContentCardsUpdatedSubscriber: IEventSubscriber<ContentCardsUpdatedEvent>? = null
Next, add the following code to subscribe to Content Card updates from Braze, typically inside of your custom Content Cards activity’s Activity.onCreate()
:
1
2
3
4
5
6
7
8
9
10
11
12
13
// Remove the previous subscriber before rebuilding a new one with our new activity.
Braze.getInstance(context).removeSingleSubscription(mContentCardsUpdatedSubscriber, ContentCardsUpdatedEvent.class);
mContentCardsUpdatedSubscriber = new IEventSubscriber<ContentCardsUpdatedEvent>() {
@Override
public void trigger(ContentCardsUpdatedEvent event) {
// List of all Content Cards
List<Card> allCards = event.getAllCards();
// Your logic below
}
};
Braze.getInstance(context).subscribeToContentCardsUpdates(mContentCardsUpdatedSubscriber);
Braze.getInstance(context).requestContentCardsRefresh(true);
1
2
3
4
5
6
7
8
9
10
// Remove the previous subscriber before rebuilding a new one with our new activity.
Braze.getInstance(context).removeSingleSubscription(mContentCardsUpdatedSubscriber, ContentCardsUpdatedEvent::class.java)
mContentCardsUpdatedSubscriber = IEventSubscriber { event ->
// List of all Content Cards
val allCards = event.allCards
// Your logic below
}
Braze.getInstance(context).subscribeToContentCardsUpdates(mContentCardsUpdatedSubscriber)
Braze.getInstance(context).requestContentCardsRefresh(true)
We also recommend unsubscribing when your custom activity moves out of view. Add the following code to your activity’s onDestroy()
lifecycle method:
1
Braze.getInstance(context).removeSingleSubscription(mContentCardsUpdatedSubscriber, ContentCardsUpdatedEvent.class);
1
Braze.getInstance(context).removeSingleSubscription(mContentCardsUpdatedSubscriber, ContentCardsUpdatedEvent::class.java)
Part 2: Logging analytics
When using custom views, you will need to log analytics manually since analytics are only handled automatically when using Braze views.
To log an impression or click on a Card, call Card.logClick()
or Card.logImpression()
respectively.
For campaigns using Control Cards for A/B testing, you can use Card.isControl()
to determine if a card will be blank, and used only for tracking purposes.
Manually dismissing a Content Card
You can manually log or set a Content Card as “dismissed” to Braze for a particular card with setIsDismissed
.
If a card is already marked as dismissed, it cannot be marked as dismissed again.