Capacitor and Ionic
Add Fload's attribution plugin to a Capacitor app, Ionic included. One plugin covers iOS and Android. It calls Fload's native SDKs underneath, so it behaves exactly like them.
What you need
- Capacitor 8 or later.
- iOS 15 or later, and Android API 24 or later.
- Your app's write key.
@revenuecat/purchases-capacitorin your app, if you want revenue per keyword. The plugin doesn't depend on it.
1. Install the plugin
npm install @fload-ai/attribution-capacitor
npx cap sync- iOS: set your deployment target to 15.0 or later. The plugin works with Swift Package Manager (Capacitor's default) and with CocoaPods.
- Android: the plugin adds the JitPack repository and the native SDK itself. You only add JitPack by hand if your
android/settings.gradleusesRepositoriesMode.FAIL_ON_PROJECT_REPOS:
// android/settings.gradle
dependencyResolutionManagement {
repositories {
maven {
url 'https://jitpack.io'
content { includeGroup 'com.github.fload-ai' }
}
}
}2. Start it at app start
Call FloadAttribution.configure once, as your app starts. It returns at once; the work runs in the background on the native side. A second call is ignored.
import { Capacitor } from '@capacitor/core';
import { FloadAttribution } from '@fload-ai/attribution-capacitor';
import { Purchases } from '@revenuecat/purchases-capacitor';
export async function startAttribution() {
await Purchases.configure({
apiKey: Capacitor.getPlatform() === 'ios' ? 'appl_…' : 'goog_…',
});
await FloadAttribution.configure({ key: 'fload_pk_…' });
const { appUserID } = await Purchases.getAppUserID();
await FloadAttribution.setUserId({ id: appUserID });
}On the web, the plugin checks its arguments and sends nothing. Attribution only exists in the native apps.
3. Link the user after login
When a user logs in, RevenueCat's id changes. Send the new one too:
await Purchases.logIn({ appUserID: 'user_123' });
const { appUserID } = await Purchases.getAppUserID();
await FloadAttribution.setUserId({ id: appUserID });Fload keeps every id an install has had, so purchases before and after login both count.
4. Check it works
Turn on debug logs while you test:
await FloadAttribution.configure({ key: 'fload_pk_…', logLevel: 'debug' });Run on a real iPhone and a real Android phone, and look for the native logs: the subsystem com.fload.attribution on iOS, and the Logcat tag FloadAttribution on Android. Remove the debug option before you ship.
5. Ship it
Ship a new store build. A live web update can't add native code, so it can't add the plugin. Fill in Privacy for both stores.
Reference
| Call | What it does |
|---|---|
configure({ key, logLevel? }) | Starts the SDK. Call once, at app start. logLevel is 'none', 'error', 'warning' (the default), 'info' or 'debug' |
setUserId({ id }) | Links your user id to this install |
getInstallReference() | Resolves to { installReference }: this install's random reference, for support questions. null until the SDK has loaded |
Every call returns a Promise. configure rejects an empty key or an unknown log level.
Source code and changelog: github.com/fload-ai/fload-attribution-capacitor.