@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.d.mts
CHANGED
|
@@ -10,6 +10,20 @@ interface TolinkuConfig {
|
|
|
10
10
|
debug?: boolean;
|
|
11
11
|
/** Request timeout in milliseconds. Defaults to 30000 (30 seconds). */
|
|
12
12
|
timeout?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Report incoming links automatically, instead of calling trackLinkOpen by
|
|
15
|
+
* hand. Defaults to false.
|
|
16
|
+
*
|
|
17
|
+
* Off by default because a reported open is billed as a click. Turning this
|
|
18
|
+
* on by upgrading would raise somebody's bill without them asking, so it is
|
|
19
|
+
* a decision the app makes rather than one a release makes for it.
|
|
20
|
+
*
|
|
21
|
+
* Covers both ways a link arrives on React Native, the cold start and the
|
|
22
|
+
* listener, which is the pair that is easy to get half right by hand. It does
|
|
23
|
+
* not cover the open after a deferred install: only your app knows that it
|
|
24
|
+
* just claimed a link, so that one is still reported explicitly.
|
|
25
|
+
*/
|
|
26
|
+
autoTrackLinkOpens?: boolean;
|
|
13
27
|
}
|
|
14
28
|
/** Resolved configuration with all defaults applied */
|
|
15
29
|
interface ResolvedTolinkuConfig {
|
|
@@ -101,6 +115,15 @@ interface LeaderboardEntry {
|
|
|
101
115
|
interface DeferredLink {
|
|
102
116
|
deep_link_path: string;
|
|
103
117
|
appspace_id: string;
|
|
118
|
+
/**
|
|
119
|
+
* The absolute URL for this link, for reporting the open that follows.
|
|
120
|
+
*
|
|
121
|
+
* Reporting an open needs the whole URL, not the path: the host is how the
|
|
122
|
+
* server finds the Appspace and the only thing proving the link belongs to
|
|
123
|
+
* it, and the device has no way to know it. Absent from servers older than
|
|
124
|
+
* this field, so treat it as optional.
|
|
125
|
+
*/
|
|
126
|
+
url?: string;
|
|
104
127
|
referrer_id?: string;
|
|
105
128
|
referral_code?: string;
|
|
106
129
|
}
|
|
@@ -450,7 +473,7 @@ declare class Links {
|
|
|
450
473
|
* await Tolinku.track('signup', { source: 'onboarding' });
|
|
451
474
|
*/
|
|
452
475
|
declare class Tolinku {
|
|
453
|
-
static readonly VERSION = "0.8.
|
|
476
|
+
static readonly VERSION = "0.8.1";
|
|
454
477
|
private static client;
|
|
455
478
|
private static analyticsInstance;
|
|
456
479
|
private static ecommerceInstance;
|
|
@@ -474,7 +497,28 @@ declare class Tolinku {
|
|
|
474
497
|
* moving off it is a one-line change rather than a surprise.
|
|
475
498
|
*/
|
|
476
499
|
static configure(config: TolinkuConfig): void;
|
|
500
|
+
/**
|
|
501
|
+
* Removes the automatic link listener, when one was installed.
|
|
502
|
+
*
|
|
503
|
+
* Held here rather than inside Analytics because it is a property of this
|
|
504
|
+
* configuration: destroy() has to take it back down or a reconfigured SDK
|
|
505
|
+
* reports every link twice.
|
|
506
|
+
*/
|
|
507
|
+
private static linkSubscription;
|
|
477
508
|
static init(config: TolinkuConfig): void;
|
|
509
|
+
/**
|
|
510
|
+
* Report incoming links without the app wiring anything.
|
|
511
|
+
*
|
|
512
|
+
* A link arrives in two places and both need reporting: one that launches the
|
|
513
|
+
* app cold arrives at getInitialURL, one tapped while it is already running
|
|
514
|
+
* arrives at the listener. Instrumenting only the second is the common
|
|
515
|
+
* mistake, because it works in every test done by hand with the app open.
|
|
516
|
+
*
|
|
517
|
+
* Both are wired, and the same link arriving at both inside a few seconds is
|
|
518
|
+
* reported once: trackLinkOpen drops a repeat of the same URL, which is why
|
|
519
|
+
* covering both here is safe rather than double counting.
|
|
520
|
+
*/
|
|
521
|
+
private static startAutoLinkTracking;
|
|
478
522
|
/** Check whether the SDK has been initialized. */
|
|
479
523
|
static isConfigured(): boolean;
|
|
480
524
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,20 @@ interface TolinkuConfig {
|
|
|
10
10
|
debug?: boolean;
|
|
11
11
|
/** Request timeout in milliseconds. Defaults to 30000 (30 seconds). */
|
|
12
12
|
timeout?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Report incoming links automatically, instead of calling trackLinkOpen by
|
|
15
|
+
* hand. Defaults to false.
|
|
16
|
+
*
|
|
17
|
+
* Off by default because a reported open is billed as a click. Turning this
|
|
18
|
+
* on by upgrading would raise somebody's bill without them asking, so it is
|
|
19
|
+
* a decision the app makes rather than one a release makes for it.
|
|
20
|
+
*
|
|
21
|
+
* Covers both ways a link arrives on React Native, the cold start and the
|
|
22
|
+
* listener, which is the pair that is easy to get half right by hand. It does
|
|
23
|
+
* not cover the open after a deferred install: only your app knows that it
|
|
24
|
+
* just claimed a link, so that one is still reported explicitly.
|
|
25
|
+
*/
|
|
26
|
+
autoTrackLinkOpens?: boolean;
|
|
13
27
|
}
|
|
14
28
|
/** Resolved configuration with all defaults applied */
|
|
15
29
|
interface ResolvedTolinkuConfig {
|
|
@@ -101,6 +115,15 @@ interface LeaderboardEntry {
|
|
|
101
115
|
interface DeferredLink {
|
|
102
116
|
deep_link_path: string;
|
|
103
117
|
appspace_id: string;
|
|
118
|
+
/**
|
|
119
|
+
* The absolute URL for this link, for reporting the open that follows.
|
|
120
|
+
*
|
|
121
|
+
* Reporting an open needs the whole URL, not the path: the host is how the
|
|
122
|
+
* server finds the Appspace and the only thing proving the link belongs to
|
|
123
|
+
* it, and the device has no way to know it. Absent from servers older than
|
|
124
|
+
* this field, so treat it as optional.
|
|
125
|
+
*/
|
|
126
|
+
url?: string;
|
|
104
127
|
referrer_id?: string;
|
|
105
128
|
referral_code?: string;
|
|
106
129
|
}
|
|
@@ -450,7 +473,7 @@ declare class Links {
|
|
|
450
473
|
* await Tolinku.track('signup', { source: 'onboarding' });
|
|
451
474
|
*/
|
|
452
475
|
declare class Tolinku {
|
|
453
|
-
static readonly VERSION = "0.8.
|
|
476
|
+
static readonly VERSION = "0.8.1";
|
|
454
477
|
private static client;
|
|
455
478
|
private static analyticsInstance;
|
|
456
479
|
private static ecommerceInstance;
|
|
@@ -474,7 +497,28 @@ declare class Tolinku {
|
|
|
474
497
|
* moving off it is a one-line change rather than a surprise.
|
|
475
498
|
*/
|
|
476
499
|
static configure(config: TolinkuConfig): void;
|
|
500
|
+
/**
|
|
501
|
+
* Removes the automatic link listener, when one was installed.
|
|
502
|
+
*
|
|
503
|
+
* Held here rather than inside Analytics because it is a property of this
|
|
504
|
+
* configuration: destroy() has to take it back down or a reconfigured SDK
|
|
505
|
+
* reports every link twice.
|
|
506
|
+
*/
|
|
507
|
+
private static linkSubscription;
|
|
477
508
|
static init(config: TolinkuConfig): void;
|
|
509
|
+
/**
|
|
510
|
+
* Report incoming links without the app wiring anything.
|
|
511
|
+
*
|
|
512
|
+
* A link arrives in two places and both need reporting: one that launches the
|
|
513
|
+
* app cold arrives at getInitialURL, one tapped while it is already running
|
|
514
|
+
* arrives at the listener. Instrumenting only the second is the common
|
|
515
|
+
* mistake, because it works in every test done by hand with the app open.
|
|
516
|
+
*
|
|
517
|
+
* Both are wired, and the same link arriving at both inside a few seconds is
|
|
518
|
+
* reported once: trackLinkOpen drops a repeat of the same URL, which is why
|
|
519
|
+
* covering both here is safe rather than double counting.
|
|
520
|
+
*/
|
|
521
|
+
private static startAutoLinkTracking;
|
|
478
522
|
/** Check whether the SDK has been initialized. */
|
|
479
523
|
static isConfigured(): boolean;
|
|
480
524
|
/**
|
package/dist/index.js
CHANGED
|
@@ -10,8 +10,10 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
10
10
|
var AsyncStorage__default = /*#__PURE__*/_interopDefault(AsyncStorage);
|
|
11
11
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
12
12
|
|
|
13
|
+
// src/Tolinku.ts
|
|
14
|
+
|
|
13
15
|
// src/types.ts
|
|
14
|
-
var SDK_VERSION = "0.8.
|
|
16
|
+
var SDK_VERSION = "0.8.1";
|
|
15
17
|
|
|
16
18
|
// src/debug.ts
|
|
17
19
|
var _debugEnabled = false;
|
|
@@ -331,6 +333,16 @@ var _Analytics = class _Analytics {
|
|
|
331
333
|
*/
|
|
332
334
|
this.lastOpenUrl = null;
|
|
333
335
|
this.lastOpenAt = 0;
|
|
336
|
+
/**
|
|
337
|
+
* Part of the key, not carried alongside it. An ordinary open and a deferred
|
|
338
|
+
* one are different events on the server and only the app can tell them
|
|
339
|
+
* apart, so a deferred report just after an ordinary one for the same link is
|
|
340
|
+
* new information rather than a repeat. Keyed on the URL alone, somebody who
|
|
341
|
+
* tapped a link, installed, then tapped it again would have the deferred
|
|
342
|
+
* report swallowed, losing the last stage of the install funnel in the one
|
|
343
|
+
* case it exists to show.
|
|
344
|
+
*/
|
|
345
|
+
this.lastOpenDeferred = false;
|
|
334
346
|
this.handleAppStateChange = (state) => {
|
|
335
347
|
if (state === "background" || state === "inactive") {
|
|
336
348
|
this.flush().catch(() => {
|
|
@@ -364,9 +376,10 @@ var _Analytics = class _Analytics {
|
|
|
364
376
|
if (!trimmed) return;
|
|
365
377
|
if (!isSafeUrl(trimmed)) return;
|
|
366
378
|
const now = Date.now();
|
|
367
|
-
if (this.lastOpenUrl === trimmed && now - this.lastOpenAt < _Analytics.OPEN_DEDUPE_MS) return;
|
|
379
|
+
if (this.lastOpenUrl === trimmed && this.lastOpenDeferred === deferred && now - this.lastOpenAt < _Analytics.OPEN_DEDUPE_MS) return;
|
|
368
380
|
this.lastOpenUrl = trimmed;
|
|
369
381
|
this.lastOpenAt = now;
|
|
382
|
+
this.lastOpenDeferred = deferred;
|
|
370
383
|
try {
|
|
371
384
|
const result = await this.client.postPublic(
|
|
372
385
|
"/v1/api/opens",
|
|
@@ -1068,8 +1081,30 @@ var _Tolinku = class _Tolinku {
|
|
|
1068
1081
|
_Tolinku.deferredInstance = new Deferred(_Tolinku.client);
|
|
1069
1082
|
_Tolinku.linksInstance = new Links(_Tolinku.client);
|
|
1070
1083
|
_Tolinku._initialized = true;
|
|
1084
|
+
if (config.autoTrackLinkOpens === true) _Tolinku.startAutoLinkTracking();
|
|
1071
1085
|
debugLog(`Tolinku SDK v${SDK_VERSION} initialized (baseUrl=${baseUrl})`);
|
|
1072
1086
|
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Report incoming links without the app wiring anything.
|
|
1089
|
+
*
|
|
1090
|
+
* A link arrives in two places and both need reporting: one that launches the
|
|
1091
|
+
* app cold arrives at getInitialURL, one tapped while it is already running
|
|
1092
|
+
* arrives at the listener. Instrumenting only the second is the common
|
|
1093
|
+
* mistake, because it works in every test done by hand with the app open.
|
|
1094
|
+
*
|
|
1095
|
+
* Both are wired, and the same link arriving at both inside a few seconds is
|
|
1096
|
+
* reported once: trackLinkOpen drops a repeat of the same URL, which is why
|
|
1097
|
+
* covering both here is safe rather than double counting.
|
|
1098
|
+
*/
|
|
1099
|
+
static startAutoLinkTracking() {
|
|
1100
|
+
reactNative.Linking.getInitialURL().then((url) => {
|
|
1101
|
+
if (url) void _Tolinku.trackLinkOpen(url);
|
|
1102
|
+
}).catch(() => {
|
|
1103
|
+
});
|
|
1104
|
+
_Tolinku.linkSubscription = reactNative.Linking.addEventListener("url", ({ url }) => {
|
|
1105
|
+
if (url) void _Tolinku.trackLinkOpen(url);
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1073
1108
|
/** Check whether the SDK has been initialized. */
|
|
1074
1109
|
static isConfigured() {
|
|
1075
1110
|
return _Tolinku._initialized;
|
|
@@ -1202,6 +1237,10 @@ var _Tolinku = class _Tolinku {
|
|
|
1202
1237
|
_Tolinku.client.abort();
|
|
1203
1238
|
}
|
|
1204
1239
|
resetStorageNamespace();
|
|
1240
|
+
if (_Tolinku.linkSubscription) {
|
|
1241
|
+
_Tolinku.linkSubscription.remove();
|
|
1242
|
+
_Tolinku.linkSubscription = null;
|
|
1243
|
+
}
|
|
1205
1244
|
_Tolinku.client = null;
|
|
1206
1245
|
_Tolinku.analyticsInstance = null;
|
|
1207
1246
|
_Tolinku.ecommerceInstance = null;
|
|
@@ -1222,6 +1261,14 @@ _Tolinku.deferredInstance = null;
|
|
|
1222
1261
|
_Tolinku.linksInstance = null;
|
|
1223
1262
|
_Tolinku._initialized = false;
|
|
1224
1263
|
_Tolinku._userId = null;
|
|
1264
|
+
/**
|
|
1265
|
+
* Removes the automatic link listener, when one was installed.
|
|
1266
|
+
*
|
|
1267
|
+
* Held here rather than inside Analytics because it is a property of this
|
|
1268
|
+
* configuration: destroy() has to take it back down or a reconfigured SDK
|
|
1269
|
+
* reports every link twice.
|
|
1270
|
+
*/
|
|
1271
|
+
_Tolinku.linkSubscription = null;
|
|
1225
1272
|
var Tolinku = _Tolinku;
|
|
1226
1273
|
var DEFAULT_IMAGE_HEIGHT = 200;
|
|
1227
1274
|
function dimension(raw) {
|