genius_sdk 1.1.0
genius_sdk: ^1.1.0 copied to clipboard
Genius attribution for Flutter: install and open tracking, events and deep links on Android, iOS and macOS.
genius_sdk #
Flutter plugin for the Genius attribution SDK. It bridges the native SDKs (Android
GeniusSDK, Apple
GeniusSDKFramework) and adds deep-link handling on top of
app_links.
Supports Android 5.0+ (API 21), iOS 13+ and macOS 12+. Apps that also run on the web can keep their calls: there the native calls do nothing and return empty values.
Installation #
flutter pub add genius_sdk
Android #
The native SDK (com.github.socal-ltd:GeniusSDK:1.1.0) is served by JitPack. Add the repository to every project
in the app's android/build.gradle:
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
For deep links, add an intent filter to the main activity and follow app_links' Android setup:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="your-apps-domain" />
</intent-filter>
iOS and macOS #
The pod depends on GeniusSDKFramework 1.1.0, which pod install fetches.
- Add
NSUserTrackingUsageDescriptiontoInfo.plistif the App Tracking Transparency prompt should be shown; without it the prompt is skipped. - For deep links (Associated Domains or a URL scheme), follow app_links' iOS and macOS setup.
- macOS needs a deployment target of 12.0 or later in both
macos/Podfile(platform :osx, '12.0') and the Runner target (Xcode › Runner › General › Minimum Deployments,MACOSX_DEPLOYMENT_TARGET), and sandboxed apps need thecom.apple.security.network.cliententitlement.
Usage #
import 'package:genius_sdk/genius_sdk.dart';
final geniusSdk = GeniusSdk();
// Optional, before connect(): turn off what the app doesn't want.
// await geniusSdk.setReadsPasteboard(false);
// await geniusSdk.setRequestsTrackingAuthorization(false);
// Not awaited: on the install launch the link data can arrive first.
geniusSdk.connect().then((launch) {
// The launch payload (install or open), or {}.
});
// On the install launch (unless stopped), the install attribution, then the opening link's
// parameters if any; otherwise the opening link's parameters. Then those of every later link.
await geniusSdk.dynamicLinkInit((data) {
// navigate with data
});
await geniusSdk.logEvent(EventName.deposit, {
EventParam.revenue: 9.99,
EventParam.currency: 'USD',
});
final link = geniusSdk.buildDynamicLink('https://your-apps-domain/open', {'leagueId': 42});
// https://your-apps-domain/open?leagueId=42
Events emitted by the native SDK arrive on onEvent:
final subscription = geniusSdk.onEvent.listen((event) {
if (event['eventName'] == GeniusEvents.firstEvent) {
// event['params'] holds the event's data, decoded from JSON.
}
});
await geniusSdk.triggerTestEvent(); // Emits GeniusEvents.firstEvent.
The example app shows the launch payload, link data and events on screen.
API #
| Member | Description |
|---|---|
GeniusSdk() |
The shared instance: every call returns the same object. |
connect() |
Resolves attribution and logs the launch event (install or open). Runs once per process; later calls await the same run. Returns the launch payload, or {} while stopped or when the app launched in the background (the launch is then logged on the first foreground). |
logEvent(eventName, [eventValue]) |
Stores the event durably and completes; it is sent in order, with retries. Events logged before connect() are sent after the launch event, except after a background launch, where they can be sent before it. Never throws. |
isFirstOpen |
Whether this process is the app's install launch. Valid before connect() finishes; no side effects. Stays true until the install is recorded, so it is true on every launch while the SDK has been stopped since the install. |
getDeferredData() |
Install attribution as string values, once connect() resolves it (Android: Play Install Referrer, waits at most about 17.5 s; iOS: pasteboard, at most 61 s). |
getDynamicLinkData() |
getDeferredData() on the install launch, unless stopped, otherwise getInitialLinkParams(); {} when there is nothing. Also sets dynamicLinkData. After a later stop(false) on the install launch, read the install attribution with getDeferredData(). |
dynamicLinkInit(callback) |
Calls callback with getDynamicLinkData(); on the install launch (unless stopped) then with getInitialLinkParams() when a link opened the app; then onLink(callback). |
deepLinkInit(callback) |
Calls callback once with getInitialLinkParams(), then onLink(callback). |
getInitialLinkParams() |
Query parameters of the link that opened the app, or null. |
onLink(callback) |
Calls callback with the query parameters of every link opened from now on, and of the link that opened the app unless getInitialLinkParams() has already returned it. One subscription: a new call replaces the previous callback. |
dynamicLinkData |
The last link or attribution data delivered. |
buildDynamicLink(url, [params]) |
Appends params form-encoded and sorted by key, before any #fragment. |
onEvent / triggerTestEvent() |
Events from the native SDK as {'eventName': String, 'params': Object?}; triggerTestEvent() emits GeniusEvents.firstEvent. |
stop(isStopped) / isStopped |
Persisted. Stopping clears pending events and drops new ones; a connect() made while stopped runs on stop(false). |
setMinTimeBetweenSessions(seconds) |
Returning to the app after at least this long in the background logs a session event. |
setDebugLogging(enabled) |
Native logs, payloads included (Logcat tag GeniusSDK, os_log subsystem com.eshkol.genius), and the plugin's own messages through debugPrint. |
setCollectAndroidId(enabled) |
Persisted. Android only: sends android_id while enabled; setCollectAndroidId(false) stops it. |
setRequestsTrackingAuthorization(enabled) |
iOS and macOS, before connect(): whether connect() shows the App Tracking Transparency prompt. |
setReadsPasteboard(enabled) |
iOS only, before connect(): whether the install launch reads attribution copied by the Genius landing page (iOS 16+ may show the "Allow Paste" alert). |
EventName, EventParam, GeniusEvents |
Predefined event names (EventName.custom(name) for others), revenue / currency value keys, test event names. |
Defaults #
| Setting | Default |
|---|---|
App Tracking Transparency prompt during connect() |
on (iOS, macOS; only when NSUserTrackingUsageDescription is declared) |
| Pasteboard read on the install launch | on (iOS) |
session events |
after 5 seconds in the background; setMinTimeBetweenSessions(0) disables them |
android_id |
off |
| Debug logging | off |
Behavior #
- One native engine per process serves every caller, including every Flutter engine; calls apply in call order,
except that on iOS and macOS a call made right after
connect()may apply before it. - Events are queued on disk and survive restarts. Network errors and HTTP 408, 425, 429 and 5xx are retried with backoff (4 s doubling up to 5 minutes); an event is dropped after 10 failed responses or on any other status. Being offline never drops events. The queue keeps the latest 200 events.
- Link parameters follow the query rules shared by every Genius SDK:
+is a space, keys and values are percent-decoded separately (a malformed escape is kept as written) and the last repeated key wins. Values are always strings. - The link that opened the app reaches the link callback once, although app_links replays it on its link stream.
That replay goes only to the stream's first listener: if the app listens to app_links before the SDK does,
onLinkdoes not get it, and oncegetInitialLinkParams()has returned the link (asdynamicLinkInitanddeepLinkInitdo), re-opening that same link as the first link afterwards is not delivered, because the SDK cannot tell that re-open from the replay. buildDynamicLinkusesapplication/x-www-form-urlencodedencoding, writesnullas an empty value and maps or lists as JSON, and joins with&when the URL already has a query.
Backend notes #
- The backend (
neuron.eshkol.io/app_sdk→ BigQueryappsdk_log) rejects a whole insert batch when a row carries an unknown non-null key, so the SDKs send exactly the existing columns. - Since 1.1.0,
event_timeis UTC (sameyyyy-MM-dd HH:mm:ss.SSSformat, no offset) andsessionis a new event name;openstill means a cold start. - Delivery is at least once: a response lost after the server stored a row produces a duplicate row.
- Device fields are collected once per session; an event sent later carries those of the session that sends it.
event_id(server-side dedupe),timezoneandcustomer_user_idare not sent yet. Each needsALTER TABLE appsdk_log ADD COLUMN …and fluentdignore_unknown_values truedeployed before any SDK sends it.
See CHANGELOG.md for what changed in 1.1.0.
Development #
flutter pub get
flutter analyze # the plugin and the example
flutter test # the plugin's Dart tests
(cd example && flutter test) # the example app's widget test
- Android bridge unit tests:
cd example/android && ./gradlew :genius_sdk:testDebugUnitTest(after aflutter build apkinexamplehas generated the Gradle wrapper). - iOS bridge unit tests: the
RunnerTeststarget inexample/ios/Runner.xcworkspace. - The fixtures in
test/fixturesare shared with the other Genius SDKs; keep them identical. - To try an unpublished native SDK, resolve
com.github.socal-ltd:GeniusSDKfrommavenLocal()inexample/android/build.gradle, and addpod 'GeniusSDKFramework', :path => '<path to the pod repo>'toexample/ios/Podfile. Revert both before releasing.