Skip to content
Menu

Content cards

Default feed

Markdown version

Show content cards with the built-in SwiftUI and Compose feed, which orders, dismisses and logs cards for you.

Add one view and your app shows the signed-in user's content cards, with impressions, clicks and dismissals logged for you.

Before you start

  • The SDK is configured and the user is identified. See Quickstart: iOS or Quickstart: Android.
  • iOS: your target links the HeraldUI library as well as HeraldSDK.
  • Android: your app depends on herald-ui as well as herald-core.

1. Add the feed

swift
import SwiftUI
import HeraldUI

struct InboxView: View {
    var body: some View {
        NavigationStack {
            ContentCardFeed()
                .navigationTitle("For you")
        }
    }
}

From UIKit, wrap the feed in a hosting controller: UIHostingController(rootView: ContentCardFeed()). From an Android View layout, host it in a ComposeView.

iOSAndroid
The default content card feed on iOSThe default content card feed on Android

2. Let users refresh

The feed updates on its own when a sync brings new cards. Syncs run at session start and when a user is identified. To fetch on demand, for example when the user opens the inbox, call refreshContentCards():

swift
ContentCardFeed()
    .onAppear { Herald.shared.refreshContentCards() }

What the feed does

BehaviorDetail
OrderPinned cards first, then newest first. Cards that sort equal keep Herald's order.
ImpressionsLogged once per card per session, the first time at least half of the card is on screen. Rebuilding the feed or relaunching the app within the session does not log it again.
ClicksA tap logs the click, then opens the card's url. On iOS the URL goes to Herald.shared.deepLinkHandler first, then to the system. On Android it opens with an ACTION_VIEW intent. Cards without a url are not tappable.
DismissalDismissible cards can be swiped away. Screen reader users get a Dismiss action. The card disappears at once, the dismissal is logged, and it does not come back on the next sync.
Empty state"No updates right now", in the theme's secondary text color.
Expired cardsLeft out. A card that expires while the feed is open goes away at its expiry time, without a sync.
Sign-outAfter reset() or a user switch, the feed empties until the new user's cards arrive.

Card views use the theme's colors, fonts, corner radius and spacing, follow the system light or dark setting, scale with Dynamic Type and Android font size, and keep every tappable card at least 44 pt (iOS) or 48 dp (Android) tall.

Verify it works

  1. Run the app, sign in, and have an agent send a content card to that user through the same connection.
  2. Pull the card in with a new session or a refreshContentCards() call. It appears at the top of the feed.
  3. Tap it. Your deep link opens. The click reaches Herald with the next batch and is credited to the agent's decision.
  4. Swipe it away and relaunch the app. It stays gone.

Troubleshooting

  • The feed is always empty. The user is not identified, or identity verification rejects the sync. Check that you call setUserToken after identify. With verification set to Optional, a sync without a token returns no cards.
  • A card does nothing when tapped. It has no url. Give the message variant a deep link, or handle taps yourself with onCardClick (see Customizing the feed).
  • A deep link opens the browser instead of the app (iOS). Set Herald.shared.deepLinkHandler to route your scheme inside the app, or register the scheme in your Info.plist.
  • A card the agent sent never shows. Herald suppresses card sends to users who have no SDK device on that connection yet. Send again after the user has run the app once.

Next

See Herald decide live →