@kissmyappss/react-native 0.0.0-stage → 1.1.0
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/CHANGELOG.md +43 -0
- package/KissMyAppsReactNative.podspec +29 -0
- package/LICENSE +21 -0
- package/README.md +335 -2
- package/android/build.gradle +65 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/AndroidManifestNew.xml +1 -0
- package/android/src/main/java/com/kissmyapps/reactnative/KissMyAppsAttributionModule.kt +138 -0
- package/android/src/main/java/com/kissmyapps/reactnative/KissMyAppsAttributionPackage.kt +15 -0
- package/ios/KissMyAppsAttribution.m +10 -0
- package/ios/KissMyAppsAttribution.swift +75 -0
- package/ios/PrivacyInfo.xcprivacy +40 -0
- package/lib/attribution.d.ts +78 -0
- package/lib/attribution.js +153 -0
- package/lib/client.d.ts +207 -0
- package/lib/client.js +940 -0
- package/lib/device.d.ts +2 -0
- package/lib/device.js +59 -0
- package/lib/index.d.ts +57 -0
- package/lib/index.js +154 -0
- package/lib/navigation.d.ts +10 -0
- package/lib/navigation.js +18 -0
- package/package.json +43 -4
- package/react-native.config.js +13 -0
- package/src/attribution.ts +207 -0
- package/src/client.ts +1087 -0
- package/src/device.ts +59 -0
- package/src/index.ts +163 -0
- package/src/navigation.ts +18 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Registers the Swift module KissMyAppsAttribution with React Native.
|
|
2
|
+
#import <React/RCTBridgeModule.h>
|
|
3
|
+
|
|
4
|
+
@interface RCT_EXTERN_MODULE(KissMyAppsAttribution, NSObject)
|
|
5
|
+
|
|
6
|
+
RCT_EXTERN_METHOD(getAttributionInfo:(NSDictionary *)request
|
|
7
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
8
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
9
|
+
|
|
10
|
+
@end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import CommonCrypto
|
|
2
|
+
import Foundation
|
|
3
|
+
import UIKit
|
|
4
|
+
#if canImport(AdServices)
|
|
5
|
+
import AdServices
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
/// The optional native part of @kissmyappss/react-native on iOS: what the install call needs
|
|
9
|
+
/// that JavaScript cannot read. The SDK works without it, minus these fields.
|
|
10
|
+
///
|
|
11
|
+
/// - `deviceKey`: SHA-256 hex of identifierForVendor. The identifier itself never leaves the phone.
|
|
12
|
+
/// - `appleAdsToken`: AAAttribution.attributionToken(), iOS 14.3 and later, first launch only.
|
|
13
|
+
/// - `clipboardClick`: the click ID after `kma:` on the clipboard, only when the app turned
|
|
14
|
+
/// clipboard handoff on (iOS asks the person before an app reads another app's copy).
|
|
15
|
+
///
|
|
16
|
+
/// No advertising identifier, no tracking prompt.
|
|
17
|
+
@objc(KissMyAppsAttribution)
|
|
18
|
+
final class KissMyAppsAttribution: NSObject {
|
|
19
|
+
@objc static func requiresMainQueueSetup() -> Bool { false }
|
|
20
|
+
|
|
21
|
+
@objc(getAttributionInfo:resolver:rejecter:)
|
|
22
|
+
func getAttributionInfo(
|
|
23
|
+
_ request: NSDictionary,
|
|
24
|
+
resolver resolve: @escaping (Any?) -> Void,
|
|
25
|
+
rejecter _: @escaping (String?, String?, Error?) -> Void
|
|
26
|
+
) {
|
|
27
|
+
let install = request["install"] as? Bool ?? false
|
|
28
|
+
let clipboard = request["clipboard"] as? Bool ?? false
|
|
29
|
+
DispatchQueue.main.async {
|
|
30
|
+
var info: [String: Any] = [:]
|
|
31
|
+
if let vendor = UIDevice.current.identifierForVendor?.uuidString {
|
|
32
|
+
info["deviceKey"] = KissMyAppsAttribution.sha256Hex(vendor)
|
|
33
|
+
}
|
|
34
|
+
if install, clipboard, let click = KissMyAppsAttribution.clipboardClick() {
|
|
35
|
+
info["clipboardClick"] = click
|
|
36
|
+
}
|
|
37
|
+
let fromMain = info
|
|
38
|
+
// The token comes from a system service; keep it off the main thread.
|
|
39
|
+
DispatchQueue.global(qos: .utility).async {
|
|
40
|
+
var result = fromMain
|
|
41
|
+
if install, let ads = KissMyAppsAttribution.appleAdsToken() {
|
|
42
|
+
result["appleAdsToken"] = ads
|
|
43
|
+
}
|
|
44
|
+
resolve(result)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private static func clipboardClick() -> String? {
|
|
50
|
+
let board = UIPasteboard.general
|
|
51
|
+
guard board.hasStrings, let text = board.string else { return nil }
|
|
52
|
+
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
53
|
+
guard trimmed.hasPrefix("kma:") else { return nil }
|
|
54
|
+
return String(trimmed.dropFirst(4))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private static func appleAdsToken() -> String? {
|
|
58
|
+
#if canImport(AdServices)
|
|
59
|
+
if #available(iOS 14.3, *) {
|
|
60
|
+
// Fails on the simulator and when Apple's service is unavailable: nothing then.
|
|
61
|
+
return try? AAAttribution.attributionToken()
|
|
62
|
+
}
|
|
63
|
+
#endif
|
|
64
|
+
return nil
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static func sha256Hex(_ text: String) -> String {
|
|
68
|
+
let bytes = Array(text.utf8)
|
|
69
|
+
var digest = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
|
|
70
|
+
_ = bytes.withUnsafeBufferPointer { buffer in
|
|
71
|
+
CC_SHA256(buffer.baseAddress, CC_LONG(buffer.count), &digest)
|
|
72
|
+
}
|
|
73
|
+
return digest.map { String(format: "%02x", $0) }.joined()
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<!-- What the KissMyApps SDK collects, for the app's privacy report. No tracking. -->
|
|
4
|
+
<plist version="1.0">
|
|
5
|
+
<dict>
|
|
6
|
+
<key>NSPrivacyTracking</key>
|
|
7
|
+
<false/>
|
|
8
|
+
<key>NSPrivacyTrackingDomains</key>
|
|
9
|
+
<array/>
|
|
10
|
+
<key>NSPrivacyCollectedDataTypes</key>
|
|
11
|
+
<array>
|
|
12
|
+
<dict>
|
|
13
|
+
<key>NSPrivacyCollectedDataType</key>
|
|
14
|
+
<string>NSPrivacyCollectedDataTypeDeviceID</string>
|
|
15
|
+
<key>NSPrivacyCollectedDataTypeLinked</key>
|
|
16
|
+
<false/>
|
|
17
|
+
<key>NSPrivacyCollectedDataTypeTracking</key>
|
|
18
|
+
<false/>
|
|
19
|
+
<key>NSPrivacyCollectedDataTypePurposes</key>
|
|
20
|
+
<array>
|
|
21
|
+
<string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
|
|
22
|
+
</array>
|
|
23
|
+
</dict>
|
|
24
|
+
<dict>
|
|
25
|
+
<key>NSPrivacyCollectedDataType</key>
|
|
26
|
+
<string>NSPrivacyCollectedDataTypeProductInteraction</string>
|
|
27
|
+
<key>NSPrivacyCollectedDataTypeLinked</key>
|
|
28
|
+
<false/>
|
|
29
|
+
<key>NSPrivacyCollectedDataTypeTracking</key>
|
|
30
|
+
<false/>
|
|
31
|
+
<key>NSPrivacyCollectedDataTypePurposes</key>
|
|
32
|
+
<array>
|
|
33
|
+
<string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
|
|
34
|
+
</array>
|
|
35
|
+
</dict>
|
|
36
|
+
</array>
|
|
37
|
+
<key>NSPrivacyAccessedAPITypes</key>
|
|
38
|
+
<array/>
|
|
39
|
+
</dict>
|
|
40
|
+
</plist>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** A deep link from KissMyApps, handed to `onDeepLink` once. */
|
|
2
|
+
export interface DeepLink {
|
|
3
|
+
/** The link's deep link value, such as `lesson`, or null when it has only parameters. */
|
|
4
|
+
value: string | null;
|
|
5
|
+
/** The deep link's parameters, such as `{ id: '4' }`. */
|
|
6
|
+
params: Record<string, string>;
|
|
7
|
+
/** True when it came through an install (a deferred deep link), false when a link opened the app. */
|
|
8
|
+
deferred: boolean;
|
|
9
|
+
/** The link that opened the app, or null when the deep link came from the store install. */
|
|
10
|
+
url: string | null;
|
|
11
|
+
}
|
|
12
|
+
/** What the optional native module `KissMyAppsAttribution` reads on the device. */
|
|
13
|
+
export interface AttributionInfo {
|
|
14
|
+
/** Lowercase hex SHA-256 of identifierForVendor (iOS) or ANDROID_ID (Android). */
|
|
15
|
+
deviceKey?: string | null;
|
|
16
|
+
/** The Google Play install referrer (Android). */
|
|
17
|
+
referrer?: string | null;
|
|
18
|
+
/** Seconds since 1970, from the Install Referrer API (Android). */
|
|
19
|
+
referrerClickTs?: number | null;
|
|
20
|
+
/** Seconds since 1970, from the Install Referrer API (Android). */
|
|
21
|
+
installBeginTs?: number | null;
|
|
22
|
+
/** AAAttribution.attributionToken() (iOS 14.3+). */
|
|
23
|
+
appleAdsToken?: string | null;
|
|
24
|
+
/** The click ID after `kma:` on the clipboard, read only when clipboard handoff is on (iOS). */
|
|
25
|
+
clipboardClick?: string | null;
|
|
26
|
+
/** True when Google Play did not answer in time: the next try reads the referrer again. */
|
|
27
|
+
retryReferrer?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** What the SDK asks the native module for. */
|
|
30
|
+
export interface AttributionRequest {
|
|
31
|
+
/** The first launch: also the install referrer or Apple Ads token; otherwise the device key only. */
|
|
32
|
+
install: boolean;
|
|
33
|
+
/** Read a `kma:` click ID from the clipboard (iOS, clipboard handoff on). */
|
|
34
|
+
clipboard: boolean;
|
|
35
|
+
}
|
|
36
|
+
export declare const INSTALL_PATH = "/v1/attribution/install";
|
|
37
|
+
export declare const OPEN_PATH = "/v1/attribution/open";
|
|
38
|
+
/** The link as the SDK sends it: an https URL of at most 2,048 characters, or null. */
|
|
39
|
+
export declare function httpsLink(value: unknown): string | null;
|
|
40
|
+
/** The device key when it is one: 64 lowercase hex characters. */
|
|
41
|
+
export declare function deviceKey(value: unknown): string | null;
|
|
42
|
+
export interface InstallInput {
|
|
43
|
+
anonymousId: string;
|
|
44
|
+
sessionId: string;
|
|
45
|
+
platform: 'ios' | 'android';
|
|
46
|
+
/** When app_installed was queued, in milliseconds since 1970. */
|
|
47
|
+
installedAt: number;
|
|
48
|
+
sdk: string;
|
|
49
|
+
userId?: string | null;
|
|
50
|
+
appVersion?: string;
|
|
51
|
+
/** The link that opened the app on this launch, if any. */
|
|
52
|
+
link?: string | null;
|
|
53
|
+
info: AttributionInfo;
|
|
54
|
+
/** Whether the app turned clipboard handoff on. */
|
|
55
|
+
clipboard: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** The body of POST /v1/attribution/install. */
|
|
58
|
+
export declare function installBody(input: InstallInput): Record<string, unknown>;
|
|
59
|
+
export interface OpenInput {
|
|
60
|
+
anonymousId: string;
|
|
61
|
+
sessionId: string;
|
|
62
|
+
platform: 'ios' | 'android';
|
|
63
|
+
url: string;
|
|
64
|
+
/** When the link opened the app, in milliseconds since 1970. */
|
|
65
|
+
openedAt: number;
|
|
66
|
+
sdk: string;
|
|
67
|
+
userId?: string | null;
|
|
68
|
+
appVersion?: string;
|
|
69
|
+
deviceKey?: string | null;
|
|
70
|
+
}
|
|
71
|
+
/** The body of POST /v1/attribution/open. */
|
|
72
|
+
export declare function openBody(input: OpenInput): Record<string, unknown>;
|
|
73
|
+
/** The deep link in an answer from either call, or null when it has none. */
|
|
74
|
+
export declare function deepLinkFrom(answer: unknown, url: string | null): DeepLink | null;
|
|
75
|
+
/** The answer's JSON, or null when it is not JSON. */
|
|
76
|
+
export declare function parseAnswer(body: string): unknown;
|
|
77
|
+
/** Settles with the promise's value, or with `fallback` after `ms` or when it fails. */
|
|
78
|
+
export declare function within<T>(promise: Promise<T>, ms: number, fallback: T): Promise<T>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The two attribution calls every KissMyApps app SDK makes: one install call on the first
|
|
3
|
+
// launch, and one open call for each link that opens the app later. What goes in them, and
|
|
4
|
+
// what comes back, is the `attribution` section of
|
|
5
|
+
// integrations/analytics-mobile/contract/app-events.json.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.OPEN_PATH = exports.INSTALL_PATH = void 0;
|
|
8
|
+
exports.httpsLink = httpsLink;
|
|
9
|
+
exports.deviceKey = deviceKey;
|
|
10
|
+
exports.installBody = installBody;
|
|
11
|
+
exports.openBody = openBody;
|
|
12
|
+
exports.deepLinkFrom = deepLinkFrom;
|
|
13
|
+
exports.parseAnswer = parseAnswer;
|
|
14
|
+
exports.within = within;
|
|
15
|
+
exports.INSTALL_PATH = '/v1/attribution/install';
|
|
16
|
+
exports.OPEN_PATH = '/v1/attribution/open';
|
|
17
|
+
const MAX_URL = 2048;
|
|
18
|
+
const MAX_PARAMS = 10;
|
|
19
|
+
const MAX_REFERRER = 1024;
|
|
20
|
+
const MAX_APPLE_ADS = 4096;
|
|
21
|
+
const DEVICE_KEY = /^[0-9a-f]{64}$/;
|
|
22
|
+
const CLICK_ID = /^[A-Za-z0-9_-]{16,40}$/;
|
|
23
|
+
// React Native's URL class leaves most of its parts unimplemented, so links are read by hand.
|
|
24
|
+
const HTTPS_URL = /^https:\/\/[^\s/?#@]+(?:[/?#]\S*)?$/i;
|
|
25
|
+
/** The link as the SDK sends it: an https URL of at most 2,048 characters, or null. */
|
|
26
|
+
function httpsLink(value) {
|
|
27
|
+
if (typeof value !== 'string')
|
|
28
|
+
return null;
|
|
29
|
+
const link = value.trim();
|
|
30
|
+
return link.length <= MAX_URL && HTTPS_URL.test(link) ? link : null;
|
|
31
|
+
}
|
|
32
|
+
function text(value, max) {
|
|
33
|
+
return typeof value === 'string' && value.length > 0 && value.length <= max ? value : null;
|
|
34
|
+
}
|
|
35
|
+
function seconds(value) {
|
|
36
|
+
// Play answers 0 when it does not know.
|
|
37
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.floor(value) : null;
|
|
38
|
+
}
|
|
39
|
+
/** The device key when it is one: 64 lowercase hex characters. */
|
|
40
|
+
function deviceKey(value) {
|
|
41
|
+
return typeof value === 'string' && DEVICE_KEY.test(value) ? value : null;
|
|
42
|
+
}
|
|
43
|
+
/** The body of POST /v1/attribution/install. */
|
|
44
|
+
function installBody(input) {
|
|
45
|
+
const { info } = input;
|
|
46
|
+
const body = {
|
|
47
|
+
anonymous_id: input.anonymousId,
|
|
48
|
+
session_id: input.sessionId,
|
|
49
|
+
platform: input.platform,
|
|
50
|
+
installed_at: new Date(input.installedAt).toISOString(),
|
|
51
|
+
sdk: input.sdk,
|
|
52
|
+
};
|
|
53
|
+
if (input.userId)
|
|
54
|
+
body.user_id = input.userId;
|
|
55
|
+
if (input.appVersion)
|
|
56
|
+
body.app_version = input.appVersion;
|
|
57
|
+
const key = deviceKey(info.deviceKey);
|
|
58
|
+
if (key)
|
|
59
|
+
body.device_key = key;
|
|
60
|
+
const link = httpsLink(input.link);
|
|
61
|
+
if (link)
|
|
62
|
+
body.link_url = link;
|
|
63
|
+
if (input.platform === 'android') {
|
|
64
|
+
// A longer referrer is cut to the contract's 1,024 characters.
|
|
65
|
+
const referrer = typeof info.referrer === 'string' && info.referrer
|
|
66
|
+
? info.referrer.slice(0, MAX_REFERRER)
|
|
67
|
+
: null;
|
|
68
|
+
const clicked = seconds(info.referrerClickTs);
|
|
69
|
+
const began = seconds(info.installBeginTs);
|
|
70
|
+
if (referrer)
|
|
71
|
+
body.referrer = referrer;
|
|
72
|
+
if (clicked !== null)
|
|
73
|
+
body.referrer_click_ts = clicked;
|
|
74
|
+
if (began !== null)
|
|
75
|
+
body.install_begin_ts = began;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const appleAds = text(info.appleAdsToken, MAX_APPLE_ADS);
|
|
79
|
+
if (appleAds)
|
|
80
|
+
body.apple_ads_token = appleAds;
|
|
81
|
+
const click = typeof info.clipboardClick === 'string' ? info.clipboardClick.trim() : '';
|
|
82
|
+
if (input.clipboard && CLICK_ID.test(click))
|
|
83
|
+
body.clipboard_click = click;
|
|
84
|
+
}
|
|
85
|
+
return body;
|
|
86
|
+
}
|
|
87
|
+
/** The body of POST /v1/attribution/open. */
|
|
88
|
+
function openBody(input) {
|
|
89
|
+
const body = {
|
|
90
|
+
anonymous_id: input.anonymousId,
|
|
91
|
+
session_id: input.sessionId,
|
|
92
|
+
platform: input.platform,
|
|
93
|
+
url: input.url,
|
|
94
|
+
opened_at: new Date(input.openedAt).toISOString(),
|
|
95
|
+
sdk: input.sdk,
|
|
96
|
+
};
|
|
97
|
+
if (input.userId)
|
|
98
|
+
body.user_id = input.userId;
|
|
99
|
+
if (input.appVersion)
|
|
100
|
+
body.app_version = input.appVersion;
|
|
101
|
+
const key = deviceKey(input.deviceKey);
|
|
102
|
+
if (key)
|
|
103
|
+
body.device_key = key;
|
|
104
|
+
return body;
|
|
105
|
+
}
|
|
106
|
+
/** The deep link in an answer from either call, or null when it has none. */
|
|
107
|
+
function deepLinkFrom(answer, url) {
|
|
108
|
+
if (!answer || typeof answer !== 'object')
|
|
109
|
+
return null;
|
|
110
|
+
const link = answer.deep_link;
|
|
111
|
+
if (!link || typeof link !== 'object' || Array.isArray(link))
|
|
112
|
+
return null;
|
|
113
|
+
const { value, params, deferred } = link;
|
|
114
|
+
const clean = {};
|
|
115
|
+
if (params && typeof params === 'object' && !Array.isArray(params)) {
|
|
116
|
+
for (const [name, item] of Object.entries(params)) {
|
|
117
|
+
if (Object.keys(clean).length >= MAX_PARAMS)
|
|
118
|
+
break;
|
|
119
|
+
// Text as it is; numbers and true/false as text; anything else is left out.
|
|
120
|
+
if (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean') {
|
|
121
|
+
clean[name] = String(item);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
value: typeof value === 'string' ? value : null,
|
|
127
|
+
params: clean,
|
|
128
|
+
deferred: deferred === true,
|
|
129
|
+
url,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** The answer's JSON, or null when it is not JSON. */
|
|
133
|
+
function parseAnswer(body) {
|
|
134
|
+
try {
|
|
135
|
+
return JSON.parse(body);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/** Settles with the promise's value, or with `fallback` after `ms` or when it fails. */
|
|
142
|
+
function within(promise, ms, fallback) {
|
|
143
|
+
return new Promise((resolve) => {
|
|
144
|
+
const timer = setTimeout(() => resolve(fallback), ms);
|
|
145
|
+
promise.then((value) => {
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
resolve(value);
|
|
148
|
+
}, () => {
|
|
149
|
+
clearTimeout(timer);
|
|
150
|
+
resolve(fallback);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type { AttributionInfo, AttributionRequest, DeepLink } from './attribution';
|
|
2
|
+
export declare const SDK_VERSION = "1.1.0";
|
|
3
|
+
export declare const DEFAULT_ENDPOINT = "https://events.kissmyapps.dev";
|
|
4
|
+
export type Properties = Record<string, unknown>;
|
|
5
|
+
/** AsyncStorage, MMKV or anything with the same two methods. */
|
|
6
|
+
export interface Storage {
|
|
7
|
+
getItem(key: string): Promise<string | null> | string | null;
|
|
8
|
+
setItem(key: string, value: string): Promise<void> | void;
|
|
9
|
+
}
|
|
10
|
+
export interface DeviceInfo {
|
|
11
|
+
platform: 'ios' | 'android';
|
|
12
|
+
os_name: string;
|
|
13
|
+
os_version: string;
|
|
14
|
+
device_type: 'mobile' | 'tablet';
|
|
15
|
+
device_model?: string;
|
|
16
|
+
screen_width: number;
|
|
17
|
+
screen_height: number;
|
|
18
|
+
timezone: string;
|
|
19
|
+
language: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ClientOptions {
|
|
22
|
+
/** The project's client key, kma_pk_live_… or kma_pk_test_…. */
|
|
23
|
+
key: string;
|
|
24
|
+
endpoint?: string;
|
|
25
|
+
/** The app's version, such as 2.4.0, and build number, such as 120. */
|
|
26
|
+
appVersion?: string;
|
|
27
|
+
build?: string;
|
|
28
|
+
/** A session ends after this long in the background or without events. Default 30. */
|
|
29
|
+
sessionTimeoutMinutes?: number;
|
|
30
|
+
/** How often queued events are sent while the app is open. Default 10. */
|
|
31
|
+
flushIntervalSeconds?: number;
|
|
32
|
+
/** The most events kept while offline; the oldest go first. Default 1000. */
|
|
33
|
+
maxQueue?: number;
|
|
34
|
+
/** Record installs, updates, opens and backgrounding. Default true. */
|
|
35
|
+
trackLifecycle?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Match the install to the link that brought it on the first launch, and report links that
|
|
38
|
+
* open the app. Default true. Nothing is matched until attribution is on for the project.
|
|
39
|
+
*/
|
|
40
|
+
attribution?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* iPhone only: on the first launch, read a `kma:` click ID that the smart link's page put on
|
|
43
|
+
* the clipboard. Turn it on only with "Clipboard handoff for iPhone" on in the console:
|
|
44
|
+
* iOS asks the person before an app reads what another app copied. Default false.
|
|
45
|
+
*/
|
|
46
|
+
clipboardHandoff?: boolean;
|
|
47
|
+
debug?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface RevenueOptions {
|
|
50
|
+
/** Your product or plan, such as annual_plan. */
|
|
51
|
+
productId?: string;
|
|
52
|
+
/**
|
|
53
|
+
* The payment's ID at the store, such as StoreKit's transaction ID or Google Play's order
|
|
54
|
+
* ID. The same payment reported by the app and by a RevenueCat or Adapty webhook with the
|
|
55
|
+
* same ID counts once.
|
|
56
|
+
*/
|
|
57
|
+
transactionId?: string;
|
|
58
|
+
/** The event's name. Default purchase, or refund for a negative amount. */
|
|
59
|
+
event?: string;
|
|
60
|
+
/** More properties for the event. The kma_ revenue properties always win. */
|
|
61
|
+
properties?: Properties;
|
|
62
|
+
}
|
|
63
|
+
export interface Environment {
|
|
64
|
+
storage: Storage | null;
|
|
65
|
+
device(): DeviceInfo;
|
|
66
|
+
fetch: (url: string, init: RequestInit) => Promise<Pick<Response, 'ok' | 'status' | 'text'>>;
|
|
67
|
+
sdk: string;
|
|
68
|
+
now?: () => number;
|
|
69
|
+
log?: (message: string) => void;
|
|
70
|
+
/** The link that opened the app, such as Linking.getInitialURL(). */
|
|
71
|
+
initialLink?: () => Promise<string | null>;
|
|
72
|
+
/** What the optional native module reads: device key, install referrer, Apple Ads token, if any. */
|
|
73
|
+
attributionInfo?: (request: AttributionRequest) => Promise<AttributionInfo | null>;
|
|
74
|
+
}
|
|
75
|
+
export interface QueuedEvent {
|
|
76
|
+
name: string;
|
|
77
|
+
insert_id: string;
|
|
78
|
+
time: string;
|
|
79
|
+
screen?: string;
|
|
80
|
+
properties: Properties;
|
|
81
|
+
user_id: string | null;
|
|
82
|
+
anonymous_id: string;
|
|
83
|
+
session_id: string;
|
|
84
|
+
session_started_at: string;
|
|
85
|
+
}
|
|
86
|
+
export declare const EVENT_NAME: RegExp;
|
|
87
|
+
export declare function uuid(): string;
|
|
88
|
+
export declare class KmaClient {
|
|
89
|
+
readonly options: ClientOptions & {
|
|
90
|
+
endpoint: string;
|
|
91
|
+
};
|
|
92
|
+
private readonly env;
|
|
93
|
+
private readonly storageKey;
|
|
94
|
+
private state;
|
|
95
|
+
private queue;
|
|
96
|
+
private screenName;
|
|
97
|
+
private foregroundAt;
|
|
98
|
+
private loaded;
|
|
99
|
+
private readonly waiting;
|
|
100
|
+
private flushTimer;
|
|
101
|
+
private heartbeatTimer;
|
|
102
|
+
private saveTimer;
|
|
103
|
+
private inflight;
|
|
104
|
+
private failures;
|
|
105
|
+
private lastSent;
|
|
106
|
+
private identityPending;
|
|
107
|
+
private inForeground;
|
|
108
|
+
private firstLaunch;
|
|
109
|
+
private stopped;
|
|
110
|
+
private launched;
|
|
111
|
+
private firstLaunchNow;
|
|
112
|
+
private installRunning;
|
|
113
|
+
private installSent;
|
|
114
|
+
private installPhase;
|
|
115
|
+
private linksBeforeLaunch;
|
|
116
|
+
private waitingLinks;
|
|
117
|
+
private readonly recentLinks;
|
|
118
|
+
private deviceKeyRead;
|
|
119
|
+
private deepLinkHandler;
|
|
120
|
+
private heldDeepLink;
|
|
121
|
+
private readonly initialLink;
|
|
122
|
+
/** Settles once saved state is read and the launch is recorded. */
|
|
123
|
+
readonly ready: Promise<void>;
|
|
124
|
+
constructor(options: ClientOptions, env: Environment);
|
|
125
|
+
/** Records something a person did. */
|
|
126
|
+
track(name: string, properties?: Properties): void;
|
|
127
|
+
/**
|
|
128
|
+
* Records a payment: the amount in major units (9.99, not 999), negative for a refund, and
|
|
129
|
+
* its ISO 4217 currency code. Sent as a purchase (or refund) event with kma_revenue and
|
|
130
|
+
* kma_currency. An amount or currency that is not valid sends nothing (a warning in debug).
|
|
131
|
+
*/
|
|
132
|
+
revenue(amount: number, currency: string, options?: RevenueOptions): void;
|
|
133
|
+
/** Records a screen view; later events carry the screen's name. */
|
|
134
|
+
screen(name: string, properties?: Properties): void;
|
|
135
|
+
/** Ties this install to your own user ID, with optional traits such as email, name or plan. */
|
|
136
|
+
identify(userId: string | number, traits?: Properties): void;
|
|
137
|
+
/** Updates traits for the current person without changing who they are. */
|
|
138
|
+
setTraits(traits: Properties): void;
|
|
139
|
+
/** Forgets the user, for example on sign out: what follows is a new person and session. */
|
|
140
|
+
reset(): void;
|
|
141
|
+
/** Stops recording and drops anything not sent yet, until optIn. Remembered across launches. */
|
|
142
|
+
optOut(): void;
|
|
143
|
+
private clearConsentData;
|
|
144
|
+
optIn(): void;
|
|
145
|
+
/**
|
|
146
|
+
* Reports a link that opened the app, such as a Universal Link or App Link. Any https link
|
|
147
|
+
* is sent and KissMyApps decides whether it is one of the project's links; its deep link then
|
|
148
|
+
* goes to `onDeepLink`. Returns false when nothing is sent (not https, longer than 2,048
|
|
149
|
+
* characters, attribution off, opted out). The same link handed over twice within 3 seconds
|
|
150
|
+
* counts once, so Linking and the app may both report it.
|
|
151
|
+
*/
|
|
152
|
+
handleDeepLink(url: string): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Where deep links go: the deferred one after an install, and one each time a link opens the
|
|
155
|
+
* app. Each deep link is handed over once; one that arrives before a handler is set is held
|
|
156
|
+
* and handed to the next handler set. Pass null to stop.
|
|
157
|
+
*/
|
|
158
|
+
onDeepLink(handler: ((link: DeepLink) => void) | null): void;
|
|
159
|
+
getAnonymousId(): string;
|
|
160
|
+
getUserId(): string | null;
|
|
161
|
+
getSessionId(): string | null;
|
|
162
|
+
/** Sends everything queued now. */
|
|
163
|
+
flush(): Promise<void>;
|
|
164
|
+
/** Stops timers; the client records nothing more. */
|
|
165
|
+
shutdown(): void;
|
|
166
|
+
/** The app came to the front. The first call is the launch. */
|
|
167
|
+
foreground(): void;
|
|
168
|
+
/** The app went to the background: record it and send what is queued while it can. */
|
|
169
|
+
background(): void;
|
|
170
|
+
private load;
|
|
171
|
+
private whenLoaded;
|
|
172
|
+
private recordInstallOrUpdate;
|
|
173
|
+
private save;
|
|
174
|
+
private writeNow;
|
|
175
|
+
private now;
|
|
176
|
+
private ensureSession;
|
|
177
|
+
private enqueue;
|
|
178
|
+
private clean;
|
|
179
|
+
private context;
|
|
180
|
+
/** One request's body: queued events share a person and session; with none, a heartbeat. */
|
|
181
|
+
body(events: QueuedEvent[]): Properties;
|
|
182
|
+
private nextBatch;
|
|
183
|
+
private post;
|
|
184
|
+
private sendQueued;
|
|
185
|
+
private retryLater;
|
|
186
|
+
private scheduleFlush;
|
|
187
|
+
/** Keeps an open app counted as online. */
|
|
188
|
+
private heartbeat;
|
|
189
|
+
/** The launch: the first one queues the install call; links that came before it are routed. */
|
|
190
|
+
private attributeLaunch;
|
|
191
|
+
private routeLink;
|
|
192
|
+
private routeLaunched;
|
|
193
|
+
/** The device's details; `complete` is false when the install referrer could not be read in time. */
|
|
194
|
+
private readNative;
|
|
195
|
+
/** The first try's details again; the Apple Ads token, and a referrer that timed out, are read anew. */
|
|
196
|
+
private installInfo;
|
|
197
|
+
/** The install call: once, on the first launch; again on the next launches if it failed. */
|
|
198
|
+
private sendInstall;
|
|
199
|
+
/** Links that waited for the install's answer go to the open call now. */
|
|
200
|
+
private installAnswered;
|
|
201
|
+
private installFailed;
|
|
202
|
+
/** The open call, for a link that opened the app after the install was matched. Not retried. */
|
|
203
|
+
private sendOpen;
|
|
204
|
+
/** Hands a deep link to the handler; without one, the newest is held for the next handler. */
|
|
205
|
+
private deliver;
|
|
206
|
+
private warn;
|
|
207
|
+
}
|