@tolinku/react-native-sdk 0.8.0 → 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 +45 -1
- package/dist/index.d.ts +45 -1
- package/dist/index.js +49 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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.8.
|
|
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(() => {
|
|
@@ -357,9 +369,10 @@ var _Analytics = class _Analytics {
|
|
|
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",
|
|
@@ -1061,8 +1074,30 @@ var _Tolinku = class _Tolinku {
|
|
|
1061
1074
|
_Tolinku.deferredInstance = new Deferred(_Tolinku.client);
|
|
1062
1075
|
_Tolinku.linksInstance = new Links(_Tolinku.client);
|
|
1063
1076
|
_Tolinku._initialized = true;
|
|
1077
|
+
if (config.autoTrackLinkOpens === true) _Tolinku.startAutoLinkTracking();
|
|
1064
1078
|
debugLog(`Tolinku SDK v${SDK_VERSION} initialized (baseUrl=${baseUrl})`);
|
|
1065
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
|
+
}
|
|
1066
1101
|
/** Check whether the SDK has been initialized. */
|
|
1067
1102
|
static isConfigured() {
|
|
1068
1103
|
return _Tolinku._initialized;
|
|
@@ -1195,6 +1230,10 @@ var _Tolinku = class _Tolinku {
|
|
|
1195
1230
|
_Tolinku.client.abort();
|
|
1196
1231
|
}
|
|
1197
1232
|
resetStorageNamespace();
|
|
1233
|
+
if (_Tolinku.linkSubscription) {
|
|
1234
|
+
_Tolinku.linkSubscription.remove();
|
|
1235
|
+
_Tolinku.linkSubscription = null;
|
|
1236
|
+
}
|
|
1198
1237
|
_Tolinku.client = null;
|
|
1199
1238
|
_Tolinku.analyticsInstance = null;
|
|
1200
1239
|
_Tolinku.ecommerceInstance = null;
|
|
@@ -1215,6 +1254,14 @@ _Tolinku.deferredInstance = null;
|
|
|
1215
1254
|
_Tolinku.linksInstance = null;
|
|
1216
1255
|
_Tolinku._initialized = false;
|
|
1217
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;
|
|
1218
1265
|
var Tolinku = _Tolinku;
|
|
1219
1266
|
var DEFAULT_IMAGE_HEIGHT = 200;
|
|
1220
1267
|
function dimension(raw) {
|