> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Campaigns

> CometChat Campaigns lets you deliver targeted, rich notifications to users via an in-app notification feed.

CometChat Campaigns lets you deliver targeted, rich notifications to users via an in-app notification feed. Each notification is a **Card Schema JSON** — a structured layout rendered natively by the CometChat Cards library.

The SDK provides APIs to fetch feed items, listen for real-time delivery, mark items as read/delivered, report engagement, and retrieve unread counts.

> [!NOTE]
>
> Before using the SDK, set up your channels, categories, templates, and campaigns in the CometChat Dashboard. See the [Dashboard Setup Guide](https://www.cometchat.com/docs/campaigns.md#setup-flow) for step-by-step instructions.

***

## Key Concepts

| Concept | Description |
| - | - |
| **NotificationFeedItem** | A single notification in the feed. Contains Card Schema JSON in its `content` field, a `category` for filtering, timestamps, and metadata. |
| **NotificationCategory** | A category label used for filter chips (e.g., "Promotions", "Updates"). |
| **Card Schema JSON** | The fully rendered card layout (images, text, buttons) inside `NotificationFeedItem.getContent()`. Passed directly to the CometChat Cards renderer. |
| **PushNotification** | Represents a campaign push notification payload received via FCM. |

***

## Card Messages

A **Card Message** is a structured, interactive message rendered as a card bubble inside a conversation. Cards are **receive-only** on the SDK: they are created through the **Platform REST API** or the **Dashboard Bubble Builder** and delivered to clients like any other message — the SDK does not send them.

* **Type:** `com.cometchat.chat.models.CardMessage`
* **Category:** `"card"` (`CometChatConstants.CATEGORY_CARD`)

### Properties

| Method | Returns | Description |
| - | - | - |
| `getCard()` | `JSONObject` | The raw card schema/payload passed to the Cards renderer. |
| `getText()` | `String` | Optional text shown alongside the card. |
| `getFallbackText()` | `String` | Text displayed when the card payload cannot be rendered. |
| `getTags()` | `List<String>` | Tags associated with the message. |

### Listening for card messages

To be notified when a card message arrives, implement `onCardMessageReceived` on your `MessageListener`.

> [tab] Java
>
> ```java theme={null}
>
> CometChat.addMessageListener(LISTENER_ID, new CometChat.MessageListener() {
>     @Override
>     public void onCardMessageReceived(CardMessage message) {
>         Log.d(TAG, "Card message received: " + message.getCard());
>     }
> });
>
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
>
> CometChat.addMessageListener(LISTENER_ID, object : CometChat.MessageListener() {
>     override fun onCardMessageReceived(message: CardMessage) {
>         Log.d(TAG, "Card message received: ${message.card}")
>     }
> })
>
> ```

See [Real-time Listeners](https://www.cometchat.com/docs/sdk/android/real-time-listeners.md) for the full `MessageListener` reference.

***

## Rendering Cards

The `content` field of each `NotificationFeedItem` is a Card Schema JSON object. To render it natively, use the CometChat Cards library.

### Add the Cards Dependency

Add the Cloudsmith repository and the cards library to your project:

```groovy theme={null}
// settings.gradle or project-level build.gradle
repositories {
    maven { url "https://dl.cloudsmith.io/public/cometchat/cometchat/maven/" }
}
```

```groovy theme={null}
// app/build.gradle
dependencies {
    implementation "com.cometchat:cards-android:1.0.0"
}
```

> [!NOTE]
>
> Requires `minSdk 24`, Kotlin, and internet permission in your AndroidManifest.xml.

### Render a Card from a Feed Item

> [tab] Jetpack Compose
>
> ```kotlin theme={null}
> import com.cometchat.cards.CometChatCardComposable
> import com.cometchat.cards.core.CometChatCardThemeMode
>
> @Composable
> fun NotificationCard(item: NotificationFeedItem) {
>     CometChatCardComposable(
>         cardJson = item.content.toString(),
>         themeMode = CometChatCardThemeMode.AUTO,
>         onAction = { event ->
>             when (event.action) {
>                 is CometChatCardOpenUrlAction -> {
>                     // Open URL in browser
>                 }
>                 is CometChatCardChatWithUserAction -> {
>                     // Navigate to chat
>                 }
>             }
>         }
>     )
> }
> ```

> [tab] Traditional View
>
> ```kotlin theme={null}
> import com.cometchat.cards.CometChatCardView
> import com.cometchat.cards.core.CometChatCardThemeMode
>
> val cardView = CometChatCardView(context)
> cardView.setCardSchema(item.content.toString())
> cardView.setThemeMode(CometChatCardThemeMode.AUTO)
> cardView.setActionCallback { event ->
>     // Handle action: event.action, event.elementId
> }
> parentLayout.addView(cardView)
> ```

> [!NOTE]
>
> The Cards library is a pure renderer — it does not execute actions. Your code must handle action callbacks (opening URLs, navigating to chats, making API calls, etc.).

***

## How Cards Render in the Notification Feed

Each `NotificationFeedItem` has a `content` field containing a `JSONObject` — this is the **Card Schema JSON**. This JSON is passed directly to the **CometChat Cards** renderer library (`com.cometchat:cards-android`).

The rendering flow:

1. Fetch feed items via `NotificationFeedRequest`
2. For each item, extract `item.getContent()` — this is the Card Schema JSON
3. Convert to string: `item.getContent().toString()`
4. Pass to the Cards renderer (`CometChatCardView` or `CometChatCardComposable`)
5. The renderer produces a native Android view from the JSON

### Card Schema JSON Structure

```json theme={null}
{
  "version": "1.0",
  "body": [
    {
      "type": "column",
      "backgroundColor": {
        "light": "transparent",
        "dark": "transparent"
      },
      "gap": 5,
      "items": [
        {
          "type": "text",
          "content": "📢 Announcement",
          "variant": "heading2",
          "id": "txt_99323141-2459-4e33-88d3-ca39c5fd2f50"
        },
        {
          "type": "text",
          "content": "Your announcement message here.",
          "variant": "body",
          "id": "txt_61a417bc-5e4a-4ba2-bfe7-b7bc64dbaf35"
        },
        {
          "type": "divider",
          "id": "div_80f5c7fb-fd10-41d1-8c2f-51498f0f62d0"
        },
        {
          "type": "button",
          "label": "Learn More",
          "backgroundColor": {
            "light": "transparent",
            "dark": "transparent"
          },
          "textColor": {
            "light": "#6C5CE7",
            "dark": "#6C5CE7"
          },
          "size": 40,
          "fontSize": 13,
          "borderRadius": 6,
          "padding": {
            "top": 0,
            "right": 16,
            "bottom": 0,
            "left": 16
          },
          "action": {
            "type": "openUrl",
            "url": ""
          },
          "id": "btn_9b87a3f1-b0c6-45b9-a4c2-e22ea590f17f"
        }
      ],
      "id": "col_98fed9bd-1a95-4cee-aa81-84a9016e41f2"
    }
  ],
  "fallbackText": "",
  "style": {
    "background": {
      "light": "#E8E8E8",
      "dark": "#E8E8E8"
    },
    "borderRadius": 16,
    "borderColor": {
      "light": "#DFE6E9",
      "dark": "#DFE6E9"
    },
    "padding": 12
  }
}
```

The `body` array contains elements (text, image, button, row, column, etc.) rendered top-to-bottom. Interactive elements like buttons emit actions via a callback — the consumer handles navigation, deep links, or API calls.

***

## Retrieve Notification Feed Items

Use `NotificationFeedRequest` to fetch a paginated list of feed items. Uses cursor-based pagination internally.

### Build the Request

> [tab] Java
>
> ```java theme={null}
> NotificationFeedRequest request = new NotificationFeedRequest.NotificationFeedRequestBuilder()
>     .setLimit(20)
>     .build();
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val request = NotificationFeedRequest.NotificationFeedRequestBuilder()
>     .setLimit(20)
>     .build()
> ```

### Builder Parameters

| Method | Type | Default | Description |
| - | - | - | - |
| `setLimit(int)` | int | 20 | Items per page (max 100) |
| `setReadState(FeedReadState)` | enum | `ALL` | Filter by `READ`, `UNREAD`, or `ALL` |
| `setCategory(String)` | String | null | Filter by category ID |
| `setChannelId(String)` | String | null | Filter by channel |
| `setTags(List<String>)` | List | null | Filter by tags |
| `setDateFrom(String)` | String | null | ISO 8601 date — items sent on or after |
| `setDateTo(String)` | String | null | ISO 8601 date — items sent on or before |

### Fetch Items

> [!WARNING]
>
> **Starting with v5.1.0, the `CallbackListener` overload of \`fetchNext()\` is deprecated.** Use \`NotificationFeedFetchListener\` instead; it requires SDK 5.1.0 or later, so on 5.0.x keep using `CallbackListener`. With offline support off, it behaves exactly like the old callback: `onError` is unchanged, and the server result arrives in the `onServer…` callback instead of `onSuccess`. With offline support on, it also delivers the cached result first; the old overload keeps working but receives only the server result. See [Show Cached Data](https://www.cometchat.com/docs/sdk/android/v5/offline-cached-data.md).

> [tab] Java
>
> ```java theme={null}
> request.fetchNext(new CometChat.NotificationFeedFetchListener() {
>     @Override
>     public void onCachedNotificationFeedItems(List<NotificationFeedItem> items) {
>         // Cached page: fires first (even when empty). Render immediately.
>         for (NotificationFeedItem item : items) {
>             String cardJson = item.getContent().toString();
>             // Pass cardJson to CometChatCardView or CometChatCardComposable
>         }
>     }
>
>     @Override
>     public void onServerNotificationFeedItems(List<NotificationFeedItem> items) {
>         // Server page: reconcile your displayed list, keyed by item id.
>         for (NotificationFeedItem item : items) {
>             String cardJson = item.getContent().toString();
>             // Pass cardJson to CometChatCardView or CometChatCardComposable
>         }
>     }
>
>     @Override
>     public void onError(CometChatException e) {
>         Log.e("Feed", "Error: " + e.getMessage());
>     }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> request.fetchNext(object : CometChat.NotificationFeedFetchListener() {
>     override fun onCachedNotificationFeedItems(items: List<NotificationFeedItem>) {
>         // Cached page: fires first (even when empty). Render immediately.
>         items.forEach { item ->
>             val cardJson = item.content.toString()
>             // Pass cardJson to CometChatCardView or CometChatCardComposable
>         }
>     }
>
>     override fun onServerNotificationFeedItems(items: List<NotificationFeedItem>) {
>         // Server page: reconcile your displayed list, keyed by item id.
>         items.forEach { item ->
>             val cardJson = item.content.toString()
>             // Pass cardJson to CometChatCardView or CometChatCardComposable
>         }
>     }
>
>     override fun onError(e: CometChatException) {
>         Log.e("Feed", "Error: ${e.message}")
>     }
> })
> ```

Call `fetchNext()` repeatedly for pagination. When the server has no more items, subsequent calls return an empty list.

### NotificationFeedItem Fields

| Field | Type | Description |
| - | - | - |
| `id` | String | Unique item identifier |
| `category` | String | Notification category (e.g., "promotions") |
| `content` | JSONObject | Card Schema JSON — pass to CometChat Cards renderer |
| `readAt` | Long? | Unix timestamp when read, or null if unread |
| `deliveredAt` | Long? | Unix timestamp when delivered, or null |
| `sentAt` | long | Unix timestamp when sent |
| `metadata` | HashMap | Custom key-value metadata |
| `tags` | List\<String> | Tags for filtering |
| `receiver` | String | Receiver identifier |

***

## Offline Behaviour

With offline support enabled, `NotificationFeedRequest.fetchNext()` on a `NotificationFeedFetchListener` first delivers `onCachedNotificationFeedItems` from the device (empty when nothing was recorded), then `onServerNotificationFeedItems` with the live page to reconcile by item `id`. Offline, the read ends with `onError` with code `ERROR_INTERNET_UNAVAILABLE` after the cached page. See [Show Cached Data](https://www.cometchat.com/docs/sdk/android/offline-cached-data.md).

A `fetchNext()` call made while another fetch of the same request is still running ends with `onError` with code `ERROR_REQUEST_IN_PROGRESS`. Once the list has ended, a further `fetchNext()` asks the server again and delivers only items this request has not delivered before.

| Builder method | Offline |
| - | - |
| `setLimit` | Cached |
| `setReadState` | Cached |
| `setCategory` | Cached |
| `setChannelId` | Cached |
| `setTags` | Cached |
| `setDateFrom` | Cached |
| `setDateTo` | Cached |

## Retrieve Notification Categories

Use `NotificationCategoriesRequest` to fetch available categories for filter chips.

> [tab] Java
>
> ```java theme={null}
> NotificationCategoriesRequest categoriesRequest = new NotificationCategoriesRequest
>     .NotificationCategoriesRequestBuilder()
>     .setLimit(50)
>     .build();
>
> categoriesRequest.fetchNext(new CometChat.CallbackListener<List<NotificationCategory>>() {
>     @Override
>     public void onSuccess(List<NotificationCategory> categories) {
>         for (NotificationCategory category : categories) {
>             Log.d("Feed", "Category: " + category.getName());
>         }
>     }
>
>     @Override
>     public void onError(CometChatException e) {
>         Log.e("Feed", "Error: " + e.getMessage());
>     }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val categoriesRequest = NotificationCategoriesRequest.NotificationCategoriesRequestBuilder()
>     .setLimit(50)
>     .build()
>
> categoriesRequest.fetchNext(object : CometChat.CallbackListener<List<NotificationCategory>>() {
>     override fun onSuccess(categories: List<NotificationCategory>) {
>         categories.forEach { category ->
>             Log.d("Feed", "Category: ${category.name}")
>         }
>     }
>
>     override fun onError(e: CometChatException) {
>         Log.e("Feed", "Error: ${e.message}")
>     }
> })
> ```

### NotificationCategory Fields

| Field | Type | Description |
| - | - | - |
| `id` | String | Category identifier |
| `name` | String | Display name for filter UI |
| `description` | String | Category description |
| `appId` | String | Associated app ID |

***

## Real-Time Notification Feed Listener

Listen for new feed items arriving via WebSocket. This listener is independent from `MessageListener`, `GroupListener`, and `CallListener`.

> [tab] Java
>
> ```java theme={null}
> CometChat.addNotificationFeedListener("feedListener", new NotificationFeedListener() {
>     @Override
>     public void onFeedItemReceived(NotificationFeedItem feedItem) {
>         Log.d("Feed", "New item: " + feedItem.getId());
>         String cardJson = feedItem.getContent().toString();
>         // Insert at top of feed and render
>     }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> CometChat.addNotificationFeedListener("feedListener", object : NotificationFeedListener() {
>     override fun onFeedItemReceived(feedItem: NotificationFeedItem) {
>         Log.d("Feed", "New item: ${feedItem.id}")
>         val cardJson = feedItem.content.toString()
>         // Insert at top of feed and render
>     }
> })
> ```

Remove the listener when no longer needed:

> [tab] Java
>
> ```java theme={null}
> CometChat.removeNotificationFeedListener("feedListener");
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> CometChat.removeNotificationFeedListener("feedListener")
> ```

***

## Mark Feed Item as Read

Mark a single item as read. Idempotent — safe to call multiple times.

> [tab] Java
>
> ```java theme={null}
> CometChat.markFeedItemAsRead(feedItem, new CometChat.CallbackListener<Void>() {
>     @Override
>     public void onSuccess(Void unused) {
>         Log.d("Feed", "Marked as read");
>     }
>
>     @Override
>     public void onError(CometChatException e) {
>         Log.e("Feed", "Error: " + e.getMessage());
>     }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> CometChat.markFeedItemAsRead(feedItem, object : CometChat.CallbackListener<Void?>() {
>     override fun onSuccess(result: Void?) {
>         Log.d("Feed", "Marked as read")
>     }
>
>     override fun onError(e: CometChatException) {
>         Log.e("Feed", "Error: ${e.message}")
>     }
> })
> ```

***

## Mark Feed Item as Delivered

Mark a single item as delivered. Idempotent.

> [tab] Java
>
> ```java theme={null}
> CometChat.markFeedItemAsDelivered(feedItem, new CometChat.CallbackListener<Void>() {
>     @Override
>     public void onSuccess(Void unused) {
>         // Success
>     }
>
>     @Override
>     public void onError(CometChatException e) {
>         Log.e("Feed", "Error: " + e.getMessage());
>     }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> CometChat.markFeedItemAsDelivered(feedItem, object : CometChat.CallbackListener<Void?>() {
>     override fun onSuccess(result: Void?) { /* Success */ }
>     override fun onError(e: CometChatException) {
>         Log.e("Feed", "Error: ${e.message}")
>     }
> })
> ```

***

## Report Engagement

Report that a user engaged with a feed item (e.g., viewed, clicked, interacted). Idempotent.

> [tab] Java
>
> ```java theme={null}
> CometChat.reportFeedEngagement(feedItem, "clicked", new CometChat.CallbackListener<Void>() {
>     @Override
>     public void onSuccess(Void unused) { }
>
>     @Override
>     public void onError(CometChatException e) { }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> CometChat.reportFeedEngagement(feedItem, "clicked", object : CometChat.CallbackListener<Void?>() {
>     override fun onSuccess(result: Void?) { }
>     override fun onError(e: CometChatException) { }
> })
> ```

The `interactionString` parameter is a free-form string describing the engagement (e.g., `"viewed"`, `"clicked"`, `"interacted"`).

***

## Get Unread Count

Fetch the total number of unread notification feed items.

> [tab] Java
>
> ```java theme={null}
> CometChat.getNotificationFeedUnreadCount(new CometChat.CallbackListener<Integer>() {
>     @Override
>     public void onSuccess(Integer count) {
>         Log.d("Feed", "Unread: " + count);
>     }
>
>     @Override
>     public void onError(CometChatException e) {
>         Log.e("Feed", "Error: " + e.getMessage());
>     }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> CometChat.getNotificationFeedUnreadCount(object : CometChat.CallbackListener<Int>() {
>     override fun onSuccess(count: Int) {
>         Log.d("Feed", "Unread: $count")
>     }
>
>     override fun onError(e: CometChatException) {
>         Log.e("Feed", "Error: ${e.message}")
>     }
> })
> ```

***

## Fetch Single Feed Item

Fetch a specific item by ID — useful for deep linking from push notifications.

> [tab] Java
>
> ```java theme={null}
> CometChat.getNotificationFeedItem("item-id-123", new CometChat.CallbackListener<NotificationFeedItem>() {
>     @Override
>     public void onSuccess(NotificationFeedItem item) {
>         String cardJson = item.getContent().toString();
>         // Render the card
>     }
>
>     @Override
>     public void onError(CometChatException e) {
>         Log.e("Feed", "Error: " + e.getMessage());
>     }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> CometChat.getNotificationFeedItem("item-id-123", object : CometChat.CallbackListener<NotificationFeedItem>() {
>     override fun onSuccess(item: NotificationFeedItem) {
>         val cardJson = item.content.toString()
>         // Render the card
>     }
>
>     override fun onError(e: CometChatException) {
>         Log.e("Feed", "Error: ${e.message}")
>     }
> })
> ```

***

## Push Notification Tracking

When a campaign push notification arrives via FCM, use these methods to report delivery and click engagement.

### Mark Push Notification as Delivered

Call this in your `FirebaseMessagingService.onMessageReceived()`:

> [tab] Java
>
> ```java theme={null}
> PushNotification pushNotification = PushNotification.fromJson(pushPayloadJson);
>
> CometChat.markPushNotificationDelivered(pushNotification, new CometChat.CallbackListener<Void>() {
>     @Override
>     public void onSuccess(Void unused) { }
>
>     @Override
>     public void onError(CometChatException e) { }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> val pushNotification = PushNotification.fromJson(pushPayloadJson)
>
> CometChat.markPushNotificationDelivered(pushNotification, object : CometChat.CallbackListener<Void?>() {
>     override fun onSuccess(result: Void?) { }
>     override fun onError(e: CometChatException) { }
> })
> ```

### Mark Push Notification as Clicked

Call this when the user taps the push notification:

> [tab] Java
>
> ```java theme={null}
> CometChat.markPushNotificationClicked(pushNotification, new CometChat.CallbackListener<Void>() {
>     @Override
>     public void onSuccess(Void unused) { }
>
>     @Override
>     public void onError(CometChatException e) { }
> });
> ```

> [tab] Kotlin
>
> ```kotlin theme={null}
> CometChat.markPushNotificationClicked(pushNotification, object : CometChat.CallbackListener<Void?>() {
>     override fun onSuccess(result: Void?) { }
>     override fun onError(e: CometChatException) { }
> })
> ```

### PushNotification Fields

| Field | Type | Description |
| - | - | - |
| `id` | String | Announcement ID from the push payload |
| `announcementId` | String | Same as id (for clarity) |
| `campaignId` | String? | Campaign ID if from a campaign |
| `source` | String | Always `"campaign"` for notification feed pushes |

***

## FeedReadState Enum

| Value | Description |
| - | - |
| `READ` | Only read items |
| `UNREAD` | Only unread items |
| `ALL` | All items (default) |

***

## Supported Card Actions

When a user taps a button or link inside a card, the action callback receives one of these action types:

| Action Type | Parameters | Description |
| - | - | - |
| `openUrl` | url, openIn | Open a URL in browser or webview |
| `chatWithUser` | uid | Navigate to 1:1 chat |
| `chatWithGroup` | guid | Navigate to group chat |
| `sendMessage` | text, receiverUid, receiverGuid | Send a text message |
| `copyToClipboard` | value | Copy text to clipboard |
| `downloadFile` | url, filename | Download a file |
| `initiateCall` | callType (audio/video), uid, guid | Start a call |
| `apiCall` | url, method, headers, body | Make an HTTP request |
| `customCallback` | callbackId, payload | App-specific logic |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.