Self Handled Cards

Self-handled cards give you the flexibility of creating Card Campaigns on the MoEngage Platform and displaying the cards anywhere inside the website. SDK provides APIs to fetch campaign data using which you can create your view for cards.

SDK Installation

Pass the Cards config in the SDK initialization script as shown below.

JavaScript
<script type="text/javascript">
 (function(i,s,o,g,r,a,m,n){i.moengage_object=r;t={};q=function(f){return function(){(i.moengage_q=i.moengage_q||[]).push({f:f,a:arguments})}};f=['track_event','add_user_attribute','add_first_name','add_last_name','add_email','add_mobile','add_user_name','add_gender','add_birthday','destroy_session','add_unique_user_id','moe_events','call_web_push','track','location_type_attribute'],h={onsite:["getData","registerCallback"]};for(k in f){t[f[k]]=q(f[k])}for(k in h)for(l in h[k]){null==t[k]&&(t[k]={}),t[k][h[k][l]]=q(k+"."+h[k][l])}a=s.createElement(o);m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m);i.moe=i.moe||function(){n=arguments[0];return t};a.onload=function(){if(n){i[r]=moe(n)}}})(window,document,'script','https://cdn.moengage.com/webpush/moe_webSdk.min.latest.js','Moengage')
 
 Moengage = moe({
   app_id: "APP ID",
   debug_logs: 0,
   cards: {
     enable: true
   }
 });
</script>

Notify on Inbox Open

Whenever you open the inbox, you can notify Moengage as shown below to sync the data and track the inbox open event.

JavaScript
<script type="text/javascript">
   Moengage.cards.inboxOpened();
</script>

Fetch Categories

To fetch all the categories for which cards are configured, use the getCardCategories() API.

JavaScript
<script type="text/javascript">
   Moengage.cards.getCardCategories().then(function(categories) {
   	console.log(categories);
   })
</script>

Additionally, you can have an All category which would be a superset of all the categories. Use the isAllCategoryEnabled() API.

JavaScript
<script type="text/javascript">
   Moengage.cards.isAllCategoryEnabled().then(function(enabled) {
   	console.log(enabled); // boolean
   })
</script>

Fetch Cards for Categories

To fetch the cards eligible for display for a specific category, use the getCardsForCategory(categoryName) API.

JavaScript
<script type="text/javascript">
   Moengage.cards.getCardsForCategory('Announcement').then(function(cards) {
   	console.log(cards); // list of cards
   })
</script>

Fetch Card Info

Instead of using separate APIs to fetch Cards and categories, you can use the getCardsInfo(cardID)API to fetch all the information in one go.

JavaScript
<script type="text/javascript">
   Moengage.cards.getCardsInfo('12345').then(function(card) {
   	console.log(card); // card detail
   })
</script>

Track Statistics for Cards

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.

Impressions

Call the cardShown(cardID)API when a specific card is visible on the screen.

JavaScript
<script type="text/javascript">
   Moengage.cards.cardShown('12345')
</script>

Clicks

Whenever a user clicks on a card, call the cardClicked(cardID, widgetID) API and pass the card object widget identifier for the UI element clicked.

JavaScript
<script type="text/javascript">
   Moengage.cards.cardClicked('12345', 123)
</script>

Delete Card

Call the deleteCard(cardID) API to delete a card.

JavaScript
<script type="text/javascript">
   Moengage.cards.deleteCard('12345')
</script>
Was this article helpful?
0 out of 0 found this helpful