Introduction
Applying carousel banners on the home page of your website is a great way to engage with your app users and promote specific offerings. In this article, we will learn how we can use MoEngage Self-Handled Cards to build a banner carousel on your Android and iOS native apps and create Card campaigns to deliver targeted Cards to your app visitors through these banner carousels.Expected Result
Users will see a carousel banner on the home page of your website:
Steps to Integrate
MoEngage self-handled Cards allow you to access the raw payload of the Card content. You can create components in your app to consume these payloads and display the Card content in a design and layout that works as an integrated component of your app. The following steps will help you with the following:- Cards Integration
- Cards UI Creation for each Category
- Parsing MoEngage Cards Payload and Feed into the Carousel UI
- Track Analytics
Step 1: Cards Integration
For Android
Installing using Catalog
Integration using a Version Catalog is the recommended way of integration; refer to the Configure Version Catalog document to configure a catalog if not done already. Once you have configured the catalog add the dependency in the app/build.gradle file as shown below: build.gradleFor iOS
Install using CocoaPod
Integrate the MoEngageCards framework by adding the dependency in the podfile as shown below: Ruby pod install to install the framework
For more information, refer to Self Handled Cards for iOS native.
Step 2: Guide for Cards UI Creation
Now that we have integrated self-handled cards, we will next build the UI that will consume the Card payload to show cards. For example, we have used SliderView and ImageSliderfor Android and iOS respectively while building this use case. These will appear in a carousel format that slides for every 3-4 seconds (configurable) on the homepage.The SliderView and ImageSlider are external libraries used in this use-case only as an example and are not maintained by MoEngage. We strongly recommend using libraries that you trust and best fit your use case.
- The campaign-driven components of the UI should match with components existing in the cards payload eg. Title, message, action, image etc.
- A user may qualify not qualify for any cards, please handle removing the carousel widget or having backup content for such cases.
- For all the elements in the payload, check for exception scenarios like null values, syntax errors from the campaign, and image assets not getting fetched in time.
- If you have assets that may take a longer time to load, consider adding interim UI for a seamless user experience.
- Ensure the image dimensions used in campaigns should fit the image containers or the UI handles the image scaling.
- Texts (Header & Message) supports emojis and html format (for formatting, color etc) so ensure to handle that using Html.format() method.
- Pin to top feature is present in the “display_control” and it has to be handled separately at the time of rendering to the UI (please refer to the sample payload for the structure).
- Illustration and Basic templates have slightly different payload structures. Please account for the null value in the image key with Basic Template
Step 3: Parsing MoEngage Cards Payload and Feed into the Carousel UI
Now that we have built a UI, we will be learning how to parse the cards payload into a structure that feeds the UI. Cards contain multiple categories and each category consists of two types of Cards as follows:- Basic
- Illustration
For Android
To fetch all the categories for which Cards are configured, use the getCardCategories() API. In this example, we are using the getCardsForCategory() API to fetch the Cards that belong to Announcement Type.- Kotlin
- Java
- Kotlin
- Java
- Kotlin
- Java

For iOS
To fetch all the categories for which Cards are configured, use the getCardsCategories API. To fetch all the categories for which Cards are configured, use the getCardsCategories API. Swift
Step 4: Track Analytics
After the Cards are rendered properly in the UI, you can use MoEngage SDKs that provide APIs to fetch the Card’s data, allowing you to track the usage and analytics of the Cards. To learn more, refer to the following documents:Test Campaigns
Creating carousel Cards is similar to creating a Card campaign for your application. While you are creating Cards, navigate to the step Create view on your MoEngage dashboard and scroll down to the Test Card section. You can test the output of your newly created Card by selecting a custom attribute and its value for a test user.Before Testing

Expected Result

Recommendation for Additional Layouts
This document illustrated an example of creating carousel Cards using the Auto Image Slider in Android and Image Slideshow on Cocoapods in iOS. You can use the same method to create Cards with either Basic or Illustration template and parse the payload to build different UI layouts with different libraries. Here are a few examples for layouts that can be used instead of carousels:


Sample Cards Payload
You can populate any layout by parsing the Card payload into UI elements similar to how the content was parsed for the carousel use case we saw above. Here is a sample payload for a card: JSONAdd Additional Keys in the Card Payload
The cards standard payload consists of card campaign details, expiry details, title, message, image and action. If you want to add additional data in the cards payload you recieve, you can add them as part of the Primary action for the card while creating the card campaign in the for for Key-Value pairs as seen below.