Content Card integration
This reference article covers Content Card implementation guidelines for the Unity platform such as displaying cards, parsing cards, and analytics.
Displaying Content Cards natively
You can display the default UI for Content Cards using the following call:
1
Appboy.AppboyBinding.DisplayContentCards();
Receiving Content Card data in Unity
You may register Unity game objects to be notified of incoming Content Cards. We recommend setting game object listeners from the Braze configuration editor.
If you need to configure your game object listener at runtime, use AppboyBinding.ConfigureListener()
and specify BrazeUnityMessageType.CONTENT_CARDS_UPDATED
.
Note, you will additionally need to make a call to AppboyBinding.RequestContentCardsRefresh()
to start receiving data in your game object listener on iOS.
Parsing Content Cards
Incoming string
messages received in your Content Cards game object callback can be parsed into our pre-supplied ContentCard
model object for convenience.
Parsing Content Cards requires Json parsing, see the following example for details:
Example Content Cards callback
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
void ExampleCallback(string message) {
try {
JSONClass json = (JSONClass)JSON.Parse(message);
// Content Card data is contained in the `mContentCards` field of the top level object.
if (json["mContentCards"] != null) {
JSONArray jsonArray = (JSONArray)JSON.Parse(json["mContentCards"].ToString());
Debug.Log(String.Format("Parsed content cards array with {0} cards", jsonArray.Count));
// Iterate over the card array to parse individual cards.
for (int i = 0; i < jsonArray.Count; i++) {
JSONClass cardJson = jsonArray[i].AsObject;
try {
ContentCard card = new ContentCard(cardJson);
Debug.Log(String.Format("Created card object for card: {0}", card));
// Example of logging Content Card analytics on the ContentCard object
card.LogImpression();
card.LogClick();
} catch {
Debug.Log(String.Format("Unable to create and log analytics for card {0}", cardJson));
}
}
}
} catch {
throw new ArgumentException("Could not parse content card JSON message.");
}
}
Refreshing Content Cards
To refresh Content Cards from Braze, call either of the following methods:
1
2
3
4
// results in a network request to Braze
AppboyBinding.RequestContentCardsRefresh()
AppboyBinding.RequestContentCardsRefreshFromCache()
GIF Support
By default, the native Braze Android SDK does not provide animated GIF support for Content Cards—however, you can use a third-party image library to display GIFs instead. For more information, see Android Content Cards: GIFs.
By default, the Braze Swift SDK does not provide animated GIF support for Content Cards—however, you can wrap your own view or a third-party view in an instance of GIFViewProvider
. For a full walkthrough, see Tutorial: GIF Support for Swift Content Cards.
Analytics
Clicks and impressions must be manually logged for Content Cards not displayed directly by Braze.
Use LogClick()
and LogImpression()
on ContentCard to log clicks and impressions for specific cards.