@glomopay/react-native-sdk 2.0.2 → 3.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 +79 -0
- package/MIGRATION.md +50 -0
- package/README.md +348 -316
- package/lib/config/base.d.ts +17 -11
- package/lib/config/base.d.ts.map +1 -1
- package/lib/config/base.js +19 -7
- package/lib/config/segment.js +3 -3
- package/lib/glomo-checkout.d.ts +8 -0
- package/lib/glomo-checkout.d.ts.map +1 -0
- package/lib/glomo-checkout.js +106 -0
- package/lib/glomo-lrs-checkout.js +9 -9
- package/lib/glomo-standard-checkout.d.ts +25 -0
- package/lib/glomo-standard-checkout.d.ts.map +1 -0
- package/lib/glomo-standard-checkout.js +229 -0
- package/lib/glomo-subscriptions-checkout.d.ts +8 -0
- package/lib/glomo-subscriptions-checkout.d.ts.map +1 -0
- package/lib/glomo-subscriptions-checkout.js +85 -0
- package/lib/index.d.ts +5 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -5
- package/lib/injections/index.d.ts +1 -0
- package/lib/injections/index.d.ts.map +1 -1
- package/lib/injections/index.js +2 -0
- package/lib/injections/webview-flow.injection.d.ts.map +1 -1
- package/lib/injections/webview-flow.injection.js +106 -69
- package/lib/injections/webview-main.injection.d.ts.map +1 -1
- package/lib/injections/webview-main.injection.js +112 -77
- package/lib/injections/webview-standard.injection.d.ts +3 -0
- package/lib/injections/webview-standard.injection.d.ts.map +1 -0
- package/lib/injections/webview-standard.injection.js +214 -0
- package/lib/services/order-type-fetcher.d.ts +28 -0
- package/lib/services/order-type-fetcher.d.ts.map +1 -0
- package/lib/services/order-type-fetcher.js +99 -0
- package/lib/types/checkout.d.ts +65 -0
- package/lib/types/checkout.d.ts.map +1 -0
- package/lib/types/checkout.js +3 -0
- package/lib/types/standard-checkout.d.ts +40 -0
- package/lib/types/standard-checkout.d.ts.map +1 -0
- package/lib/types/standard-checkout.js +3 -0
- package/lib/types/subscriptions-checkout.d.ts +29 -0
- package/lib/types/subscriptions-checkout.d.ts.map +1 -0
- package/lib/types/subscriptions-checkout.js +3 -0
- package/lib/use-glomo-checkout.d.ts +54 -0
- package/lib/use-glomo-checkout.d.ts.map +1 -0
- package/lib/use-glomo-checkout.js +261 -0
- package/lib/use-lrs-checkout.d.ts +9 -4
- package/lib/use-lrs-checkout.d.ts.map +1 -1
- package/lib/use-lrs-checkout.js +76 -93
- package/lib/use-standard-checkout.d.ts +74 -0
- package/lib/use-standard-checkout.d.ts.map +1 -0
- package/lib/use-standard-checkout.js +849 -0
- package/lib/utils/analytics.d.ts +188 -2
- package/lib/utils/analytics.d.ts.map +1 -1
- package/lib/utils/analytics.js +636 -22
- package/lib/utils/device-compliance.d.ts.map +1 -1
- package/lib/utils/device-compliance.js +3 -4
- package/lib/utils/validation.d.ts.map +1 -1
- package/lib/utils/validation.js +7 -6
- package/package.json +17 -5
- package/src/config/base.ts +36 -17
- package/src/config/segment.ts +3 -3
- package/src/glomo-checkout.tsx +147 -0
- package/src/glomo-lrs-checkout.tsx +9 -9
- package/src/glomo-standard-checkout.tsx +353 -0
- package/src/glomo-subscriptions-checkout.tsx +83 -0
- package/src/index.ts +13 -7
- package/src/injections/index.ts +2 -0
- package/src/injections/webview-flow.injection.ts +106 -69
- package/src/injections/webview-main.injection.ts +112 -77
- package/src/injections/webview-standard.injection.ts +211 -0
- package/src/services/order-type-fetcher.ts +86 -0
- package/src/types/checkout.ts +72 -0
- package/src/types/standard-checkout.ts +49 -0
- package/src/types/subscriptions-checkout.ts +31 -0
- package/src/use-glomo-checkout.tsx +369 -0
- package/src/use-lrs-checkout.tsx +91 -111
- package/src/use-standard-checkout.tsx +1203 -0
- package/src/utils/analytics.ts +908 -34
- package/src/utils/device-compliance.ts +3 -4
- package/src/utils/validation.ts +7 -8
package/src/utils/analytics.ts
CHANGED
|
@@ -10,8 +10,14 @@
|
|
|
10
10
|
* Analytics failures never break the SDK.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import { Platform } from "react-native";
|
|
13
14
|
import { getSegmentClient, isSegmentAvailable, getAnonymousId, getSegmentWriteKey } from "../config/segment";
|
|
14
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Flow type for checkout
|
|
18
|
+
*/
|
|
19
|
+
export type FlowType = "lrs" | "standard" | "unified" | "subscriptions";
|
|
20
|
+
|
|
15
21
|
/**
|
|
16
22
|
* Common properties that should be included with every event
|
|
17
23
|
*/
|
|
@@ -21,7 +27,11 @@ export interface CommonEventProperties {
|
|
|
21
27
|
mockMode?: boolean;
|
|
22
28
|
orderId?: string;
|
|
23
29
|
publicKey?: string;
|
|
24
|
-
|
|
30
|
+
checkoutUrl?: string;
|
|
31
|
+
platform: "react-native";
|
|
32
|
+
deviceOS: "ios" | "android" | string;
|
|
33
|
+
deviceOSVersion: string;
|
|
34
|
+
flowType?: FlowType;
|
|
25
35
|
timestamp?: string;
|
|
26
36
|
[key: string]: unknown;
|
|
27
37
|
}
|
|
@@ -30,7 +40,7 @@ export interface CommonEventProperties {
|
|
|
30
40
|
export interface SdkError {
|
|
31
41
|
type: "validation_error" | "device_forbidden";
|
|
32
42
|
message: string;
|
|
33
|
-
field?: "publicKey" | "orderId" | "baseCheckoutUrl" | "generatedCheckoutUrl";
|
|
43
|
+
field?: "publicKey" | "orderId" | "subscriptionId" | "baseCheckoutUrl" | "generatedCheckoutUrl";
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
/**
|
|
@@ -42,7 +52,6 @@ export interface SdkError {
|
|
|
42
52
|
function getSdkVersion(): string {
|
|
43
53
|
try {
|
|
44
54
|
// Using require to dynamically import package.json
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
46
55
|
const packageJson = require("../../package.json");
|
|
47
56
|
return packageJson.version || "unknown";
|
|
48
57
|
} catch {
|
|
@@ -58,7 +67,8 @@ function getSdkVersion(): string {
|
|
|
58
67
|
* @param publicKey - The public key of the merchant
|
|
59
68
|
* @param devMode - Whether dev mode is enabled
|
|
60
69
|
* @param mockMode - Whether mock mode is enabled
|
|
61
|
-
* @param
|
|
70
|
+
* @param checkoutUrl - The checkout URL
|
|
71
|
+
* @param flowType - The flow type
|
|
62
72
|
* @returns Common properties object
|
|
63
73
|
*/
|
|
64
74
|
function buildCommonProperties(
|
|
@@ -66,16 +76,21 @@ function buildCommonProperties(
|
|
|
66
76
|
publicKey?: string,
|
|
67
77
|
devMode: boolean = false,
|
|
68
78
|
mockMode: boolean = false,
|
|
69
|
-
|
|
79
|
+
checkoutUrl?: string,
|
|
80
|
+
flowType?: FlowType
|
|
70
81
|
): CommonEventProperties {
|
|
71
82
|
return {
|
|
72
83
|
orderId,
|
|
73
84
|
publicKey,
|
|
74
|
-
|
|
85
|
+
checkoutUrl,
|
|
75
86
|
devMode,
|
|
76
87
|
mockMode,
|
|
88
|
+
platform: "react-native",
|
|
89
|
+
deviceOS: Platform.OS,
|
|
90
|
+
deviceOSVersion: String(Platform.Version),
|
|
77
91
|
sdkVersion: getSdkVersion(),
|
|
78
92
|
timestamp: new Date().toISOString(),
|
|
93
|
+
...(flowType && { flowType }),
|
|
79
94
|
};
|
|
80
95
|
}
|
|
81
96
|
|
|
@@ -97,7 +112,7 @@ async function trackEvent(
|
|
|
97
112
|
// Returning early if GlomoPay Segment is not available
|
|
98
113
|
if (!isSegmentAvailable()) {
|
|
99
114
|
if (devMode) {
|
|
100
|
-
console.log(`[
|
|
115
|
+
console.log(`[Glomo-RN-SDK] Segment not available. Event "${eventName}" not tracked.`, properties);
|
|
101
116
|
}
|
|
102
117
|
return;
|
|
103
118
|
}
|
|
@@ -109,7 +124,7 @@ async function trackEvent(
|
|
|
109
124
|
// Double-checking if the client exists (TypeScript safety)
|
|
110
125
|
if (!client || !anonymousId) {
|
|
111
126
|
if (devMode) {
|
|
112
|
-
console.log(`[
|
|
127
|
+
console.log(`[Glomo-RN-SDK] Segment client is null. Event "${eventName}" not tracked.`);
|
|
113
128
|
}
|
|
114
129
|
return;
|
|
115
130
|
}
|
|
@@ -139,12 +154,12 @@ async function trackEvent(
|
|
|
139
154
|
await client.post("/track", payload);
|
|
140
155
|
|
|
141
156
|
if (devMode) {
|
|
142
|
-
console.log(`[
|
|
157
|
+
console.log(`[Glomo-RN-SDK] Tracked event: ${eventName}`, eventProperties);
|
|
143
158
|
}
|
|
144
159
|
} catch (error) {
|
|
145
160
|
if (devMode) {
|
|
146
161
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
147
|
-
console.error(`[
|
|
162
|
+
console.error(`[Glomo-RN-SDK] Error tracking event ${eventName}:`, errorMessage);
|
|
148
163
|
}
|
|
149
164
|
// Silently failing - GlomoPay analytics should never break the SDK
|
|
150
165
|
}
|
|
@@ -181,7 +196,7 @@ export function trackStartSuccess(
|
|
|
181
196
|
// Async tracking to avoid blocking the main thread
|
|
182
197
|
trackEvent("LRS Checkout Started", properties, devMode).catch((error) => {
|
|
183
198
|
if (devMode) {
|
|
184
|
-
console.error(`[
|
|
199
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on start() success:`, error);
|
|
185
200
|
}
|
|
186
201
|
});
|
|
187
202
|
}
|
|
@@ -220,7 +235,7 @@ export function trackStartAttempt(
|
|
|
220
235
|
// Async tracking to avoid blocking the main thread
|
|
221
236
|
trackEvent("LRS Checkout Start Attempted", properties, devMode).catch((error) => {
|
|
222
237
|
if (devMode) {
|
|
223
|
-
console.error(`[
|
|
238
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on start() attempt:`, error);
|
|
224
239
|
}
|
|
225
240
|
});
|
|
226
241
|
}
|
|
@@ -259,7 +274,7 @@ export function trackStartFailure(
|
|
|
259
274
|
// Async tracking to avoid blocking the main thread
|
|
260
275
|
trackEvent("LRS Checkout Start Failed", properties, devMode).catch((error) => {
|
|
261
276
|
if (devMode) {
|
|
262
|
-
console.error(`[
|
|
277
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on start() failure:`, error);
|
|
263
278
|
}
|
|
264
279
|
});
|
|
265
280
|
}
|
|
@@ -292,7 +307,7 @@ export function trackWindowOpen(
|
|
|
292
307
|
// Async tracking to avoid blocking the main thread
|
|
293
308
|
trackEvent("LRS Checkout Window Open", properties, devMode).catch((error) => {
|
|
294
309
|
if (devMode) {
|
|
295
|
-
console.error(`[
|
|
310
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on window.open:`, error);
|
|
296
311
|
}
|
|
297
312
|
});
|
|
298
313
|
}
|
|
@@ -322,7 +337,7 @@ export function trackWindowClose(
|
|
|
322
337
|
// Async tracking to avoid blocking the main thread
|
|
323
338
|
trackEvent("LRS Checkout Window Close", properties, devMode).catch((error) => {
|
|
324
339
|
if (devMode) {
|
|
325
|
-
console.error(`[
|
|
340
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on window.close:`, error);
|
|
326
341
|
}
|
|
327
342
|
});
|
|
328
343
|
}
|
|
@@ -377,7 +392,7 @@ export function trackInvalidMessageReceived(
|
|
|
377
392
|
// Async tracking to avoid blocking the main thread
|
|
378
393
|
trackEvent("LRS Checkout Invalid Message Received", properties, devMode).catch((error) => {
|
|
379
394
|
if (devMode) {
|
|
380
|
-
console.error(`[
|
|
395
|
+
console.error(`[Glomo-RN-SDK] Event tracking error for invalid message received event:`, error);
|
|
381
396
|
}
|
|
382
397
|
});
|
|
383
398
|
}
|
|
@@ -407,7 +422,7 @@ export function trackPaymentSuccess(
|
|
|
407
422
|
// Async tracking to avoid blocking the main thread
|
|
408
423
|
trackEvent("LRS Payment Success", properties, devMode).catch((error) => {
|
|
409
424
|
if (devMode) {
|
|
410
|
-
console.error(`[
|
|
425
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on payment success callback:`, error);
|
|
411
426
|
}
|
|
412
427
|
});
|
|
413
428
|
}
|
|
@@ -437,7 +452,7 @@ export function trackPaymentFailure(
|
|
|
437
452
|
// Async tracking to avoid blocking the main thread
|
|
438
453
|
trackEvent("LRS Payment Failure", properties, devMode).catch((error) => {
|
|
439
454
|
if (devMode) {
|
|
440
|
-
console.error(`[
|
|
455
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on payment failure callback:`, error);
|
|
441
456
|
}
|
|
442
457
|
});
|
|
443
458
|
}
|
|
@@ -467,7 +482,7 @@ export function trackPaymentTerminate(
|
|
|
467
482
|
// Async tracking to avoid blocking the main thread
|
|
468
483
|
trackEvent("LRS Payment Terminated", properties, devMode).catch((error) => {
|
|
469
484
|
if (devMode) {
|
|
470
|
-
console.error(`[
|
|
485
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on payment terminate callback:`, error);
|
|
471
486
|
}
|
|
472
487
|
});
|
|
473
488
|
}
|
|
@@ -497,7 +512,7 @@ export function trackConnectionError(
|
|
|
497
512
|
// Async tracking to avoid blocking the main thread
|
|
498
513
|
trackEvent("LRS Connection Error", properties, devMode).catch((error) => {
|
|
499
514
|
if (devMode) {
|
|
500
|
-
console.error(`[
|
|
515
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on connection error callback:`, error);
|
|
501
516
|
}
|
|
502
517
|
});
|
|
503
518
|
}
|
|
@@ -526,7 +541,36 @@ export function trackEducationStepsShown(
|
|
|
526
541
|
};
|
|
527
542
|
trackEvent("LRS Has Education Steps", properties, devMode).catch((error) => {
|
|
528
543
|
if (devMode) {
|
|
529
|
-
console.error(`[
|
|
544
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on education steps shown event:`, error);
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Tracks when the education carousel URL is invalid and the carousel cannot be shown
|
|
551
|
+
*
|
|
552
|
+
* @param orderId - The order ID
|
|
553
|
+
* @param publicKey - The public key of the merchant
|
|
554
|
+
* @param devMode - Whether dev mode is enabled
|
|
555
|
+
* @param mockMode - Whether mock mode is enabled
|
|
556
|
+
* @param lrsUrl - The LRS checkout URL
|
|
557
|
+
* @param reason - Why the carousel failed to show
|
|
558
|
+
*/
|
|
559
|
+
export function trackEducationStepsFailedToShow(
|
|
560
|
+
orderId: string,
|
|
561
|
+
publicKey: string,
|
|
562
|
+
devMode: boolean = false,
|
|
563
|
+
mockMode: boolean = false,
|
|
564
|
+
lrsUrl?: string,
|
|
565
|
+
reason?: string
|
|
566
|
+
): void {
|
|
567
|
+
const properties = {
|
|
568
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, lrsUrl),
|
|
569
|
+
...(reason && { reason }),
|
|
570
|
+
};
|
|
571
|
+
trackEvent("LRS Education Steps Failed To Show", properties, devMode).catch((error) => {
|
|
572
|
+
if (devMode) {
|
|
573
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on education steps failed to show event:`, error);
|
|
530
574
|
}
|
|
531
575
|
});
|
|
532
576
|
}
|
|
@@ -557,28 +601,858 @@ export function trackSdkError(
|
|
|
557
601
|
// Async tracking to avoid blocking the main thread
|
|
558
602
|
trackEvent("LRS SDK Error", properties, devMode).catch((error) => {
|
|
559
603
|
if (devMode) {
|
|
560
|
-
console.error(`[
|
|
604
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on SDK error callback:`, error);
|
|
561
605
|
}
|
|
562
606
|
});
|
|
563
607
|
}
|
|
564
608
|
|
|
609
|
+
// ---------------------------------------------------------------------------
|
|
610
|
+
// Standard Checkout Trackers
|
|
611
|
+
// ---------------------------------------------------------------------------
|
|
612
|
+
|
|
565
613
|
/**
|
|
566
|
-
*
|
|
567
|
-
* To be used for debugging merchant integration issues
|
|
568
|
-
*
|
|
569
|
-
* @param devMode - Console logs will be enabled for dev mode
|
|
570
|
-
* @returns true if GlomoPay Segment is available, false otherwise
|
|
614
|
+
* Tracks when the standard checkout start() method has been called successfully
|
|
571
615
|
*/
|
|
572
|
-
export function
|
|
573
|
-
|
|
616
|
+
export function trackStandardStartSuccess(
|
|
617
|
+
orderId: string,
|
|
618
|
+
publicKey: string,
|
|
619
|
+
devMode: boolean = false,
|
|
620
|
+
mockMode: boolean = false,
|
|
621
|
+
standardUrl?: string,
|
|
622
|
+
jailbreakDetectionInfo?: {
|
|
623
|
+
jailbreakDetectionLibraryInstalled: boolean;
|
|
624
|
+
jailbreakDetected: boolean | null;
|
|
625
|
+
}
|
|
626
|
+
): void {
|
|
627
|
+
const properties = {
|
|
628
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
629
|
+
...(jailbreakDetectionInfo && {
|
|
630
|
+
jailbreakDetectionLibraryInstalled: jailbreakDetectionInfo.jailbreakDetectionLibraryInstalled,
|
|
631
|
+
jailbreakDetected: jailbreakDetectionInfo.jailbreakDetected,
|
|
632
|
+
}),
|
|
633
|
+
};
|
|
634
|
+
trackEvent("Standard Checkout Started", properties, devMode).catch((error) => {
|
|
635
|
+
if (devMode) {
|
|
636
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard start:", error);
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
}
|
|
574
640
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
641
|
+
/**
|
|
642
|
+
* Tracks when the standard checkout start() method is called (attempted)
|
|
643
|
+
*/
|
|
644
|
+
export function trackStandardStartAttempt(
|
|
645
|
+
status: string,
|
|
646
|
+
orderId: string,
|
|
647
|
+
publicKey: string,
|
|
648
|
+
devMode: boolean = false,
|
|
649
|
+
mockMode: boolean = false,
|
|
650
|
+
standardUrl?: string,
|
|
651
|
+
jailbreakDetectionInfo?: {
|
|
652
|
+
jailbreakDetectionLibraryInstalled: boolean;
|
|
653
|
+
jailbreakDetected: boolean | null;
|
|
654
|
+
}
|
|
655
|
+
): void {
|
|
656
|
+
const properties = {
|
|
657
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
658
|
+
status,
|
|
659
|
+
...(jailbreakDetectionInfo && {
|
|
660
|
+
jailbreakDetectionLibraryInstalled: jailbreakDetectionInfo.jailbreakDetectionLibraryInstalled,
|
|
661
|
+
jailbreakDetected: jailbreakDetectionInfo.jailbreakDetected,
|
|
662
|
+
}),
|
|
663
|
+
};
|
|
664
|
+
trackEvent("Standard Checkout Start Attempted", properties, devMode).catch((error) => {
|
|
665
|
+
if (devMode) {
|
|
666
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard start attempt:", error);
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Tracks when the standard checkout start() method fails
|
|
673
|
+
*/
|
|
674
|
+
export function trackStandardStartFailure(
|
|
675
|
+
reason: "device_forbidden" | "validation_error" | "payment_successful" | "invalid_status" | "invalid_url",
|
|
676
|
+
orderId?: string,
|
|
677
|
+
publicKey?: string,
|
|
678
|
+
devMode: boolean = false,
|
|
679
|
+
mockMode: boolean = false,
|
|
680
|
+
standardUrl?: string,
|
|
681
|
+
jailbreakDetectionInfo?: {
|
|
682
|
+
jailbreakDetectionLibraryInstalled: boolean;
|
|
683
|
+
jailbreakDetected: boolean | null;
|
|
684
|
+
}
|
|
685
|
+
): void {
|
|
686
|
+
const properties = {
|
|
687
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
688
|
+
failureReason: reason,
|
|
689
|
+
...(jailbreakDetectionInfo && {
|
|
690
|
+
jailbreakDetectionLibraryInstalled: jailbreakDetectionInfo.jailbreakDetectionLibraryInstalled,
|
|
691
|
+
jailbreakDetected: jailbreakDetectionInfo.jailbreakDetected,
|
|
692
|
+
}),
|
|
693
|
+
};
|
|
694
|
+
trackEvent("Standard Checkout Start Failed", properties, devMode).catch((error) => {
|
|
695
|
+
if (devMode) {
|
|
696
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard start failure:", error);
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Tracks when window.open is intercepted from the standard checkout WebView
|
|
703
|
+
*/
|
|
704
|
+
export function trackStandardWindowOpen(
|
|
705
|
+
source: "main" | "flow",
|
|
706
|
+
url: string,
|
|
707
|
+
orderId: string,
|
|
708
|
+
publicKey: string,
|
|
709
|
+
devMode: boolean = false,
|
|
710
|
+
mockMode: boolean = false,
|
|
711
|
+
standardUrl?: string
|
|
712
|
+
): void {
|
|
713
|
+
const properties = {
|
|
714
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
715
|
+
source,
|
|
716
|
+
url,
|
|
717
|
+
};
|
|
718
|
+
trackEvent("Standard Checkout Window Open", properties, devMode).catch((error) => {
|
|
719
|
+
if (devMode) {
|
|
720
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard window open:", error);
|
|
721
|
+
}
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Tracks when window.close is intercepted from the standard checkout WebView
|
|
727
|
+
*/
|
|
728
|
+
export function trackStandardWindowClose(
|
|
729
|
+
source: "main" | "flow",
|
|
730
|
+
orderId: string,
|
|
731
|
+
publicKey: string,
|
|
732
|
+
devMode: boolean = false,
|
|
733
|
+
mockMode: boolean = false,
|
|
734
|
+
standardUrl?: string
|
|
735
|
+
): void {
|
|
736
|
+
const properties = {
|
|
737
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
738
|
+
source,
|
|
739
|
+
};
|
|
740
|
+
trackEvent("Standard Checkout Window Close", properties, devMode).catch((error) => {
|
|
741
|
+
if (devMode) {
|
|
742
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard window close:", error);
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Tracks when invalid message data is received from a standard checkout WebView
|
|
749
|
+
*/
|
|
750
|
+
export function trackStandardInvalidMessageReceived(
|
|
751
|
+
webviewType: "main" | "flow",
|
|
752
|
+
data: unknown,
|
|
753
|
+
url: string | undefined,
|
|
754
|
+
orderId: string,
|
|
755
|
+
publicKey: string,
|
|
756
|
+
devMode: boolean = false,
|
|
757
|
+
mockMode: boolean = false,
|
|
758
|
+
standardUrl?: string
|
|
759
|
+
): void {
|
|
760
|
+
let dataString: string;
|
|
761
|
+
try {
|
|
762
|
+
if (data === null) {
|
|
763
|
+
dataString = "null";
|
|
764
|
+
} else if (data === undefined) {
|
|
765
|
+
dataString = "undefined";
|
|
766
|
+
} else if (typeof data === "string") {
|
|
767
|
+
dataString = data;
|
|
768
|
+
} else if (typeof data === "object") {
|
|
769
|
+
dataString = JSON.stringify(data);
|
|
578
770
|
} else {
|
|
579
|
-
|
|
771
|
+
dataString = String(data);
|
|
580
772
|
}
|
|
773
|
+
} catch {
|
|
774
|
+
dataString = "[unable to stringify]";
|
|
581
775
|
}
|
|
582
776
|
|
|
583
|
-
|
|
777
|
+
const properties = {
|
|
778
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
779
|
+
webviewType,
|
|
780
|
+
data: dataString,
|
|
781
|
+
dataType: data === null ? "null" : typeof data,
|
|
782
|
+
...(url && { url }),
|
|
783
|
+
};
|
|
784
|
+
trackEvent("Standard Checkout Invalid Message Received", properties, devMode).catch((error) => {
|
|
785
|
+
if (devMode) {
|
|
786
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard invalid message:", error);
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Tracks when standard checkout onPaymentSuccess callback is invoked
|
|
793
|
+
*/
|
|
794
|
+
export function trackStandardPaymentSuccess(
|
|
795
|
+
orderId: string,
|
|
796
|
+
paymentId: string,
|
|
797
|
+
publicKey: string,
|
|
798
|
+
devMode: boolean = false,
|
|
799
|
+
mockMode: boolean = false,
|
|
800
|
+
standardUrl?: string
|
|
801
|
+
): void {
|
|
802
|
+
const properties = {
|
|
803
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
804
|
+
paymentId,
|
|
805
|
+
};
|
|
806
|
+
trackEvent("Standard Payment Success", properties, devMode).catch((error) => {
|
|
807
|
+
if (devMode) {
|
|
808
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard payment success:", error);
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* Tracks when standard checkout onPaymentFailure callback is invoked
|
|
815
|
+
*/
|
|
816
|
+
export function trackStandardPaymentFailure(
|
|
817
|
+
orderId: string,
|
|
818
|
+
paymentId: string,
|
|
819
|
+
publicKey: string,
|
|
820
|
+
devMode: boolean = false,
|
|
821
|
+
mockMode: boolean = false,
|
|
822
|
+
standardUrl?: string
|
|
823
|
+
): void {
|
|
824
|
+
const properties = {
|
|
825
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
826
|
+
paymentId,
|
|
827
|
+
};
|
|
828
|
+
trackEvent("Standard Payment Failure", properties, devMode).catch((error) => {
|
|
829
|
+
if (devMode) {
|
|
830
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard payment failure:", error);
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Tracks when standard checkout onPaymentTerminate callback is invoked
|
|
837
|
+
*/
|
|
838
|
+
export function trackStandardPaymentTerminate(
|
|
839
|
+
orderId: string,
|
|
840
|
+
source: "user_dismiss" | "back_button" | "checkout_closed",
|
|
841
|
+
publicKey: string,
|
|
842
|
+
devMode: boolean = false,
|
|
843
|
+
mockMode: boolean = false,
|
|
844
|
+
standardUrl?: string
|
|
845
|
+
): void {
|
|
846
|
+
const properties = {
|
|
847
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
848
|
+
terminationSource: source,
|
|
849
|
+
};
|
|
850
|
+
trackEvent("Standard Payment Terminated", properties, devMode).catch((error) => {
|
|
851
|
+
if (devMode) {
|
|
852
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard payment terminate:", error);
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Tracks when standard checkout onConnectionError callback is invoked
|
|
859
|
+
*/
|
|
860
|
+
export function trackStandardConnectionError(
|
|
861
|
+
orderId: string,
|
|
862
|
+
errorCode: number | undefined,
|
|
863
|
+
publicKey: string,
|
|
864
|
+
devMode: boolean = false,
|
|
865
|
+
mockMode: boolean = false,
|
|
866
|
+
standardUrl?: string
|
|
867
|
+
): void {
|
|
868
|
+
const properties = {
|
|
869
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
870
|
+
...(errorCode !== undefined && { errorCode }),
|
|
871
|
+
};
|
|
872
|
+
trackEvent("Standard Connection Error", properties, devMode).catch((error) => {
|
|
873
|
+
if (devMode) {
|
|
874
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard connection error:", error);
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Tracks when standard checkout onSdkError callback is invoked
|
|
881
|
+
*/
|
|
882
|
+
export function trackStandardSdkError(
|
|
883
|
+
errors: Array<SdkError>,
|
|
884
|
+
orderId?: string,
|
|
885
|
+
publicKey?: string,
|
|
886
|
+
devMode: boolean = false,
|
|
887
|
+
mockMode: boolean = false,
|
|
888
|
+
standardUrl?: string
|
|
889
|
+
): void {
|
|
890
|
+
const properties = {
|
|
891
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
892
|
+
errors,
|
|
893
|
+
errorCount: errors.length,
|
|
894
|
+
};
|
|
895
|
+
trackEvent("Standard SDK Error", properties, devMode).catch((error) => {
|
|
896
|
+
if (devMode) {
|
|
897
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard SDK error:", error);
|
|
898
|
+
}
|
|
899
|
+
});
|
|
584
900
|
}
|
|
901
|
+
|
|
902
|
+
export function trackStandardBankTransferSubmitted(
|
|
903
|
+
orderId: string,
|
|
904
|
+
publicKey: string,
|
|
905
|
+
devMode: boolean = false,
|
|
906
|
+
mockMode: boolean = false,
|
|
907
|
+
standardUrl?: string
|
|
908
|
+
): void {
|
|
909
|
+
const properties = {
|
|
910
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
911
|
+
};
|
|
912
|
+
trackEvent("Standard Bank Transfer Submitted", properties, devMode).catch((error) => {
|
|
913
|
+
if (devMode) {
|
|
914
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard bank transfer submitted:", error);
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
export function trackStandardPayViaBankCompleted(
|
|
920
|
+
orderId: string,
|
|
921
|
+
publicKey: string,
|
|
922
|
+
status: string,
|
|
923
|
+
devMode: boolean = false,
|
|
924
|
+
mockMode: boolean = false,
|
|
925
|
+
standardUrl?: string
|
|
926
|
+
): void {
|
|
927
|
+
const properties = {
|
|
928
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
929
|
+
payViaBankStatus: status,
|
|
930
|
+
};
|
|
931
|
+
trackEvent("Standard Pay Via Bank Completed", properties, devMode).catch((error) => {
|
|
932
|
+
if (devMode) {
|
|
933
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard pay via bank completed:", error);
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
export function trackStandardPayViaBankBankConnectionSuccessful(
|
|
939
|
+
orderId: string,
|
|
940
|
+
publicKey: string,
|
|
941
|
+
bankIdentifier: string,
|
|
942
|
+
devMode: boolean = false,
|
|
943
|
+
mockMode: boolean = false,
|
|
944
|
+
standardUrl?: string
|
|
945
|
+
): void {
|
|
946
|
+
const properties = {
|
|
947
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, standardUrl, "standard"),
|
|
948
|
+
bankIdentifier,
|
|
949
|
+
};
|
|
950
|
+
trackEvent("Standard Pay Via Bank Bank Connection Successful", properties, devMode).catch((error) => {
|
|
951
|
+
if (devMode) {
|
|
952
|
+
console.error("[Glomo-RN-SDK] Event tracking error on standard pay via bank connection:", error);
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// ---------------------------------------------------------------------------
|
|
958
|
+
// Order Type Detection Trackers (Unified Flow)
|
|
959
|
+
// ---------------------------------------------------------------------------
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* Tracks when order type detection starts
|
|
963
|
+
*
|
|
964
|
+
* @param orderId - The order ID
|
|
965
|
+
* @param publicKey - The public key of the merchant
|
|
966
|
+
* @param devMode - Whether dev mode is enabled
|
|
967
|
+
*/
|
|
968
|
+
export function trackOrderTypeDetectionStarted(orderId: string, publicKey: string, devMode: boolean = false): void {
|
|
969
|
+
const properties = {
|
|
970
|
+
...buildCommonProperties(orderId, publicKey, devMode, false, undefined, "unified"),
|
|
971
|
+
};
|
|
972
|
+
trackEvent("Order Type Detection Started", properties, devMode).catch((error) => {
|
|
973
|
+
if (devMode) {
|
|
974
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on order type detection started:`, error);
|
|
975
|
+
}
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* Tracks when order type detection resolves successfully
|
|
981
|
+
*
|
|
982
|
+
* @param orderId - The order ID
|
|
983
|
+
* @param publicKey - The public key of the merchant
|
|
984
|
+
* @param resolvedType - The resolved order type ("lrs" or "standard")
|
|
985
|
+
* @param devMode - Whether dev mode is enabled
|
|
986
|
+
*/
|
|
987
|
+
export function trackOrderTypeDetectionResolved(
|
|
988
|
+
orderId: string,
|
|
989
|
+
publicKey: string,
|
|
990
|
+
resolvedType: "lrs" | "standard",
|
|
991
|
+
devMode: boolean = false
|
|
992
|
+
): void {
|
|
993
|
+
const eventName = resolvedType === "lrs" ? "Order Type Resolved LRS" : "Order Type Resolved Standard";
|
|
994
|
+
const properties = {
|
|
995
|
+
...buildCommonProperties(orderId, publicKey, devMode, false, undefined, "unified"),
|
|
996
|
+
};
|
|
997
|
+
trackEvent(eventName, properties, devMode).catch((error) => {
|
|
998
|
+
if (devMode) {
|
|
999
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on order type detection resolved:`, error);
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* Tracks when order type detection fails
|
|
1006
|
+
*
|
|
1007
|
+
* @param orderId - The order ID
|
|
1008
|
+
* @param publicKey - The public key of the merchant
|
|
1009
|
+
* @param error - The error message
|
|
1010
|
+
* @param devMode - Whether dev mode is enabled
|
|
1011
|
+
*/
|
|
1012
|
+
export function trackOrderTypeDetectionFailed(
|
|
1013
|
+
orderId: string,
|
|
1014
|
+
publicKey: string,
|
|
1015
|
+
error: string,
|
|
1016
|
+
devMode: boolean = false
|
|
1017
|
+
): void {
|
|
1018
|
+
const properties = {
|
|
1019
|
+
...buildCommonProperties(orderId, publicKey, devMode, false, undefined, "unified"),
|
|
1020
|
+
error,
|
|
1021
|
+
};
|
|
1022
|
+
trackEvent("Order Type Detection Failed", properties, devMode).catch((trackError) => {
|
|
1023
|
+
if (devMode) {
|
|
1024
|
+
console.error(`[Glomo-RN-SDK] Event tracking error on order type detection failed:`, trackError);
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* Helper to check if analytics is enabled and log accordingly
|
|
1031
|
+
* To be used for debugging merchant integration issues
|
|
1032
|
+
*
|
|
1033
|
+
* @param devMode - Console logs will be enabled for dev mode
|
|
1034
|
+
* @returns true if GlomoPay Segment is available, false otherwise
|
|
1035
|
+
*/
|
|
1036
|
+
export function checkAnalyticsStatus(devMode: boolean = false): boolean {
|
|
1037
|
+
const available = isSegmentAvailable();
|
|
1038
|
+
|
|
1039
|
+
if (devMode) {
|
|
1040
|
+
if (available) {
|
|
1041
|
+
console.log("[Glomo-RN-SDK] Analytics: ENABLED");
|
|
1042
|
+
} else {
|
|
1043
|
+
console.log("[Glomo-RN-SDK] Analytics: DISABLED");
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
return available;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
// ---------------------------------------------------------------------------
|
|
1051
|
+
// Subscription Checkout Trackers
|
|
1052
|
+
// ---------------------------------------------------------------------------
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* Tracks when the subscription checkout start() method is called (attempted)
|
|
1056
|
+
*/
|
|
1057
|
+
export function trackSubscriptionStartAttempt(
|
|
1058
|
+
status: string,
|
|
1059
|
+
orderId: string,
|
|
1060
|
+
publicKey: string,
|
|
1061
|
+
devMode: boolean = false,
|
|
1062
|
+
mockMode: boolean = false,
|
|
1063
|
+
checkoutUrl?: string,
|
|
1064
|
+
jailbreakDetectionInfo?: {
|
|
1065
|
+
jailbreakDetectionLibraryInstalled: boolean;
|
|
1066
|
+
jailbreakDetected: boolean | null;
|
|
1067
|
+
}
|
|
1068
|
+
): void {
|
|
1069
|
+
const properties = {
|
|
1070
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, checkoutUrl, "subscriptions"),
|
|
1071
|
+
subscriptionId: orderId,
|
|
1072
|
+
status,
|
|
1073
|
+
...(jailbreakDetectionInfo && {
|
|
1074
|
+
jailbreakDetectionLibraryInstalled: jailbreakDetectionInfo.jailbreakDetectionLibraryInstalled,
|
|
1075
|
+
jailbreakDetected: jailbreakDetectionInfo.jailbreakDetected,
|
|
1076
|
+
}),
|
|
1077
|
+
};
|
|
1078
|
+
trackEvent("Subscription Checkout Start Attempted", properties, devMode).catch((error) => {
|
|
1079
|
+
if (devMode) {
|
|
1080
|
+
console.error("[Glomo-RN-SDK] Event tracking error on subscription start attempt:", error);
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
/**
|
|
1086
|
+
* Tracks when the subscription checkout start() method has been called successfully
|
|
1087
|
+
*/
|
|
1088
|
+
export function trackSubscriptionStartSuccess(
|
|
1089
|
+
orderId: string,
|
|
1090
|
+
publicKey: string,
|
|
1091
|
+
devMode: boolean = false,
|
|
1092
|
+
mockMode: boolean = false,
|
|
1093
|
+
checkoutUrl?: string,
|
|
1094
|
+
jailbreakDetectionInfo?: {
|
|
1095
|
+
jailbreakDetectionLibraryInstalled: boolean;
|
|
1096
|
+
jailbreakDetected: boolean | null;
|
|
1097
|
+
}
|
|
1098
|
+
): void {
|
|
1099
|
+
const properties = {
|
|
1100
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, checkoutUrl, "subscriptions"),
|
|
1101
|
+
subscriptionId: orderId,
|
|
1102
|
+
...(jailbreakDetectionInfo && {
|
|
1103
|
+
jailbreakDetectionLibraryInstalled: jailbreakDetectionInfo.jailbreakDetectionLibraryInstalled,
|
|
1104
|
+
jailbreakDetected: jailbreakDetectionInfo.jailbreakDetected,
|
|
1105
|
+
}),
|
|
1106
|
+
};
|
|
1107
|
+
trackEvent("Subscription Checkout Started", properties, devMode).catch((error) => {
|
|
1108
|
+
if (devMode) {
|
|
1109
|
+
console.error("[Glomo-RN-SDK] Event tracking error on subscription start:", error);
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* Tracks when the subscription checkout start() method fails
|
|
1116
|
+
*/
|
|
1117
|
+
export function trackSubscriptionStartFailure(
|
|
1118
|
+
reason: "device_forbidden" | "validation_error" | "payment_successful" | "invalid_status" | "invalid_url",
|
|
1119
|
+
orderId?: string,
|
|
1120
|
+
publicKey?: string,
|
|
1121
|
+
devMode: boolean = false,
|
|
1122
|
+
mockMode: boolean = false,
|
|
1123
|
+
checkoutUrl?: string,
|
|
1124
|
+
jailbreakDetectionInfo?: {
|
|
1125
|
+
jailbreakDetectionLibraryInstalled: boolean;
|
|
1126
|
+
jailbreakDetected: boolean | null;
|
|
1127
|
+
}
|
|
1128
|
+
): void {
|
|
1129
|
+
const properties = {
|
|
1130
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, checkoutUrl, "subscriptions"),
|
|
1131
|
+
subscriptionId: orderId,
|
|
1132
|
+
failureReason: reason,
|
|
1133
|
+
...(jailbreakDetectionInfo && {
|
|
1134
|
+
jailbreakDetectionLibraryInstalled: jailbreakDetectionInfo.jailbreakDetectionLibraryInstalled,
|
|
1135
|
+
jailbreakDetected: jailbreakDetectionInfo.jailbreakDetected,
|
|
1136
|
+
}),
|
|
1137
|
+
};
|
|
1138
|
+
trackEvent("Subscription Checkout Start Failed", properties, devMode).catch((error) => {
|
|
1139
|
+
if (devMode) {
|
|
1140
|
+
console.error("[Glomo-RN-SDK] Event tracking error on subscription start failure:", error);
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* Tracks when window.open is intercepted from the subscription checkout WebView
|
|
1147
|
+
*/
|
|
1148
|
+
export function trackSubscriptionWindowOpen(
|
|
1149
|
+
source: "main" | "flow",
|
|
1150
|
+
url: string,
|
|
1151
|
+
orderId: string,
|
|
1152
|
+
publicKey: string,
|
|
1153
|
+
devMode: boolean = false,
|
|
1154
|
+
mockMode: boolean = false,
|
|
1155
|
+
checkoutUrl?: string
|
|
1156
|
+
): void {
|
|
1157
|
+
const properties = {
|
|
1158
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, checkoutUrl, "subscriptions"),
|
|
1159
|
+
subscriptionId: orderId,
|
|
1160
|
+
source,
|
|
1161
|
+
url,
|
|
1162
|
+
};
|
|
1163
|
+
trackEvent("Subscription Checkout Window Open", properties, devMode).catch((error) => {
|
|
1164
|
+
if (devMode) {
|
|
1165
|
+
console.error("[Glomo-RN-SDK] Event tracking error on subscription window open:", error);
|
|
1166
|
+
}
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
/**
|
|
1171
|
+
* Tracks when window.close is intercepted from the subscription checkout WebView
|
|
1172
|
+
*/
|
|
1173
|
+
export function trackSubscriptionWindowClose(
|
|
1174
|
+
source: "main" | "flow",
|
|
1175
|
+
orderId: string,
|
|
1176
|
+
publicKey: string,
|
|
1177
|
+
devMode: boolean = false,
|
|
1178
|
+
mockMode: boolean = false,
|
|
1179
|
+
checkoutUrl?: string
|
|
1180
|
+
): void {
|
|
1181
|
+
const properties = {
|
|
1182
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, checkoutUrl, "subscriptions"),
|
|
1183
|
+
subscriptionId: orderId,
|
|
1184
|
+
source,
|
|
1185
|
+
};
|
|
1186
|
+
trackEvent("Subscription Checkout Window Close", properties, devMode).catch((error) => {
|
|
1187
|
+
if (devMode) {
|
|
1188
|
+
console.error("[Glomo-RN-SDK] Event tracking error on subscription window close:", error);
|
|
1189
|
+
}
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/**
|
|
1194
|
+
* Tracks when invalid message data is received from a subscription checkout WebView
|
|
1195
|
+
*/
|
|
1196
|
+
export function trackSubscriptionInvalidMessageReceived(
|
|
1197
|
+
webviewType: "main" | "flow",
|
|
1198
|
+
data: unknown,
|
|
1199
|
+
url: string | undefined,
|
|
1200
|
+
orderId: string,
|
|
1201
|
+
publicKey: string,
|
|
1202
|
+
devMode: boolean = false,
|
|
1203
|
+
mockMode: boolean = false,
|
|
1204
|
+
checkoutUrl?: string
|
|
1205
|
+
): void {
|
|
1206
|
+
let dataString: string;
|
|
1207
|
+
try {
|
|
1208
|
+
if (data === null) {
|
|
1209
|
+
dataString = "null";
|
|
1210
|
+
} else if (data === undefined) {
|
|
1211
|
+
dataString = "undefined";
|
|
1212
|
+
} else if (typeof data === "string") {
|
|
1213
|
+
dataString = data;
|
|
1214
|
+
} else if (typeof data === "object") {
|
|
1215
|
+
dataString = JSON.stringify(data);
|
|
1216
|
+
} else {
|
|
1217
|
+
dataString = String(data);
|
|
1218
|
+
}
|
|
1219
|
+
} catch {
|
|
1220
|
+
dataString = "[unable to stringify]";
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
const properties = {
|
|
1224
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, checkoutUrl, "subscriptions"),
|
|
1225
|
+
subscriptionId: orderId,
|
|
1226
|
+
webviewType,
|
|
1227
|
+
data: dataString,
|
|
1228
|
+
dataType: data === null ? "null" : typeof data,
|
|
1229
|
+
...(url && { url }),
|
|
1230
|
+
};
|
|
1231
|
+
trackEvent("Subscription Checkout Invalid Message Received", properties, devMode).catch((error) => {
|
|
1232
|
+
if (devMode) {
|
|
1233
|
+
console.error("[Glomo-RN-SDK] Event tracking error on subscription invalid message:", error);
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
/**
|
|
1239
|
+
* Tracks when subscription checkout onPaymentSuccess callback is invoked
|
|
1240
|
+
*/
|
|
1241
|
+
export function trackSubscriptionPaymentSuccess(
|
|
1242
|
+
orderId: string,
|
|
1243
|
+
paymentId: string,
|
|
1244
|
+
publicKey: string,
|
|
1245
|
+
devMode: boolean = false,
|
|
1246
|
+
mockMode: boolean = false,
|
|
1247
|
+
checkoutUrl?: string
|
|
1248
|
+
): void {
|
|
1249
|
+
const properties = {
|
|
1250
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, checkoutUrl, "subscriptions"),
|
|
1251
|
+
subscriptionId: orderId,
|
|
1252
|
+
paymentId,
|
|
1253
|
+
};
|
|
1254
|
+
trackEvent("Subscription Payment Success", properties, devMode).catch((error) => {
|
|
1255
|
+
if (devMode) {
|
|
1256
|
+
console.error("[Glomo-RN-SDK] Event tracking error on subscription payment success:", error);
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
/**
|
|
1262
|
+
* Tracks when subscription checkout onPaymentFailure callback is invoked
|
|
1263
|
+
*/
|
|
1264
|
+
export function trackSubscriptionPaymentFailure(
|
|
1265
|
+
orderId: string,
|
|
1266
|
+
paymentId: string,
|
|
1267
|
+
publicKey: string,
|
|
1268
|
+
devMode: boolean = false,
|
|
1269
|
+
mockMode: boolean = false,
|
|
1270
|
+
checkoutUrl?: string
|
|
1271
|
+
): void {
|
|
1272
|
+
const properties = {
|
|
1273
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, checkoutUrl, "subscriptions"),
|
|
1274
|
+
subscriptionId: orderId,
|
|
1275
|
+
paymentId,
|
|
1276
|
+
};
|
|
1277
|
+
trackEvent("Subscription Payment Failure", properties, devMode).catch((error) => {
|
|
1278
|
+
if (devMode) {
|
|
1279
|
+
console.error("[Glomo-RN-SDK] Event tracking error on subscription payment failure:", error);
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* Tracks when subscription checkout onPaymentTerminate callback is invoked
|
|
1286
|
+
*/
|
|
1287
|
+
export function trackSubscriptionPaymentTerminate(
|
|
1288
|
+
orderId: string,
|
|
1289
|
+
source: "user_dismiss" | "back_button" | "checkout_closed",
|
|
1290
|
+
publicKey: string,
|
|
1291
|
+
devMode: boolean = false,
|
|
1292
|
+
mockMode: boolean = false,
|
|
1293
|
+
checkoutUrl?: string
|
|
1294
|
+
): void {
|
|
1295
|
+
const properties = {
|
|
1296
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, checkoutUrl, "subscriptions"),
|
|
1297
|
+
subscriptionId: orderId,
|
|
1298
|
+
terminationSource: source,
|
|
1299
|
+
};
|
|
1300
|
+
trackEvent("Subscription Payment Terminated", properties, devMode).catch((error) => {
|
|
1301
|
+
if (devMode) {
|
|
1302
|
+
console.error("[Glomo-RN-SDK] Event tracking error on subscription payment terminate:", error);
|
|
1303
|
+
}
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
/**
|
|
1308
|
+
* Tracks when subscription checkout onConnectionError callback is invoked
|
|
1309
|
+
*/
|
|
1310
|
+
export function trackSubscriptionConnectionError(
|
|
1311
|
+
orderId: string,
|
|
1312
|
+
errorCode: number | undefined,
|
|
1313
|
+
publicKey: string,
|
|
1314
|
+
devMode: boolean = false,
|
|
1315
|
+
mockMode: boolean = false,
|
|
1316
|
+
checkoutUrl?: string
|
|
1317
|
+
): void {
|
|
1318
|
+
const properties = {
|
|
1319
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, checkoutUrl, "subscriptions"),
|
|
1320
|
+
subscriptionId: orderId,
|
|
1321
|
+
...(errorCode !== undefined && { errorCode }),
|
|
1322
|
+
};
|
|
1323
|
+
trackEvent("Subscription Connection Error", properties, devMode).catch((error) => {
|
|
1324
|
+
if (devMode) {
|
|
1325
|
+
console.error("[Glomo-RN-SDK] Event tracking error on subscription connection error:", error);
|
|
1326
|
+
}
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
/**
|
|
1331
|
+
* Tracks when subscription checkout onSdkError callback is invoked
|
|
1332
|
+
*/
|
|
1333
|
+
export function trackSubscriptionSdkError(
|
|
1334
|
+
errors: Array<SdkError>,
|
|
1335
|
+
orderId?: string,
|
|
1336
|
+
publicKey?: string,
|
|
1337
|
+
devMode: boolean = false,
|
|
1338
|
+
mockMode: boolean = false,
|
|
1339
|
+
checkoutUrl?: string
|
|
1340
|
+
): void {
|
|
1341
|
+
const properties = {
|
|
1342
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, checkoutUrl, "subscriptions"),
|
|
1343
|
+
subscriptionId: orderId,
|
|
1344
|
+
errors,
|
|
1345
|
+
errorCount: errors.length,
|
|
1346
|
+
};
|
|
1347
|
+
trackEvent("Subscription SDK Error", properties, devMode).catch((error) => {
|
|
1348
|
+
if (devMode) {
|
|
1349
|
+
console.error("[Glomo-RN-SDK] Event tracking error on subscription SDK error:", error);
|
|
1350
|
+
}
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
// ---------------------------------------------------------------------------
|
|
1355
|
+
// Unsupported Functionality Telemetry
|
|
1356
|
+
// ---------------------------------------------------------------------------
|
|
1357
|
+
|
|
1358
|
+
/**
|
|
1359
|
+
* Internal telemetry - fires when a merchant uses functionality that is
|
|
1360
|
+
* unsupported in the current context or deprecated.
|
|
1361
|
+
* Fires at most once per detection site (callers use a ref guard).
|
|
1362
|
+
*/
|
|
1363
|
+
export function trackUseOfUnsupportedFunctionality(
|
|
1364
|
+
name: string,
|
|
1365
|
+
orderId: string | undefined,
|
|
1366
|
+
publicKey: string,
|
|
1367
|
+
devMode: boolean,
|
|
1368
|
+
mockMode: boolean,
|
|
1369
|
+
checkoutUrl: string
|
|
1370
|
+
): void {
|
|
1371
|
+
const properties = {
|
|
1372
|
+
...buildCommonProperties(orderId, publicKey, devMode, mockMode, checkoutUrl),
|
|
1373
|
+
name,
|
|
1374
|
+
};
|
|
1375
|
+
trackEvent("Use of Unsupported Functionality", properties, devMode).catch((error) => {
|
|
1376
|
+
if (devMode) {
|
|
1377
|
+
console.error("[Glomo-RN-SDK] Event tracking error on unsupported functionality:", error);
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
// ---------------------------------------------------------------------------
|
|
1383
|
+
// Checkout Analytics Tracker Map
|
|
1384
|
+
// ---------------------------------------------------------------------------
|
|
1385
|
+
|
|
1386
|
+
/**
|
|
1387
|
+
* Internal tracker map interface.
|
|
1388
|
+
* Each flow (standard, subscription) provides its own implementation.
|
|
1389
|
+
* useStandardCheckout calls through this map at every analytics call site.
|
|
1390
|
+
* Not exported to merchants via index.ts.
|
|
1391
|
+
*/
|
|
1392
|
+
export interface CheckoutAnalyticsTrackers {
|
|
1393
|
+
trackStartAttempt: typeof trackStandardStartAttempt;
|
|
1394
|
+
trackStartSuccess: typeof trackStandardStartSuccess;
|
|
1395
|
+
trackStartFailure: typeof trackStandardStartFailure;
|
|
1396
|
+
trackWindowOpen: typeof trackStandardWindowOpen;
|
|
1397
|
+
trackWindowClose: typeof trackStandardWindowClose;
|
|
1398
|
+
trackInvalidMessageReceived: typeof trackStandardInvalidMessageReceived;
|
|
1399
|
+
trackPaymentSuccess: typeof trackStandardPaymentSuccess;
|
|
1400
|
+
trackPaymentFailure: typeof trackStandardPaymentFailure;
|
|
1401
|
+
trackPaymentTerminate: typeof trackStandardPaymentTerminate;
|
|
1402
|
+
trackConnectionError: typeof trackStandardConnectionError;
|
|
1403
|
+
trackSdkError: typeof trackStandardSdkError;
|
|
1404
|
+
trackBankTransferSubmitted: typeof trackStandardBankTransferSubmitted;
|
|
1405
|
+
trackPayViaBankCompleted: typeof trackStandardPayViaBankCompleted;
|
|
1406
|
+
trackPayViaBankBankConnectionSuccessful: typeof trackStandardPayViaBankBankConnectionSuccessful;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
/** Standard checkout tracker map - delegates to trackStandard* functions */
|
|
1410
|
+
export const standardCheckoutTrackers: CheckoutAnalyticsTrackers = {
|
|
1411
|
+
trackStartAttempt: trackStandardStartAttempt,
|
|
1412
|
+
trackStartSuccess: trackStandardStartSuccess,
|
|
1413
|
+
trackStartFailure: trackStandardStartFailure,
|
|
1414
|
+
trackWindowOpen: trackStandardWindowOpen,
|
|
1415
|
+
trackWindowClose: trackStandardWindowClose,
|
|
1416
|
+
trackInvalidMessageReceived: trackStandardInvalidMessageReceived,
|
|
1417
|
+
trackPaymentSuccess: trackStandardPaymentSuccess,
|
|
1418
|
+
trackPaymentFailure: trackStandardPaymentFailure,
|
|
1419
|
+
trackPaymentTerminate: trackStandardPaymentTerminate,
|
|
1420
|
+
trackConnectionError: trackStandardConnectionError,
|
|
1421
|
+
trackSdkError: trackStandardSdkError,
|
|
1422
|
+
trackBankTransferSubmitted: trackStandardBankTransferSubmitted,
|
|
1423
|
+
trackPayViaBankCompleted: trackStandardPayViaBankCompleted,
|
|
1424
|
+
trackPayViaBankBankConnectionSuccessful: trackStandardPayViaBankBankConnectionSuccessful,
|
|
1425
|
+
};
|
|
1426
|
+
|
|
1427
|
+
/** Subscription checkout tracker map - delegates to trackSubscription* functions, no-ops for bank transfer */
|
|
1428
|
+
export const subscriptionCheckoutTrackers: CheckoutAnalyticsTrackers = {
|
|
1429
|
+
trackStartAttempt: trackSubscriptionStartAttempt,
|
|
1430
|
+
trackStartSuccess: trackSubscriptionStartSuccess,
|
|
1431
|
+
trackStartFailure: trackSubscriptionStartFailure,
|
|
1432
|
+
trackWindowOpen: trackSubscriptionWindowOpen,
|
|
1433
|
+
trackWindowClose: trackSubscriptionWindowClose,
|
|
1434
|
+
trackInvalidMessageReceived: trackSubscriptionInvalidMessageReceived,
|
|
1435
|
+
trackPaymentSuccess: trackSubscriptionPaymentSuccess,
|
|
1436
|
+
trackPaymentFailure: trackSubscriptionPaymentFailure,
|
|
1437
|
+
trackPaymentTerminate: trackSubscriptionPaymentTerminate,
|
|
1438
|
+
trackConnectionError: trackSubscriptionConnectionError,
|
|
1439
|
+
trackSdkError: trackSubscriptionSdkError,
|
|
1440
|
+
trackBankTransferSubmitted: (...args) => {
|
|
1441
|
+
const devMode = args[2];
|
|
1442
|
+
if (devMode) {
|
|
1443
|
+
console.warn("[Glomo-RN-SDK] Unexpected bank transfer event in subscription flow");
|
|
1444
|
+
}
|
|
1445
|
+
},
|
|
1446
|
+
trackPayViaBankCompleted: (...args) => {
|
|
1447
|
+
const devMode = args[3];
|
|
1448
|
+
if (devMode) {
|
|
1449
|
+
console.warn("[Glomo-RN-SDK] Unexpected pay via bank completed event in subscription flow");
|
|
1450
|
+
}
|
|
1451
|
+
},
|
|
1452
|
+
trackPayViaBankBankConnectionSuccessful: (...args) => {
|
|
1453
|
+
const devMode = args[3];
|
|
1454
|
+
if (devMode) {
|
|
1455
|
+
console.warn("[Glomo-RN-SDK] Unexpected pay via bank connection event in subscription flow");
|
|
1456
|
+
}
|
|
1457
|
+
},
|
|
1458
|
+
};
|