Fetch card campaign data via the MoEngage SDK and build custom card UI on your website.
Self-handled cards allow you to create Card Campaigns on the MoEngage Platform and display the cards anywhere inside the website. SDK provides APIs to fetch campaign data, which you can use to create your view for cards.
Cards is a separate module and it gets loaded asynchronously with core SDK module. So it may not be available immediately on the page load.Please use this event listener and call the Cards API once it has been initialised:
window.addEventListener('MOE_LIFECYCLE', event => { if (event.detail.name === 'CARDS_INITIALIZED') { // call the cards APIs here }});
If you are using npm package, then use this helper function:
moengage.on_cards_loaded().then(function() { // call the cards APIs here})
To fetch the cards eligible for display for a specific category, use the getCardsForCategory(categoryName) API.
<script type="text/javascript"> Moengage.cards.getCardsForCategory('Announcement').then(function(cards) { console.log(cards); // list of cards })</script>
To fetch all the cards eligible for display irrespective of the category, pass the category ‘All’ as shown below
<script type="text/javascript"> Moengage.cards.getCardsForCategory('All').then(function(cards) { console.log(cards); // list of cards })</script>
Since the UI/display of the cards is controlled by the application, to track the statistics on display and click, we need the application to notify the SDK.