@tolinku/react-native-sdk 0.7.1 → 0.8.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/dist/index.d.mts +46 -2
- package/dist/index.d.ts +46 -2
- package/dist/index.js +58 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { StyleSheet, Platform, NativeModules, AppState, Dimensions, PixelRatio, Modal, Pressable, TouchableOpacity, Text, ScrollView, View, Image, ImageBackground
|
|
1
|
+
import { StyleSheet, Platform, Linking, NativeModules, AppState, Dimensions, PixelRatio, Modal, Pressable, TouchableOpacity, Text, ScrollView, View, Image, ImageBackground } from 'react-native';
|
|
2
2
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
3
3
|
import React, { useState, useRef, useMemo, useEffect, useCallback } from 'react';
|
|
4
4
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
|
+
// src/Tolinku.ts
|
|
7
|
+
|
|
6
8
|
// src/types.ts
|
|
7
|
-
var SDK_VERSION = "0.
|
|
9
|
+
var SDK_VERSION = "0.8.1";
|
|
8
10
|
|
|
9
11
|
// src/debug.ts
|
|
10
12
|
var _debugEnabled = false;
|
|
@@ -324,6 +326,16 @@ var _Analytics = class _Analytics {
|
|
|
324
326
|
*/
|
|
325
327
|
this.lastOpenUrl = null;
|
|
326
328
|
this.lastOpenAt = 0;
|
|
329
|
+
/**
|
|
330
|
+
* Part of the key, not carried alongside it. An ordinary open and a deferred
|
|
331
|
+
* one are different events on the server and only the app can tell them
|
|
332
|
+
* apart, so a deferred report just after an ordinary one for the same link is
|
|
333
|
+
* new information rather than a repeat. Keyed on the URL alone, somebody who
|
|
334
|
+
* tapped a link, installed, then tapped it again would have the deferred
|
|
335
|
+
* report swallowed, losing the last stage of the install funnel in the one
|
|
336
|
+
* case it exists to show.
|
|
337
|
+
*/
|
|
338
|
+
this.lastOpenDeferred = false;
|
|
327
339
|
this.handleAppStateChange = (state) => {
|
|
328
340
|
if (state === "background" || state === "inactive") {
|
|
329
341
|
this.flush().catch(() => {
|
|
@@ -351,15 +363,16 @@ var _Analytics = class _Analytics {
|
|
|
351
363
|
* Never throws. This runs on the path that routes the user somewhere, and a
|
|
352
364
|
* tap that goes unrecorded is not worth interrupting that.
|
|
353
365
|
*/
|
|
354
|
-
async trackLinkOpen(url, userId) {
|
|
366
|
+
async trackLinkOpen(url, userId, deferred = false) {
|
|
355
367
|
if (this.appOpensDisabled) return;
|
|
356
368
|
const trimmed = typeof url === "string" ? url.trim() : "";
|
|
357
369
|
if (!trimmed) return;
|
|
358
370
|
if (!isSafeUrl(trimmed)) return;
|
|
359
371
|
const now = Date.now();
|
|
360
|
-
if (this.lastOpenUrl === trimmed && now - this.lastOpenAt < _Analytics.OPEN_DEDUPE_MS) return;
|
|
372
|
+
if (this.lastOpenUrl === trimmed && this.lastOpenDeferred === deferred && now - this.lastOpenAt < _Analytics.OPEN_DEDUPE_MS) return;
|
|
361
373
|
this.lastOpenUrl = trimmed;
|
|
362
374
|
this.lastOpenAt = now;
|
|
375
|
+
this.lastOpenDeferred = deferred;
|
|
363
376
|
try {
|
|
364
377
|
const result = await this.client.postPublic(
|
|
365
378
|
"/v1/api/opens",
|
|
@@ -369,6 +382,12 @@ var _Analytics = class _Analytics {
|
|
|
369
382
|
// identifies itself the same way on both. Without it an app open has
|
|
370
383
|
// no platform and lands in a blank bucket on every breakdown.
|
|
371
384
|
platform: Platform.OS === "ios" || Platform.OS === "android" ? Platform.OS : void 0,
|
|
385
|
+
// Whether this open followed a deferred install. Only the app knows.
|
|
386
|
+
// An ordinary open is somebody who already had the app and can never
|
|
387
|
+
// convert to an install; an open after a deferred claim is the last
|
|
388
|
+
// stage of the install funnel. The server records them as different
|
|
389
|
+
// events and must not pool them.
|
|
390
|
+
...deferred ? { deferred: true } : {},
|
|
372
391
|
...userId ? { user_id: userId } : {}
|
|
373
392
|
}
|
|
374
393
|
);
|
|
@@ -1055,8 +1074,30 @@ var _Tolinku = class _Tolinku {
|
|
|
1055
1074
|
_Tolinku.deferredInstance = new Deferred(_Tolinku.client);
|
|
1056
1075
|
_Tolinku.linksInstance = new Links(_Tolinku.client);
|
|
1057
1076
|
_Tolinku._initialized = true;
|
|
1077
|
+
if (config.autoTrackLinkOpens === true) _Tolinku.startAutoLinkTracking();
|
|
1058
1078
|
debugLog(`Tolinku SDK v${SDK_VERSION} initialized (baseUrl=${baseUrl})`);
|
|
1059
1079
|
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Report incoming links without the app wiring anything.
|
|
1082
|
+
*
|
|
1083
|
+
* A link arrives in two places and both need reporting: one that launches the
|
|
1084
|
+
* app cold arrives at getInitialURL, one tapped while it is already running
|
|
1085
|
+
* arrives at the listener. Instrumenting only the second is the common
|
|
1086
|
+
* mistake, because it works in every test done by hand with the app open.
|
|
1087
|
+
*
|
|
1088
|
+
* Both are wired, and the same link arriving at both inside a few seconds is
|
|
1089
|
+
* reported once: trackLinkOpen drops a repeat of the same URL, which is why
|
|
1090
|
+
* covering both here is safe rather than double counting.
|
|
1091
|
+
*/
|
|
1092
|
+
static startAutoLinkTracking() {
|
|
1093
|
+
Linking.getInitialURL().then((url) => {
|
|
1094
|
+
if (url) void _Tolinku.trackLinkOpen(url);
|
|
1095
|
+
}).catch(() => {
|
|
1096
|
+
});
|
|
1097
|
+
_Tolinku.linkSubscription = Linking.addEventListener("url", ({ url }) => {
|
|
1098
|
+
if (url) void _Tolinku.trackLinkOpen(url);
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1060
1101
|
/** Check whether the SDK has been initialized. */
|
|
1061
1102
|
static isConfigured() {
|
|
1062
1103
|
return _Tolinku._initialized;
|
|
@@ -1122,9 +1163,9 @@ var _Tolinku = class _Tolinku {
|
|
|
1122
1163
|
*
|
|
1123
1164
|
* Never throws.
|
|
1124
1165
|
*/
|
|
1125
|
-
static async trackLinkOpen(url) {
|
|
1166
|
+
static async trackLinkOpen(url, deferred = false) {
|
|
1126
1167
|
if (!_Tolinku.analyticsInstance) return;
|
|
1127
|
-
return _Tolinku.analyticsInstance.trackLinkOpen(url, _Tolinku._userId ?? void 0);
|
|
1168
|
+
return _Tolinku.analyticsInstance.trackLinkOpen(url, _Tolinku._userId ?? void 0, deferred);
|
|
1128
1169
|
}
|
|
1129
1170
|
/**
|
|
1130
1171
|
* Immediately flush all queued analytics and ecommerce events to the server.
|
|
@@ -1189,6 +1230,10 @@ var _Tolinku = class _Tolinku {
|
|
|
1189
1230
|
_Tolinku.client.abort();
|
|
1190
1231
|
}
|
|
1191
1232
|
resetStorageNamespace();
|
|
1233
|
+
if (_Tolinku.linkSubscription) {
|
|
1234
|
+
_Tolinku.linkSubscription.remove();
|
|
1235
|
+
_Tolinku.linkSubscription = null;
|
|
1236
|
+
}
|
|
1192
1237
|
_Tolinku.client = null;
|
|
1193
1238
|
_Tolinku.analyticsInstance = null;
|
|
1194
1239
|
_Tolinku.ecommerceInstance = null;
|
|
@@ -1209,6 +1254,14 @@ _Tolinku.deferredInstance = null;
|
|
|
1209
1254
|
_Tolinku.linksInstance = null;
|
|
1210
1255
|
_Tolinku._initialized = false;
|
|
1211
1256
|
_Tolinku._userId = null;
|
|
1257
|
+
/**
|
|
1258
|
+
* Removes the automatic link listener, when one was installed.
|
|
1259
|
+
*
|
|
1260
|
+
* Held here rather than inside Analytics because it is a property of this
|
|
1261
|
+
* configuration: destroy() has to take it back down or a reconfigured SDK
|
|
1262
|
+
* reports every link twice.
|
|
1263
|
+
*/
|
|
1264
|
+
_Tolinku.linkSubscription = null;
|
|
1212
1265
|
var Tolinku = _Tolinku;
|
|
1213
1266
|
var DEFAULT_IMAGE_HEIGHT = 200;
|
|
1214
1267
|
function dimension(raw) {
|