Launch offer for the first 500 accounts: $10K MTR free for 24 months + $100 credit →
    .io
    Paywalls
    Any platform
    Intermediate
    42 min

    Build your own paywall UI in a native app (headless)

    To build a headless paywall in a native app with BillDog, call getOffering(placement:) (iOS) or BillDog.getOffering(placement) (Android, Flutter, React Native) to get the offering the dashboard assigned to a placement, render its packages in your own UI, and buy with purchase(package:) or purchasePackage. Call trackPaywallPresented when your screen appears so impressions count, and show nothing when the result is a holdout or withheld.

    Steps last checked against the SDK source on 16 Nov 2026.

    What you'll build

    • A paywall screen drawn entirely by your code, selling the offering the dashboard picks
    • Purchases attributed to the placement, offering and experiment arm
    • Impressions recorded for offering conversion rates
    • Correct handling of holdouts, excluded audiences and subscribers

    What you'll need

    1. Set up the offering and placement

    6 min

    A headless read needs no paywall design. It needs an offering linked to a placement. If you followed a first-paywall codelab, you already have this and can skip ahead.

    1. Monetization → Products → New Product with your App Store Product ID and Play Store Product ID.
    2. Monetization → Entitlements: create premium and tick the product under Product Mapping.
    3. Monetization → Offerings → New Offering, then Create Offering. In the editor, Add Product, type a Package Identifier such as monthly, Add Package, Save Changes.
    4. Monetization → Placements → Create Placement with the identifier onboarding. Click the link icon on its row, tick the offering, tick Default and click Link Offerings.

    Unlike register, a headless read never creates a placement. An identifier that doesn't exist fails with PLACEMENT_NOT_FOUND instead of quietly selling the default offering. A placement with no offering linked returns no offering.

    2. Make sure impressions are recorded

    3 min

    A hosted paywall records its own impression. Yours can't, so you call trackPaywallPresented (step 3). That event is uploaded by the analytics module:

    • iOS (BillDogFull), Flutter and React Native: the module is registered for you. Nothing to do.
    • Android native: add billdog-analytics and register it. Without it, trackPaywallPresented reaches your delegate but is never uploaded.
    app/build.gradle.kts
    dependencies {
        implementation("io.billdog:billdog-compose:1.2.0-beta.1")
        implementation("io.billdog:billdog-paywall:1.2.0-beta.1")   // Google Play Billing
        implementation("io.billdog:billdog-analytics:1.2.0-beta.1") // uploads impressions
    }
    MyApplication.kt
    import android.app.Application
    import io.billdog.analytics.BillDogAnalytics
    import io.billdog.core.BillDog
    
    class MyApplication : Application() {
        override fun onCreate() {
            super.onCreate()
            val analytics = BillDogAnalytics()
            BillDog.use(analytics)
            analytics.initializeAutoTracking(this) // opens the event queue; events are dropped without it
            BillDog.configure(this, "bd_public_test_YOUR_KEY")
        }
    }

    3. iOS: fetch, render and buy in SwiftUI

    10 min

    getOffering(placement:) is async throws and returns a PlacementOffering: the offering, a presentation block, and any experiment or campaign. shouldPresent is true only when there is an offering and the user is neither held out nor excluded. Each Package carries its store price in localizedPriceString and its name in resolvedDisplayName.

    HeadlessPaywallView.swift
    import SwiftUI
    import BillDogFull
    
    struct HeadlessPaywallView: View {
        let onUnlocked: () -> Void   // your code: unlock and close
        let onSkip: () -> Void       // your code: continue without a paywall
    
        private let placement = "onboarding"
        @State private var offering: Offering?
        @State private var errorText: String?
    
        var body: some View {
            VStack(spacing: 12) {
                if let offering {
                    Text("Unlock Premium").font(.title.bold())
                    ForEach(offering.packages, id: \.identifier) { pkg in
                        Button("\(pkg.resolvedDisplayName) · \(pkg.localizedPriceString)") {
                            Task { await buy(pkg) }
                        }
                        .buttonStyle(.borderedProminent)
                    }
                    if let errorText { Text(errorText).foregroundStyle(.red) }
                    Button("Not now") { onSkip() }
                }
            }
            .padding()
            .task { await load() }
            .onDisappear {
                if let offering {
                    BillDog.shared.trackPaywallDismissed(offering: offering, placement: placement)
                }
            }
        }
    
        private func load() async {
            do {
                let result = try await BillDog.shared.getOffering(placement: placement)
                guard result.shouldPresent, let offering = result.offering else {
                    onSkip() // holdout, excluded, or nothing linked
                    return
                }
                BillDog.shared.trackPaywallPresented(offering: offering, placement: placement)
                self.offering = offering
            } catch BillDogError.placementNotFound {
                print("No placement called \(placement): check the identifier")
                onSkip()
            } catch {
                onSkip()
            }
        }
    
        private func buy(_ pkg: Package) async {
            do {
                switch try await BillDog.shared.purchase(package: pkg) {
                case .purchased, .restored:
                    onUnlocked()
                case .failed(let error):
                    errorText = "Purchase failed: \(error)"
                case .cancelled, .pending:
                    break
                @unknown default:
                    break
                }
            } catch {
                errorText = "Purchase failed: \(error)"
            }
        }
    }

    Buy with purchase(package:), not purchase(productId:). The package returned by getOffering is stamped with its placement, offering and experiment arm, and that context travels with the purchase, so revenue is attributed to the right placement and variant.

    If a price shows as a plain dollar amount such as $9.99 for every country, StoreKit didn't return the product and the SDK fell back to the dashboard's USD price. Check the App Store Product ID and your sandbox setup (Test real App Store purchases).

    4. Android: fetch, render and buy in Jetpack Compose

    10 min

    On Android, BillDog.getOffering(placement) is a suspend function. It returns a PlacementOffering with the same fields and shouldPresent, and throws BillDogException (its error is a typed BillDogError, such as PlacementNotFound). BillDog.purchase(activity, pkg) needs the Activity that launches Google Play's purchase sheet.

    HeadlessPaywall.kt
    import android.app.Activity
    import android.util.Log
    import androidx.compose.foundation.layout.Column
    import androidx.compose.material3.Button
    import androidx.compose.material3.Text
    import androidx.compose.material3.TextButton
    import androidx.compose.runtime.*
    import androidx.compose.ui.platform.LocalContext
    import io.billdog.core.BillDog
    import io.billdog.core.BillDogError
    import io.billdog.core.BillDogException
    import io.billdog.core.PurchaseResult
    import io.billdog.core.models.Offering
    import io.billdog.core.models.Package
    import kotlinx.coroutines.launch
    
    private const val PLACEMENT = "onboarding"
    
    @Composable
    fun HeadlessPaywall(onUnlocked: () -> Unit, onSkip: () -> Unit) {
        val activity = LocalContext.current as Activity
        val scope = rememberCoroutineScope()
        var offering by remember { mutableStateOf<Offering?>(null) }
        var error by remember { mutableStateOf<String?>(null) }
    
        LaunchedEffect(Unit) {
            try {
                val result = BillDog.getOffering(PLACEMENT)
                val loaded = result.offering
                if (result.shouldPresent && loaded != null) {
                    BillDog.trackPaywallPresented(loaded, PLACEMENT)
                    offering = loaded
                } else {
                    onSkip() // holdout, excluded, or nothing linked
                }
            } catch (e: BillDogException) {
                if (e.error is BillDogError.PlacementNotFound) Log.w("BillDog", "No placement called $PLACEMENT")
                onSkip()
            }
        }
    
        DisposableEffect(offering) {
            val shown = offering
            onDispose { if (shown != null) BillDog.trackPaywallDismissed(shown, PLACEMENT) }
        }
    
        val current = offering ?: return
        Column {
            Text("Unlock Premium")
            current.packages.forEach { pkg: Package ->
                Button(onClick = {
                    scope.launch {
                        when (val r = BillDog.purchase(activity, pkg)) {
                            is PurchaseResult.Purchased, is PurchaseResult.Restored -> onUnlocked()
                            is PurchaseResult.Failed -> error = "Purchase failed: ${r.error.message}"
                            else -> Unit // Cancelled, Pending
                        }
                    }
                }) {
                    Text("${pkg.storeProduct?.title ?: pkg.identifier} · ${pkg.localizedPriceString}")
                }
            }
            error?.let { Text(it) }
            TextButton(onClick = onSkip) { Text("Not now") }
        }
    }

    purchase(activity, pkg) buys the package's own Play product and offer, attributed to the package's placement and offering, the same way iOS does. If your context is wrapped (a themed ContextWrapper), replace the as Activity cast with a findActivity() helper.

    5. Flutter and React Native

    8 min

    In Flutter, BillDog.shared.getOffering(placement) never throws. It returns a sealed OfferingResult: OfferingAvailable, OfferingHoldout, OfferingWithheld, OfferingNotConfigured or OfferingFailed. Buy with purchasePackage.

    headless_paywall.dart
    import 'package:flutter/material.dart';
    import 'package:billdog_flutter/billdog_flutter.dart';
    
    class HeadlessPaywall extends StatefulWidget {
      const HeadlessPaywall({super.key, required this.onUnlocked, required this.onSkip});
      final VoidCallback onUnlocked; // your code: unlock and close
      final VoidCallback onSkip;     // your code: continue without a paywall
    
      @override
      State<HeadlessPaywall> createState() => _HeadlessPaywallState();
    }
    
    class _HeadlessPaywallState extends State<HeadlessPaywall> {
      static const placement = 'onboarding';
      Offering? _offering;
    
      @override
      void initState() {
        super.initState();
        _load();
      }
    
      Future<void> _load() async {
        final result = await BillDog.shared.getOffering(placement);
        if (result case OfferingAvailable(:final offering)) {
          await BillDog.shared.trackPaywallPresented(offering: offering, placement: placement);
          if (mounted) setState(() => _offering = offering);
        } else {
          if (result is OfferingFailed && result.error is PlacementNotFoundError) {
            debugPrint('No placement called $placement');
          }
          widget.onSkip(); // holdout, withheld, nothing linked, or failed
        }
      }
    
      @override
      void dispose() {
        final shown = _offering;
        if (shown != null) BillDog.shared.trackPaywallDismissed(offering: shown, placement: placement);
        super.dispose();
      }
    
      Future<void> _buy(Package package) async {
        switch (await BillDog.shared.purchasePackage(package)) {
          case Purchased() || Restored():
            widget.onUnlocked();
          case Failed(:final error):
            debugPrint('Purchase failed: ${error.message}');
          case Cancelled() || Pending():
            break;
        }
      }
    
      @override
      Widget build(BuildContext context) {
        final offering = _offering;
        if (offering == null) return const SizedBox.shrink();
        return Column(children: [
          for (final pkg in offering.packages)
            FilledButton(
              onPressed: () => _buy(pkg),
              child: Text('${pkg.product?.name ?? pkg.identifier} · ${pkg.localizedPriceString}'),
            ),
          TextButton(onPressed: widget.onSkip, child: const Text('Not now')),
        ]);
      }
    }

    In React Native, BillDog.getOffering(placement) resolves with { offering, offerings, placement, presentation, experiment, campaign } and rejects with a typed error such as PlacementNotFoundError. purchasePackage resolves with a result whose type is purchased, restored, cancelled, pending or failed. Expo apps can import the same names from @billdog.io/expo.

    HeadlessPaywall.tsx
    import { useEffect, useState } from 'react';
    import { Button, View } from 'react-native';
    import { BillDog, PlacementNotFoundError, type Offering, type Package } from '@billdog.io/react-native';
    
    const PLACEMENT = 'onboarding';
    
    export function HeadlessPaywall({ onUnlocked, onSkip }: { onUnlocked: () => void; onSkip: () => void }) {
      const [offering, setOffering] = useState<Offering | null>(null);
    
      useEffect(() => {
        (async () => {
          try {
            const result = await BillDog.getOffering(PLACEMENT);
            const { offering: loaded, presentation } = result;
            if (loaded && !presentation.holdout && !presentation.withheld) {
              BillDog.trackPaywallPresented(loaded, result.placement);
              setOffering(loaded);
            } else {
              onSkip(); // holdout, excluded, or nothing linked
            }
          } catch (e) {
            if (e instanceof PlacementNotFoundError) console.warn('Check the placement identifier');
            onSkip();
          }
        })();
      }, []);
    
      async function buy(pkg: Package) {
        const r = await BillDog.purchasePackage(pkg);
        if (r.type === 'purchased' || r.type === 'restored') onUnlocked();
        else if (r.type === 'failed') console.warn('Purchase failed', r.error);
      }
    
      if (!offering) return null;
      return (
        <View>
          {offering.packages.map((pkg) => (
            <Button
              key={pkg.identifier}
              title={`${pkg.product?.displayName ?? pkg.identifier} · ${pkg.product?.priceString ?? ''}`}
              onPress={() => buy(pkg)}
            />
          ))}
          <Button title="Not now" onPress={onSkip} />
        </View>
      );
    }

    6. Handle holdouts, subscribers and experiments

    5 min
    • Holdout (presentation.holdout): a campaign put this user in its holdout group to measure what happens without a paywall. Show nothing and don't call trackPaywallPresented. The server records the holdout when it answers.
    • Withheld (presentation.withheld): the server excluded this user, and withheldReason says why (holdout, audience_excluded or wall_inactive). Show nothing.
    • Subscribers: a headless read doesn't skip users who already pay. With Requires access on, presentation.gated is true and presentation.requiredEntitlement names the entitlement, but the offering still comes back. Check the entitlement yourself before showing the paywall.
    Swift
    // Before presenting HeadlessPaywallView
    let info = try await BillDog.shared.getCustomerInfo()
    if info.hasEntitlement("premium") {
        // already subscribed: open the feature instead of the paywall
    }
    Kotlin
    // Inside a coroutine, before showing HeadlessPaywall
    val subscribed = BillDog.getCustomerInfo().getOrNull()?.hasEntitlement("premium") == true

    Experiments. A headless read follows the placement's campaign. When the campaign runs an experiment (Engagement → Campaigns), the server assigns the arm, records the exposure and returns it in experiment (experimentId, variantId, variantName). Each arm can sell a different offering, so a price test needs no app change. A Paywall experiment under A/B Tests swaps hosted paywall designs and does not split headless reads.

    To check it end to end, switch the dashboard header to Sandbox, make a test purchase, and open Customers: the purchase and the premium entitlement should be there.

    Frequently asked questions

    A paywall you draw yourself. BillDog supplies the offering selected for a placement, its packages and store prices, any experiment arm and the holdout decision. Your app renders the UI and calls purchase(package:) or purchasePackage, and BillDog records the purchase and entitlement.

    Yes. A hosted paywall records its own impression, but BillDog can't see your view, so without the call your offering shows purchases with no impressions. On native Android the billdog-analytics module must also be registered for the event to be uploaded.

    The identifier doesn't match a placement in the project (identifiers are case-sensitive). Unlike register, a headless read never creates the placement or falls back to the default offering. Create it under Monetization → Placements, or fix the typo.

    No. In headless mode the app owns the gate: presentation.gated and presentation.requiredEntitlement tell you the placement requires access, but the offering is still returned. Check the entitlement with getCustomerInfo before showing your paywall.

    Yes, through a campaign that runs an experiment on the placement. The server assigns the arm and returns it in experiment, and each arm can sell a different offering. Paywall experiments, which swap hosted designs, don't apply to headless reads.

    Reference

    Ship it on a free project

    Create a project, grab your SDK key and follow along. Sandbox purchases and data stay separate from production, so test transactions never mix with real revenue.

    We use cookies and process your data to provide our services. By continuing, you agree to our Terms and Privacy Policy.