@traqio/react-native 0.2.7 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/android/build.gradle +2 -2
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/java/io/khufu/traqio/expo/MetaInstallReferrer.kt +61 -0
- package/android/src/main/java/io/khufu/traqio/expo/MetaInstallReferrerReader.kt +50 -0
- package/android/src/main/java/io/khufu/traqio/expo/TraqioModule.kt +15 -1
- package/build/native.d.ts +24 -1
- package/build/native.d.ts.map +1 -1
- package/build/native.js +118 -76
- package/build/native.js.map +1 -1
- package/package.json +2 -2
- package/src/native.ts +126 -72
package/README.md
CHANGED
|
@@ -148,6 +148,14 @@ Traqio.init({ sdkKey: "SDK_KEY", endpoint: "https://api.traqio.app", collectAdve
|
|
|
148
148
|
- **Android**: add `com.google.android.gms:play-services-ads-identifier` and the
|
|
149
149
|
`com.google.android.gms.permission.AD_ID` permission; nothing is sent when the user
|
|
150
150
|
limited ad tracking.
|
|
151
|
+
- **Your app asks for consent after the first launch** (GDPR CMP, ATT after onboarding)?
|
|
152
|
+
Start with `waitForAdvertisingIdConsent: true` and report the answer — the id is not read
|
|
153
|
+
before it, and the install's Meta / TikTok postback waits up to one hour for it:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
Traqio.init({ sdkKey: "SDK_KEY", endpoint: "https://api.traqio.app", waitForAdvertisingIdConsent: true });
|
|
157
|
+
await Traqio.setAdvertisingIdConsent(userAgreed); // after your CMP / ATT prompt
|
|
158
|
+
```
|
|
151
159
|
|
|
152
160
|
It goes with the install, or once later when ATT is granted after the first launch. Traqio
|
|
153
161
|
matches it hashed against tracked clicks, keeps it on that install, and sends it to Meta
|
|
@@ -155,6 +163,21 @@ matches it hashed against tracked clicks, keeps it on that install, and sends it
|
|
|
155
163
|
TikTok with the device's later conversions. Dropped when the user denies consent or
|
|
156
164
|
withdraws ATT. Never used as the user's identity.
|
|
157
165
|
|
|
166
|
+
## Meta Install Referrer (Android)
|
|
167
|
+
|
|
168
|
+
Meta's own Install Referrer is read from the Facebook, Instagram and Facebook Lite apps on the first launch. It attributes the installs the Play referrer cannot see: **view-through** installs (an ad seen, not tapped) and clicks that did not go straight to the Play Store. Traqio decrypts it on the server with the same **Install Referrer Decryption Key** you paste for the Play referrer (Integrations → Meta install referrer). Reports split a Meta click (`deterministic`) from a Meta view (`view_through`).
|
|
169
|
+
|
|
170
|
+
Pass your Facebook App ID as `metaAppId` in `init()`. If you leave it out, the SDK uses the `com.facebook.sdk.ApplicationId` meta-data from your manifest, which the Facebook SDK sets:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
await Traqio.init({ sdkKey, endpoint, native: getNativeBridge(), metaAppId: "1234567890" });
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
- The library manifest already declares the `<queries>` for `com.facebook.katana`, `com.instagram.android` and `com.facebook.lite`. You add nothing.
|
|
177
|
+
- Meta requires Facebook v428+, Instagram v296+ or Facebook Lite v411+ on the device. An older app, or none, means nothing is read.
|
|
178
|
+
- A view credits an install only if the app has a **view-through window** set in Traqio. With no window, the install stays organic with the note `meta_view_through_off`.
|
|
179
|
+
- Source: https://developers.facebook.com/docs/app-ads/meta-install-referrer
|
|
180
|
+
|
|
158
181
|
## Ad revenue (AdMob, AppLovin MAX)
|
|
159
182
|
|
|
160
183
|
```ts
|
package/android/build.gradle
CHANGED
|
@@ -6,7 +6,7 @@ apply plugin: 'kotlin-android'
|
|
|
6
6
|
apply plugin: 'maven-publish'
|
|
7
7
|
|
|
8
8
|
group = 'io.khufu.traqio'
|
|
9
|
-
version = '0.
|
|
9
|
+
version = '0.3.1'
|
|
10
10
|
|
|
11
11
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
12
12
|
apply from: expoModulesCorePlugin
|
|
@@ -28,7 +28,7 @@ android {
|
|
|
28
28
|
defaultConfig {
|
|
29
29
|
minSdk safeExtGet("minSdkVersion", 24)
|
|
30
30
|
versionCode 1
|
|
31
|
-
versionName "0.
|
|
31
|
+
versionName "0.3.1"
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
compileOptions {
|
|
@@ -9,4 +9,16 @@
|
|
|
9
9
|
<action android:name="com.google.android.finsky.BIND_GET_INSTALL_REFERRER_SERVICE" />
|
|
10
10
|
</intent>
|
|
11
11
|
</queries>
|
|
12
|
+
<!-- Meta's own Install Referrer (todo cmwy39da): the Facebook, Instagram and Facebook
|
|
13
|
+
Lite apps' content providers are invisible on Android 11+ without these, exactly as
|
|
14
|
+
https://developers.facebook.com/docs/app-ads/meta-install-referrer lists them. -->
|
|
15
|
+
<queries>
|
|
16
|
+
<package android:name="com.facebook.katana" />
|
|
17
|
+
</queries>
|
|
18
|
+
<queries>
|
|
19
|
+
<package android:name="com.instagram.android" />
|
|
20
|
+
</queries>
|
|
21
|
+
<queries>
|
|
22
|
+
<package android:name="com.facebook.lite" />
|
|
23
|
+
</queries>
|
|
12
24
|
</manifest>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
package io.khufu.traqio.expo
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The Android-free half of Meta's own Install Referrer read (todo cmwy39da), kept
|
|
5
|
+
* apart so it runs on a plain JVM (packages/sdk/android-tests). The Android half —
|
|
6
|
+
* the content-provider query — is [MetaInstallReferrerReader].
|
|
7
|
+
*
|
|
8
|
+
* Source: https://developers.facebook.com/docs/app-ads/meta-install-referrer
|
|
9
|
+
* · providers `content://<authority>/<FB_APP_ID>`, checked in this order:
|
|
10
|
+
* Facebook, Instagram, Facebook Lite;
|
|
11
|
+
* · projection `install_referrer`, `is_ct` (« 0 = VT, 1 = CT »), `actual_timestamp`
|
|
12
|
+
* (« timestamp in seconds for click/impression »);
|
|
13
|
+
* · minimum app versions: Facebook v428, Instagram v296, Facebook Lite v411 — an
|
|
14
|
+
* older app simply has no provider, and the read answers nothing.
|
|
15
|
+
*/
|
|
16
|
+
data class MetaInstallReferrer(
|
|
17
|
+
/** "facebook" | "instagram" | "facebook_lite" — the wire name the API expects. */
|
|
18
|
+
val provider: String,
|
|
19
|
+
val installReferrer: String,
|
|
20
|
+
val isCt: Int,
|
|
21
|
+
val actualTimestamp: Long?,
|
|
22
|
+
) {
|
|
23
|
+
fun toMap(): Map<String, Any?> = buildMap {
|
|
24
|
+
put("provider", provider)
|
|
25
|
+
put("installReferrer", installReferrer)
|
|
26
|
+
put("isCt", isCt)
|
|
27
|
+
if (actualTimestamp != null) put("actualTimestamp", actualTimestamp)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
object MetaInstallReferrerRules {
|
|
32
|
+
/** (authority, wire name), in the order Meta's sample checks them. */
|
|
33
|
+
val PROVIDERS: List<Pair<String, String>> = listOf(
|
|
34
|
+
"com.facebook.katana.provider.InstallReferrerProvider" to "facebook",
|
|
35
|
+
"com.instagram.contentprovider.InstallReferrerProvider" to "instagram",
|
|
36
|
+
"com.facebook.lite.provider.InstallReferrerProvider" to "facebook_lite",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
val PROJECTION: Array<String> = arrayOf("install_referrer", "is_ct", "actual_timestamp")
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The Facebook App ID to query with: the host's explicit `metaAppId` first, then
|
|
43
|
+
* the manifest's `com.facebook.sdk.ApplicationId` (the Facebook SDK's own
|
|
44
|
+
* meta-data, sometimes written `fb<id>`). Null unless it is all digits — a
|
|
45
|
+
* malformed id would only ever query a URI no provider answers.
|
|
46
|
+
*/
|
|
47
|
+
fun appId(explicit: String?, manifest: String?): String? {
|
|
48
|
+
for (raw in listOf(explicit, manifest)) {
|
|
49
|
+
val v = raw?.trim()?.removePrefix("fb") ?: continue
|
|
50
|
+
if (v.isNotEmpty() && v.all { it in '0'..'9' }) return v
|
|
51
|
+
}
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** One cursor row → an entry, or null when it carries no referrer or a bad `is_ct`. */
|
|
56
|
+
fun entry(provider: String, installReferrer: String?, isCt: Int?, actualTimestamp: Long?): MetaInstallReferrer? {
|
|
57
|
+
val referrer = installReferrer?.trim()
|
|
58
|
+
if (referrer.isNullOrEmpty() || (isCt != 0 && isCt != 1)) return null
|
|
59
|
+
return MetaInstallReferrer(provider, referrer, isCt, actualTimestamp?.takeIf { it > 0 })
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
package io.khufu.traqio.expo
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.pm.PackageManager
|
|
5
|
+
import android.net.Uri
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Reads Meta's own Install Referrer — the content providers of the Facebook,
|
|
9
|
+
* Instagram and Facebook Lite apps — exactly as
|
|
10
|
+
* https://developers.facebook.com/docs/app-ads/meta-install-referrer does it:
|
|
11
|
+
* `resolveContentProvider(authority, 0)`, then
|
|
12
|
+
* `query(content://<authority>/<FB_APP_ID>, [install_referrer, is_ct, actual_timestamp], null, null, null)`,
|
|
13
|
+
* first row. Every provider that answers is kept (the API picks: a click beats a
|
|
14
|
+
* view, the latest wins). Blocking I/O: call it off the main thread. Never throws.
|
|
15
|
+
*
|
|
16
|
+
* Package visibility (Android 11+): the library manifest declares `<queries>` for
|
|
17
|
+
* com.facebook.katana, com.instagram.android and com.facebook.lite, as the page
|
|
18
|
+
* requires; it is merged into the host app.
|
|
19
|
+
*/
|
|
20
|
+
internal object MetaInstallReferrerReader {
|
|
21
|
+
fun read(context: Context, explicitAppId: String?): List<MetaInstallReferrer> {
|
|
22
|
+
val appId = MetaInstallReferrerRules.appId(explicitAppId, manifestAppId(context)) ?: return emptyList()
|
|
23
|
+
val out = mutableListOf<MetaInstallReferrer>()
|
|
24
|
+
for ((authority, provider) in MetaInstallReferrerRules.PROVIDERS) {
|
|
25
|
+
try {
|
|
26
|
+
if (context.packageManager.resolveContentProvider(authority, 0) == null) continue
|
|
27
|
+
val uri = Uri.parse("content://$authority/$appId")
|
|
28
|
+
context.contentResolver.query(uri, MetaInstallReferrerRules.PROJECTION, null, null, null)?.use { c ->
|
|
29
|
+
if (!c.moveToFirst()) return@use
|
|
30
|
+
val ref = c.getColumnIndex("install_referrer").takeIf { it >= 0 }?.let { c.getString(it) }
|
|
31
|
+
val isCt = c.getColumnIndex("is_ct").takeIf { it >= 0 }?.let { c.getInt(it) }
|
|
32
|
+
val ts = c.getColumnIndex("actual_timestamp").takeIf { it >= 0 }?.let { c.getLong(it) }
|
|
33
|
+
MetaInstallReferrerRules.entry(provider, ref, isCt, ts)?.let(out::add)
|
|
34
|
+
}
|
|
35
|
+
} catch (_: Exception) {
|
|
36
|
+
// A provider that refuses, an app mid-update: that provider answers nothing.
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return out
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private fun manifestAppId(context: Context): String? = try {
|
|
43
|
+
@Suppress("DEPRECATION")
|
|
44
|
+
val info = context.packageManager.getApplicationInfo(context.packageName, PackageManager.GET_META_DATA)
|
|
45
|
+
// The Facebook SDK writes it as a string resource; a bare number arrives as an Int.
|
|
46
|
+
info.metaData?.get("com.facebook.sdk.ApplicationId")?.toString()
|
|
47
|
+
} catch (_: Exception) {
|
|
48
|
+
null
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -8,7 +8,7 @@ import expo.modules.kotlin.modules.Module
|
|
|
8
8
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
9
9
|
|
|
10
10
|
// Expo native module bridging the JS SDK to Android. Exposes the Play Install
|
|
11
|
-
// Referrer to `getNativeBridge()` in src/native.ts. SKAN and Apple Ads attribution
|
|
11
|
+
// Referrer and Meta's Install Referrer to `getNativeBridge()` in src/native.ts. SKAN and Apple Ads attribution
|
|
12
12
|
// are iOS-only (no-ops here).
|
|
13
13
|
class TraqioModule : Module() {
|
|
14
14
|
override fun definition() = ModuleDefinition {
|
|
@@ -29,6 +29,20 @@ class TraqioModule : Module() {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
// Meta's own Install Referrer (Facebook / Instagram / Facebook Lite content
|
|
33
|
+
// providers, todo cmwy39da): a list of { provider, installReferrer, isCt,
|
|
34
|
+
// actualTimestamp? }, empty when no Meta app answers. Provider queries are I/O,
|
|
35
|
+
// so they run off the calling thread. Never rejects.
|
|
36
|
+
// https://developers.facebook.com/docs/app-ads/meta-install-referrer
|
|
37
|
+
AsyncFunction("getMetaInstallReferrers") { metaAppId: String?, promise: Promise ->
|
|
38
|
+
val context = appContext.reactContext?.applicationContext
|
|
39
|
+
if (context == null) {
|
|
40
|
+
promise.resolve(emptyList<Map<String, Any?>>())
|
|
41
|
+
} else {
|
|
42
|
+
Thread { promise.resolve(MetaInstallReferrerReader.read(context, metaAppId).map { it.toMap() }) }.start()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
32
46
|
// Basic, non-fingerprinting device context.
|
|
33
47
|
Function("getContext") {
|
|
34
48
|
mapOf(
|
package/build/native.d.ts
CHANGED
|
@@ -5,7 +5,30 @@ import type { CoarseValue, InstallReferrerResult, NativeBridge } from "@traqio/c
|
|
|
5
5
|
* `null` answer) must degrade instead of throwing.
|
|
6
6
|
*/
|
|
7
7
|
export declare function normalizeInstallReferrer(raw: unknown): InstallReferrerResult;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* One answer of Meta's own Install Referrer, as `@traqio/core` sends it
|
|
10
|
+
* (`MetaInstallReferrer` there, todo cmwy39da). Declared here as well, with its
|
|
11
|
+
* screening, so this bridge never depends on a newer core than the one installed
|
|
12
|
+
* next to it. https://developers.facebook.com/docs/app-ads/meta-install-referrer
|
|
13
|
+
*/
|
|
14
|
+
export interface MetaInstallReferrerEntry {
|
|
15
|
+
provider: "facebook" | "instagram" | "facebook_lite";
|
|
16
|
+
installReferrer: string;
|
|
17
|
+
isCt: 0 | 1;
|
|
18
|
+
actualTimestamp?: number;
|
|
19
|
+
}
|
|
20
|
+
/** The native list → its well-formed entries; anything else is dropped one by one. */
|
|
21
|
+
export declare function normalizeMetaInstallReferrers(raw: unknown): MetaInstallReferrerEntry[];
|
|
22
|
+
/** The bridge this module builds: `NativeBridge` plus the Meta Install Referrer read. */
|
|
23
|
+
export type ExpoNativeBridge = NativeBridge & {
|
|
24
|
+
getMetaInstallReferrers(metaAppId?: string): Promise<MetaInstallReferrerEntry[]>;
|
|
25
|
+
};
|
|
26
|
+
export declare function getNativeBridge(): ExpoNativeBridge | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The bridge over a resolved native module. Apart from `getNativeBridge()` so the
|
|
29
|
+
* degradation rules can be tested against a fake module, off-device.
|
|
30
|
+
*/
|
|
31
|
+
export declare function bridgeFor(m: any): ExpoNativeBridge;
|
|
9
32
|
/**
|
|
10
33
|
* Set the iOS SKAN conversion value directly, for apps that own their own
|
|
11
34
|
* schema instead of using the mapping published in the dashboard. Most apps
|
package/build/native.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,qBAAqB,EAErB,YAAY,EAEb,MAAM,cAAc,CAAC;AAUtB;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,GAAG,qBAAqB,CAe5E;
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,qBAAqB,EAErB,YAAY,EAEb,MAAM,cAAc,CAAC;AAUtB;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,GAAG,qBAAqB,CAe5E;AAED;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,UAAU,GAAG,WAAW,GAAG,eAAe,CAAC;IACrD,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;IACZ,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,sFAAsF;AACtF,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,OAAO,GAAG,wBAAwB,EAAE,CAatF;AAED,yFAAyF;AACzF,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG;IAC5C,uBAAuB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;CAClF,CAAC;AAQF,wBAAgB,eAAe,IAAI,gBAAgB,GAAG,SAAS,CAQ9D;AAED;;;GAGG;AAEH,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,GAAG,gBAAgB,CAmFlD;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,WAAW,EACpB,UAAU,UAAQ,GACjB,IAAI,CAQN"}
|
package/build/native.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeInstallReferrer = normalizeInstallReferrer;
|
|
4
|
+
exports.normalizeMetaInstallReferrers = normalizeMetaInstallReferrers;
|
|
4
5
|
exports.getNativeBridge = getNativeBridge;
|
|
6
|
+
exports.bridgeFor = bridgeFor;
|
|
5
7
|
exports.updateSkanConversionValue = updateSkanConversionValue;
|
|
6
8
|
function finiteNumber(value) {
|
|
7
9
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined;
|
|
@@ -27,6 +29,26 @@ function normalizeInstallReferrer(raw) {
|
|
|
27
29
|
googlePlayInstant: typeof r.googlePlayInstant === "boolean" ? r.googlePlayInstant : undefined,
|
|
28
30
|
};
|
|
29
31
|
}
|
|
32
|
+
/** The native list → its well-formed entries; anything else is dropped one by one. */
|
|
33
|
+
function normalizeMetaInstallReferrers(raw) {
|
|
34
|
+
if (!Array.isArray(raw))
|
|
35
|
+
return [];
|
|
36
|
+
const out = [];
|
|
37
|
+
for (const item of raw) {
|
|
38
|
+
const r = item;
|
|
39
|
+
if (!r || typeof r !== "object")
|
|
40
|
+
continue;
|
|
41
|
+
if (r.provider !== "facebook" && r.provider !== "instagram" && r.provider !== "facebook_lite")
|
|
42
|
+
continue;
|
|
43
|
+
if (typeof r.installReferrer !== "string" || !r.installReferrer.trim())
|
|
44
|
+
continue;
|
|
45
|
+
if (r.isCt !== 0 && r.isCt !== 1)
|
|
46
|
+
continue;
|
|
47
|
+
const ts = finiteNumber(r.actualTimestamp);
|
|
48
|
+
out.push({ provider: r.provider, installReferrer: r.installReferrer, isCt: r.isCt, ...(ts !== undefined ? { actualTimestamp: ts } : {}) });
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
30
52
|
// Wires the Expo native module → the JS SDK's NativeBridge. On Android it reads
|
|
31
53
|
// the Play Install Referrer (InstallReferrerReader.kt); on iOS it drives SKAN
|
|
32
54
|
// (TraqioSkan.swift). Pass the result to Traqio.init({ native: getNativeBridge() }).
|
|
@@ -37,87 +59,107 @@ function getNativeBridge() {
|
|
|
37
59
|
try {
|
|
38
60
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
39
61
|
const { requireNativeModule } = require("expo-modules-core");
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
platform: m.platform, // "android" | "ios"
|
|
43
|
-
// The native side answers with a status instead of throwing, but a bridge
|
|
44
|
-
// teardown mid-call still can — a rejected install read must not take
|
|
45
|
-
// `Traqio.init()` down with it.
|
|
46
|
-
getInstallReferrer: async () => {
|
|
47
|
-
try {
|
|
48
|
-
return normalizeInstallReferrer(await m.getInstallReferrer?.());
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
return { status: "error", retryable: true };
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
getContext: async () => {
|
|
55
|
-
try {
|
|
56
|
-
return (await m.getContext?.()) ?? {};
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
return {};
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
// iOS drives SKAdNetwork through this; the Android module implements it as
|
|
63
|
-
// a no-op so the JS core never has to branch on platform.
|
|
64
|
-
updateConversionValue: (fine, coarse, lockWindow) => m.updateConversionValue?.(fine, coarse, lockWindow ?? false),
|
|
65
|
-
// Apple Ads attribution token (iOS 14.3+). Resolves null rather than throwing
|
|
66
|
-
// on a native build that predates the method, or a device the framework has
|
|
67
|
-
// nothing for — which is most devices, since most installs are not Search Ads.
|
|
68
|
-
getAttributionToken: async () => {
|
|
69
|
-
try {
|
|
70
|
-
const token = await m.getAttributionToken?.();
|
|
71
|
-
return typeof token === "string" && token.trim() ? token : null;
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
// IDFA / GAID — only ever called when the host passed
|
|
78
|
-
// `collectAdvertisingId: true` (decision cmvjohk6). Never prompts; null on a
|
|
79
|
-
// native build that predates the method, without ATT, or without AD_ID.
|
|
80
|
-
getAdvertisingId: async () => {
|
|
81
|
-
try {
|
|
82
|
-
const id = await m.getAdvertisingId?.();
|
|
83
|
-
return typeof id === "string" && id.trim() ? id : null;
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
// iOS: the ATT status the app already obtained — read, never requested
|
|
90
|
-
// (decision cmvjohk6). Null on Android, on a native build that predates the
|
|
91
|
-
// method, or when the app does not link AppTrackingTransparency.
|
|
92
|
-
getTrackingAuthorization: async () => {
|
|
93
|
-
try {
|
|
94
|
-
const status = await m.getTrackingAuthorization?.();
|
|
95
|
-
return status === "not_determined" || status === "restricted" || status === "denied" || status === "authorized"
|
|
96
|
-
? status
|
|
97
|
-
: null;
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
// Debug mode (InitOptions.debug): the host app is debuggable / DEBUG, or runs
|
|
104
|
-
// on an emulator / simulator. `__DEV__` already covers a Metro dev bundle; this
|
|
105
|
-
// catches a release bundle in a debug native build or on a simulator. False on
|
|
106
|
-
// a native build that predates the method — production, as before the flag.
|
|
107
|
-
isDebugBuild: async () => {
|
|
108
|
-
try {
|
|
109
|
-
return (await m.isDebugBuild?.()) === true;
|
|
110
|
-
}
|
|
111
|
-
catch {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
};
|
|
62
|
+
return bridgeFor(requireNativeModule("Traqio"));
|
|
116
63
|
}
|
|
117
64
|
catch {
|
|
118
65
|
return undefined; // native module not present (e.g. tests / web)
|
|
119
66
|
}
|
|
120
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* The bridge over a resolved native module. Apart from `getNativeBridge()` so the
|
|
70
|
+
* degradation rules can be tested against a fake module, off-device.
|
|
71
|
+
*/
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
+
function bridgeFor(m) {
|
|
74
|
+
return {
|
|
75
|
+
platform: m.platform, // "android" | "ios"
|
|
76
|
+
// The native side answers with a status instead of throwing, but a bridge
|
|
77
|
+
// teardown mid-call still can — a rejected install read must not take
|
|
78
|
+
// `Traqio.init()` down with it.
|
|
79
|
+
getInstallReferrer: async () => {
|
|
80
|
+
try {
|
|
81
|
+
return normalizeInstallReferrer(await m.getInstallReferrer?.());
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return { status: "error", retryable: true };
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
getContext: async () => {
|
|
88
|
+
try {
|
|
89
|
+
return (await m.getContext?.()) ?? {};
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return {};
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
// iOS drives SKAdNetwork through this; the Android module implements it as
|
|
96
|
+
// a no-op so the JS core never has to branch on platform.
|
|
97
|
+
updateConversionValue: (fine, coarse, lockWindow) => m.updateConversionValue?.(fine, coarse, lockWindow ?? false),
|
|
98
|
+
// Apple Ads attribution token (iOS 14.3+). Resolves null rather than throwing
|
|
99
|
+
// on a native build that predates the method, or a device the framework has
|
|
100
|
+
// nothing for — which is most devices, since most installs are not Search Ads.
|
|
101
|
+
getAttributionToken: async () => {
|
|
102
|
+
try {
|
|
103
|
+
const token = await m.getAttributionToken?.();
|
|
104
|
+
return typeof token === "string" && token.trim() ? token : null;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
// Meta's own Install Referrer (Android, todo cmwy39da): what the Facebook /
|
|
111
|
+
// Instagram / Facebook Lite apps' content providers answer. Screened here, so
|
|
112
|
+
// a malformed native entry costs that entry; [] on iOS, on a native build that
|
|
113
|
+
// predates the method, or on a bridge teardown.
|
|
114
|
+
// https://developers.facebook.com/docs/app-ads/meta-install-referrer
|
|
115
|
+
getMetaInstallReferrers: async (metaAppId) => {
|
|
116
|
+
try {
|
|
117
|
+
return normalizeMetaInstallReferrers(await m.getMetaInstallReferrers?.(metaAppId ?? null));
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
// IDFA / GAID — only ever called when the host passed
|
|
124
|
+
// `collectAdvertisingId: true` (decision cmvjohk6). Never prompts; null on a
|
|
125
|
+
// native build that predates the method, without ATT, or without AD_ID.
|
|
126
|
+
getAdvertisingId: async () => {
|
|
127
|
+
try {
|
|
128
|
+
const id = await m.getAdvertisingId?.();
|
|
129
|
+
return typeof id === "string" && id.trim() ? id : null;
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
// iOS: the ATT status the app already obtained — read, never requested
|
|
136
|
+
// (decision cmvjohk6). Null on Android, on a native build that predates the
|
|
137
|
+
// method, or when the app does not link AppTrackingTransparency.
|
|
138
|
+
getTrackingAuthorization: async () => {
|
|
139
|
+
try {
|
|
140
|
+
const status = await m.getTrackingAuthorization?.();
|
|
141
|
+
return status === "not_determined" || status === "restricted" || status === "denied" || status === "authorized"
|
|
142
|
+
? status
|
|
143
|
+
: null;
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
// Debug mode (InitOptions.debug): the host app is debuggable / DEBUG, or runs
|
|
150
|
+
// on an emulator / simulator. `__DEV__` already covers a Metro dev bundle; this
|
|
151
|
+
// catches a release bundle in a debug native build or on a simulator. False on
|
|
152
|
+
// a native build that predates the method — production, as before the flag.
|
|
153
|
+
isDebugBuild: async () => {
|
|
154
|
+
try {
|
|
155
|
+
return (await m.isDebugBuild?.()) === true;
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
121
163
|
/**
|
|
122
164
|
* Set the iOS SKAN conversion value directly, for apps that own their own
|
|
123
165
|
* schema instead of using the mapping published in the dashboard. Most apps
|
package/build/native.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":";;AAqBA,4DAeC;
|
|
1
|
+
{"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":";;AAqBA,4DAeC;AAgBD,sEAaC;AAaD,0CAQC;AAOD,8BAmFC;AAYD,8DAYC;AA5LD,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAA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,yBAAyB,CACvC,SAAiB,EACjB,MAAoB,EACpB,UAAU,GAAG,KAAK;IAElB,IAAI,CAAC;QACH,8DAA8D;QAC9D,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAC7D,mBAAmB,CAAC,QAAQ,CAAC,CAAC,qBAAqB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IACvF,CAAC;IAAC,MAAM,CAAC;QACP,sBAAsB;IACxB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@traqio/react-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Traqio SDK for React Native / Expo — deterministic install attribution (Play Install Referrer) + SKAN. No IDFA, no fingerprinting.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"README.md"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@traqio/core": "0.
|
|
47
|
+
"@traqio/core": "0.11.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@react-native-async-storage/async-storage": ">=1.21.0",
|
package/src/native.ts
CHANGED
|
@@ -36,92 +36,146 @@ export function normalizeInstallReferrer(raw: unknown): InstallReferrerResult {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* One answer of Meta's own Install Referrer, as `@traqio/core` sends it
|
|
41
|
+
* (`MetaInstallReferrer` there, todo cmwy39da). Declared here as well, with its
|
|
42
|
+
* screening, so this bridge never depends on a newer core than the one installed
|
|
43
|
+
* next to it. https://developers.facebook.com/docs/app-ads/meta-install-referrer
|
|
44
|
+
*/
|
|
45
|
+
export interface MetaInstallReferrerEntry {
|
|
46
|
+
provider: "facebook" | "instagram" | "facebook_lite";
|
|
47
|
+
installReferrer: string;
|
|
48
|
+
isCt: 0 | 1;
|
|
49
|
+
actualTimestamp?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The native list → its well-formed entries; anything else is dropped one by one. */
|
|
53
|
+
export function normalizeMetaInstallReferrers(raw: unknown): MetaInstallReferrerEntry[] {
|
|
54
|
+
if (!Array.isArray(raw)) return [];
|
|
55
|
+
const out: MetaInstallReferrerEntry[] = [];
|
|
56
|
+
for (const item of raw) {
|
|
57
|
+
const r = item as Record<string, unknown> | null;
|
|
58
|
+
if (!r || typeof r !== "object") continue;
|
|
59
|
+
if (r.provider !== "facebook" && r.provider !== "instagram" && r.provider !== "facebook_lite") continue;
|
|
60
|
+
if (typeof r.installReferrer !== "string" || !r.installReferrer.trim()) continue;
|
|
61
|
+
if (r.isCt !== 0 && r.isCt !== 1) continue;
|
|
62
|
+
const ts = finiteNumber(r.actualTimestamp);
|
|
63
|
+
out.push({ provider: r.provider, installReferrer: r.installReferrer, isCt: r.isCt, ...(ts !== undefined ? { actualTimestamp: ts } : {}) });
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The bridge this module builds: `NativeBridge` plus the Meta Install Referrer read. */
|
|
69
|
+
export type ExpoNativeBridge = NativeBridge & {
|
|
70
|
+
getMetaInstallReferrers(metaAppId?: string): Promise<MetaInstallReferrerEntry[]>;
|
|
71
|
+
};
|
|
72
|
+
|
|
39
73
|
// Wires the Expo native module → the JS SDK's NativeBridge. On Android it reads
|
|
40
74
|
// the Play Install Referrer (InstallReferrerReader.kt); on iOS it drives SKAN
|
|
41
75
|
// (TraqioSkan.swift). Pass the result to Traqio.init({ native: getNativeBridge() }).
|
|
42
76
|
//
|
|
43
77
|
// Requires the app to have the native module installed (dev build / EAS, not Expo Go).
|
|
44
78
|
// We import lazily so the SDK also works in pure-JS test contexts.
|
|
45
|
-
export function getNativeBridge():
|
|
79
|
+
export function getNativeBridge(): ExpoNativeBridge | undefined {
|
|
46
80
|
try {
|
|
47
81
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
48
82
|
const { requireNativeModule } = require("expo-modules-core");
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
platform: m.platform, // "android" | "ios"
|
|
52
|
-
// The native side answers with a status instead of throwing, but a bridge
|
|
53
|
-
// teardown mid-call still can — a rejected install read must not take
|
|
54
|
-
// `Traqio.init()` down with it.
|
|
55
|
-
getInstallReferrer: async () => {
|
|
56
|
-
try {
|
|
57
|
-
return normalizeInstallReferrer(await m.getInstallReferrer?.());
|
|
58
|
-
} catch {
|
|
59
|
-
return { status: "error", retryable: true };
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
getContext: async () => {
|
|
63
|
-
try {
|
|
64
|
-
return (await m.getContext?.()) ?? {};
|
|
65
|
-
} catch {
|
|
66
|
-
return {};
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
// iOS drives SKAdNetwork through this; the Android module implements it as
|
|
70
|
-
// a no-op so the JS core never has to branch on platform.
|
|
71
|
-
updateConversionValue: (fine, coarse, lockWindow) =>
|
|
72
|
-
m.updateConversionValue?.(fine, coarse, lockWindow ?? false),
|
|
73
|
-
// Apple Ads attribution token (iOS 14.3+). Resolves null rather than throwing
|
|
74
|
-
// on a native build that predates the method, or a device the framework has
|
|
75
|
-
// nothing for — which is most devices, since most installs are not Search Ads.
|
|
76
|
-
getAttributionToken: async () => {
|
|
77
|
-
try {
|
|
78
|
-
const token = await m.getAttributionToken?.();
|
|
79
|
-
return typeof token === "string" && token.trim() ? token : null;
|
|
80
|
-
} catch {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
// IDFA / GAID — only ever called when the host passed
|
|
85
|
-
// `collectAdvertisingId: true` (decision cmvjohk6). Never prompts; null on a
|
|
86
|
-
// native build that predates the method, without ATT, or without AD_ID.
|
|
87
|
-
getAdvertisingId: async () => {
|
|
88
|
-
try {
|
|
89
|
-
const id = await m.getAdvertisingId?.();
|
|
90
|
-
return typeof id === "string" && id.trim() ? id : null;
|
|
91
|
-
} catch {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
// iOS: the ATT status the app already obtained — read, never requested
|
|
96
|
-
// (decision cmvjohk6). Null on Android, on a native build that predates the
|
|
97
|
-
// method, or when the app does not link AppTrackingTransparency.
|
|
98
|
-
getTrackingAuthorization: async () => {
|
|
99
|
-
try {
|
|
100
|
-
const status: unknown = await m.getTrackingAuthorization?.();
|
|
101
|
-
return status === "not_determined" || status === "restricted" || status === "denied" || status === "authorized"
|
|
102
|
-
? (status as TrackingAuthorization)
|
|
103
|
-
: null;
|
|
104
|
-
} catch {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
// Debug mode (InitOptions.debug): the host app is debuggable / DEBUG, or runs
|
|
109
|
-
// on an emulator / simulator. `__DEV__` already covers a Metro dev bundle; this
|
|
110
|
-
// catches a release bundle in a debug native build or on a simulator. False on
|
|
111
|
-
// a native build that predates the method — production, as before the flag.
|
|
112
|
-
isDebugBuild: async () => {
|
|
113
|
-
try {
|
|
114
|
-
return (await m.isDebugBuild?.()) === true;
|
|
115
|
-
} catch {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
};
|
|
83
|
+
return bridgeFor(requireNativeModule("Traqio"));
|
|
120
84
|
} catch {
|
|
121
85
|
return undefined; // native module not present (e.g. tests / web)
|
|
122
86
|
}
|
|
123
87
|
}
|
|
124
88
|
|
|
89
|
+
/**
|
|
90
|
+
* The bridge over a resolved native module. Apart from `getNativeBridge()` so the
|
|
91
|
+
* degradation rules can be tested against a fake module, off-device.
|
|
92
|
+
*/
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
+
export function bridgeFor(m: any): ExpoNativeBridge {
|
|
95
|
+
return {
|
|
96
|
+
platform: m.platform, // "android" | "ios"
|
|
97
|
+
// The native side answers with a status instead of throwing, but a bridge
|
|
98
|
+
// teardown mid-call still can — a rejected install read must not take
|
|
99
|
+
// `Traqio.init()` down with it.
|
|
100
|
+
getInstallReferrer: async () => {
|
|
101
|
+
try {
|
|
102
|
+
return normalizeInstallReferrer(await m.getInstallReferrer?.());
|
|
103
|
+
} catch {
|
|
104
|
+
return { status: "error", retryable: true };
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
getContext: async () => {
|
|
108
|
+
try {
|
|
109
|
+
return (await m.getContext?.()) ?? {};
|
|
110
|
+
} catch {
|
|
111
|
+
return {};
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
// iOS drives SKAdNetwork through this; the Android module implements it as
|
|
115
|
+
// a no-op so the JS core never has to branch on platform.
|
|
116
|
+
updateConversionValue: (fine, coarse, lockWindow) =>
|
|
117
|
+
m.updateConversionValue?.(fine, coarse, lockWindow ?? false),
|
|
118
|
+
// Apple Ads attribution token (iOS 14.3+). Resolves null rather than throwing
|
|
119
|
+
// on a native build that predates the method, or a device the framework has
|
|
120
|
+
// nothing for — which is most devices, since most installs are not Search Ads.
|
|
121
|
+
getAttributionToken: async () => {
|
|
122
|
+
try {
|
|
123
|
+
const token = await m.getAttributionToken?.();
|
|
124
|
+
return typeof token === "string" && token.trim() ? token : null;
|
|
125
|
+
} catch {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
// Meta's own Install Referrer (Android, todo cmwy39da): what the Facebook /
|
|
130
|
+
// Instagram / Facebook Lite apps' content providers answer. Screened here, so
|
|
131
|
+
// a malformed native entry costs that entry; [] on iOS, on a native build that
|
|
132
|
+
// predates the method, or on a bridge teardown.
|
|
133
|
+
// https://developers.facebook.com/docs/app-ads/meta-install-referrer
|
|
134
|
+
getMetaInstallReferrers: async (metaAppId?: string): Promise<MetaInstallReferrerEntry[]> => {
|
|
135
|
+
try {
|
|
136
|
+
return normalizeMetaInstallReferrers(await m.getMetaInstallReferrers?.(metaAppId ?? null));
|
|
137
|
+
} catch {
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
// IDFA / GAID — only ever called when the host passed
|
|
142
|
+
// `collectAdvertisingId: true` (decision cmvjohk6). Never prompts; null on a
|
|
143
|
+
// native build that predates the method, without ATT, or without AD_ID.
|
|
144
|
+
getAdvertisingId: async () => {
|
|
145
|
+
try {
|
|
146
|
+
const id = await m.getAdvertisingId?.();
|
|
147
|
+
return typeof id === "string" && id.trim() ? id : null;
|
|
148
|
+
} catch {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
// iOS: the ATT status the app already obtained — read, never requested
|
|
153
|
+
// (decision cmvjohk6). Null on Android, on a native build that predates the
|
|
154
|
+
// method, or when the app does not link AppTrackingTransparency.
|
|
155
|
+
getTrackingAuthorization: async () => {
|
|
156
|
+
try {
|
|
157
|
+
const status: unknown = await m.getTrackingAuthorization?.();
|
|
158
|
+
return status === "not_determined" || status === "restricted" || status === "denied" || status === "authorized"
|
|
159
|
+
? (status as TrackingAuthorization)
|
|
160
|
+
: null;
|
|
161
|
+
} catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
// Debug mode (InitOptions.debug): the host app is debuggable / DEBUG, or runs
|
|
166
|
+
// on an emulator / simulator. `__DEV__` already covers a Metro dev bundle; this
|
|
167
|
+
// catches a release bundle in a debug native build or on a simulator. False on
|
|
168
|
+
// a native build that predates the method — production, as before the flag.
|
|
169
|
+
isDebugBuild: async () => {
|
|
170
|
+
try {
|
|
171
|
+
return (await m.isDebugBuild?.()) === true;
|
|
172
|
+
} catch {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
125
179
|
/**
|
|
126
180
|
* Set the iOS SKAN conversion value directly, for apps that own their own
|
|
127
181
|
* schema instead of using the mapping published in the dashboard. Most apps
|