@hifilabs/pixel 0.3.0 → 0.6.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/dist/browser.js +260 -9
- package/dist/browser.min.js +102 -1
- package/dist/index.js +367 -314
- package/dist/index.mjs +145 -92
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -69,7 +69,8 @@ __export(src_exports, {
|
|
|
69
69
|
useBalanceSearch: () => useBalanceSearch,
|
|
70
70
|
useBalanceSocial: () => useBalanceSocial,
|
|
71
71
|
useBalanceSubscription: () => useBalanceSubscription,
|
|
72
|
-
useGTMConsent: () => useGTMConsent
|
|
72
|
+
useGTMConsent: () => useGTMConsent,
|
|
73
|
+
usePageviewTracking: () => usePageviewTracking
|
|
73
74
|
});
|
|
74
75
|
module.exports = __toCommonJS(src_exports);
|
|
75
76
|
|
|
@@ -300,26 +301,42 @@ function BalanceProvider({
|
|
|
300
301
|
const track2 = (0, import_react4.useCallback)((event, properties) => {
|
|
301
302
|
if (typeof window === "undefined")
|
|
302
303
|
return;
|
|
303
|
-
|
|
304
|
-
|
|
304
|
+
if (window.balance?.track) {
|
|
305
|
+
window.balance.track(event, properties || {});
|
|
306
|
+
} else {
|
|
307
|
+
ensureGlobalStub();
|
|
308
|
+
window.balance("track", event, properties || {});
|
|
309
|
+
}
|
|
305
310
|
}, []);
|
|
306
311
|
const identify2 = (0, import_react4.useCallback)((email, traits) => {
|
|
307
312
|
if (typeof window === "undefined")
|
|
308
313
|
return;
|
|
309
|
-
|
|
310
|
-
|
|
314
|
+
if (window.balance?.identify) {
|
|
315
|
+
window.balance.identify(email, traits || {});
|
|
316
|
+
} else {
|
|
317
|
+
ensureGlobalStub();
|
|
318
|
+
window.balance("identify", email, traits || {});
|
|
319
|
+
}
|
|
311
320
|
}, []);
|
|
312
321
|
const page2 = (0, import_react4.useCallback)((options) => {
|
|
313
322
|
if (typeof window === "undefined")
|
|
314
323
|
return;
|
|
315
|
-
|
|
316
|
-
|
|
324
|
+
if (window.balance?.page) {
|
|
325
|
+
window.balance.page(options || {});
|
|
326
|
+
} else {
|
|
327
|
+
ensureGlobalStub();
|
|
328
|
+
window.balance("page", options || {});
|
|
329
|
+
}
|
|
317
330
|
}, []);
|
|
318
331
|
const purchase2 = (0, import_react4.useCallback)((amount, currency, properties) => {
|
|
319
332
|
if (typeof window === "undefined")
|
|
320
333
|
return;
|
|
321
|
-
|
|
322
|
-
|
|
334
|
+
if (window.balance?.purchase) {
|
|
335
|
+
window.balance.purchase(amount, currency || "USD", properties || {});
|
|
336
|
+
} else {
|
|
337
|
+
ensureGlobalStub();
|
|
338
|
+
window.balance("purchase", amount, currency || "USD", properties || {});
|
|
339
|
+
}
|
|
323
340
|
}, []);
|
|
324
341
|
const getSessionId2 = (0, import_react4.useCallback)(() => {
|
|
325
342
|
if (typeof window === "undefined")
|
|
@@ -339,8 +356,12 @@ function BalanceProvider({
|
|
|
339
356
|
const setConsent2 = (0, import_react4.useCallback)((preferences) => {
|
|
340
357
|
if (typeof window === "undefined")
|
|
341
358
|
return;
|
|
342
|
-
|
|
343
|
-
|
|
359
|
+
if (window.balance?.setConsent) {
|
|
360
|
+
window.balance.setConsent(preferences);
|
|
361
|
+
} else {
|
|
362
|
+
ensureGlobalStub();
|
|
363
|
+
window.balance("setConsent", preferences);
|
|
364
|
+
}
|
|
344
365
|
}, []);
|
|
345
366
|
const getConsent2 = (0, import_react4.useCallback)(() => {
|
|
346
367
|
if (typeof window === "undefined")
|
|
@@ -483,11 +504,40 @@ function useBalanceReady() {
|
|
|
483
504
|
return context.isReady;
|
|
484
505
|
}
|
|
485
506
|
|
|
486
|
-
// src/react/
|
|
507
|
+
// src/react/usePageviewTracking.ts
|
|
487
508
|
var import_react8 = require("react");
|
|
509
|
+
var import_navigation = require("next/navigation");
|
|
510
|
+
function usePageviewTracking(options) {
|
|
511
|
+
const { page: page2 } = useBalance();
|
|
512
|
+
const pathname = (0, import_navigation.usePathname)();
|
|
513
|
+
const isFirstRender = (0, import_react8.useRef)(true);
|
|
514
|
+
const previousPathRef = (0, import_react8.useRef)(null);
|
|
515
|
+
(0, import_react8.useEffect)(() => {
|
|
516
|
+
if (isFirstRender.current) {
|
|
517
|
+
isFirstRender.current = false;
|
|
518
|
+
previousPathRef.current = pathname;
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (pathname === previousPathRef.current) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
previousPathRef.current = pathname;
|
|
525
|
+
if (typeof window !== "undefined") {
|
|
526
|
+
const url = window.location.href;
|
|
527
|
+
const title = document.title;
|
|
528
|
+
if (options?.debug) {
|
|
529
|
+
console.log("[usePageviewTracking] Route change detected:", { url, title });
|
|
530
|
+
}
|
|
531
|
+
page2({ url, title });
|
|
532
|
+
}
|
|
533
|
+
}, [pathname, page2, options?.debug]);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// src/react/useBalanceEcommerce.ts
|
|
537
|
+
var import_react9 = require("react");
|
|
488
538
|
function useBalanceEcommerce() {
|
|
489
539
|
const { track: track2, purchase: purchase2 } = useBalance();
|
|
490
|
-
const formatProduct = (0,
|
|
540
|
+
const formatProduct = (0, import_react9.useCallback)((product, quantity) => ({
|
|
491
541
|
item_id: product.id,
|
|
492
542
|
item_name: product.name,
|
|
493
543
|
price: product.price,
|
|
@@ -496,66 +546,66 @@ function useBalanceEcommerce() {
|
|
|
496
546
|
item_brand: product.brand,
|
|
497
547
|
quantity: quantity ?? product.quantity ?? 1
|
|
498
548
|
}), []);
|
|
499
|
-
const formatProducts = (0,
|
|
549
|
+
const formatProducts = (0, import_react9.useCallback)(
|
|
500
550
|
(products) => products.map((p, index) => ({
|
|
501
551
|
...formatProduct(p),
|
|
502
552
|
index
|
|
503
553
|
})),
|
|
504
554
|
[formatProduct]
|
|
505
555
|
);
|
|
506
|
-
const calculateValue = (0,
|
|
556
|
+
const calculateValue = (0, import_react9.useCallback)(
|
|
507
557
|
(items) => items.reduce((sum, item) => sum + item.price * (item.quantity || 1), 0),
|
|
508
558
|
[]
|
|
509
559
|
);
|
|
510
|
-
const viewProduct = (0,
|
|
560
|
+
const viewProduct = (0, import_react9.useCallback)((product) => {
|
|
511
561
|
track2("view_item", {
|
|
512
562
|
currency: "USD",
|
|
513
563
|
value: product.price,
|
|
514
564
|
items: [formatProduct(product)]
|
|
515
565
|
});
|
|
516
566
|
}, [track2, formatProduct]);
|
|
517
|
-
const viewProductList = (0,
|
|
567
|
+
const viewProductList = (0, import_react9.useCallback)((listName, products) => {
|
|
518
568
|
track2("view_item_list", {
|
|
519
569
|
item_list_id: listName.toLowerCase().replace(/\s+/g, "_"),
|
|
520
570
|
item_list_name: listName,
|
|
521
571
|
items: formatProducts(products)
|
|
522
572
|
});
|
|
523
573
|
}, [track2, formatProducts]);
|
|
524
|
-
const selectProduct = (0,
|
|
574
|
+
const selectProduct = (0, import_react9.useCallback)((product, listName) => {
|
|
525
575
|
track2("select_item", {
|
|
526
576
|
item_list_name: listName,
|
|
527
577
|
items: [formatProduct(product)]
|
|
528
578
|
});
|
|
529
579
|
}, [track2, formatProduct]);
|
|
530
|
-
const addToCart = (0,
|
|
580
|
+
const addToCart = (0, import_react9.useCallback)((product, quantity = 1) => {
|
|
531
581
|
track2("add_to_cart", {
|
|
532
582
|
currency: "USD",
|
|
533
583
|
value: product.price * quantity,
|
|
534
584
|
items: [formatProduct(product, quantity)]
|
|
535
585
|
});
|
|
536
586
|
}, [track2, formatProduct]);
|
|
537
|
-
const removeFromCart = (0,
|
|
587
|
+
const removeFromCart = (0, import_react9.useCallback)((product, quantity = 1) => {
|
|
538
588
|
track2("remove_from_cart", {
|
|
539
589
|
currency: "USD",
|
|
540
590
|
value: product.price * quantity,
|
|
541
591
|
items: [formatProduct(product, quantity)]
|
|
542
592
|
});
|
|
543
593
|
}, [track2, formatProduct]);
|
|
544
|
-
const viewCart = (0,
|
|
594
|
+
const viewCart = (0, import_react9.useCallback)((items, cartTotal) => {
|
|
545
595
|
track2("view_cart", {
|
|
546
596
|
currency: "USD",
|
|
547
597
|
value: cartTotal,
|
|
548
598
|
items: formatProducts(items)
|
|
549
599
|
});
|
|
550
600
|
}, [track2, formatProducts]);
|
|
551
|
-
const beginCheckout = (0,
|
|
601
|
+
const beginCheckout = (0, import_react9.useCallback)((items, total, currency = "USD") => {
|
|
552
602
|
track2("begin_checkout", {
|
|
553
603
|
currency,
|
|
554
604
|
value: total,
|
|
555
605
|
items: formatProducts(items)
|
|
556
606
|
});
|
|
557
607
|
}, [track2, formatProducts]);
|
|
558
|
-
const addShippingInfo = (0,
|
|
608
|
+
const addShippingInfo = (0, import_react9.useCallback)((shippingTier, items) => {
|
|
559
609
|
track2("add_shipping_info", {
|
|
560
610
|
currency: "USD",
|
|
561
611
|
value: calculateValue(items),
|
|
@@ -563,7 +613,7 @@ function useBalanceEcommerce() {
|
|
|
563
613
|
items: formatProducts(items)
|
|
564
614
|
});
|
|
565
615
|
}, [track2, formatProducts, calculateValue]);
|
|
566
|
-
const addPaymentInfo = (0,
|
|
616
|
+
const addPaymentInfo = (0, import_react9.useCallback)((paymentType, items) => {
|
|
567
617
|
track2("add_payment_info", {
|
|
568
618
|
currency: "USD",
|
|
569
619
|
value: calculateValue(items),
|
|
@@ -571,7 +621,7 @@ function useBalanceEcommerce() {
|
|
|
571
621
|
items: formatProducts(items)
|
|
572
622
|
});
|
|
573
623
|
}, [track2, formatProducts, calculateValue]);
|
|
574
|
-
const completePurchase = (0,
|
|
624
|
+
const completePurchase = (0, import_react9.useCallback)((orderId, total, items, options = {}) => {
|
|
575
625
|
const { currency = "USD", tax, shipping, coupon } = options;
|
|
576
626
|
purchase2(total, currency, {
|
|
577
627
|
order_id: orderId,
|
|
@@ -581,7 +631,7 @@ function useBalanceEcommerce() {
|
|
|
581
631
|
items: formatProducts(items)
|
|
582
632
|
});
|
|
583
633
|
}, [purchase2, formatProducts]);
|
|
584
|
-
const refund = (0,
|
|
634
|
+
const refund = (0, import_react9.useCallback)((orderId, amount, items) => {
|
|
585
635
|
track2("refund", {
|
|
586
636
|
currency: "USD",
|
|
587
637
|
transaction_id: orderId,
|
|
@@ -609,15 +659,15 @@ function useBalanceEcommerce() {
|
|
|
609
659
|
}
|
|
610
660
|
|
|
611
661
|
// src/react/useBalanceMedia.ts
|
|
612
|
-
var
|
|
662
|
+
var import_react10 = require("react");
|
|
613
663
|
function useBalanceMedia() {
|
|
614
664
|
const { track: track2 } = useBalance();
|
|
615
|
-
const playStartRef = (0,
|
|
616
|
-
const totalListenTimeRef = (0,
|
|
617
|
-
const milestonesTrackedRef = (0,
|
|
618
|
-
const currentMediaIdRef = (0,
|
|
619
|
-
const isPlayingRef = (0,
|
|
620
|
-
const formatMedia = (0,
|
|
665
|
+
const playStartRef = (0, import_react10.useRef)(null);
|
|
666
|
+
const totalListenTimeRef = (0, import_react10.useRef)(0);
|
|
667
|
+
const milestonesTrackedRef = (0, import_react10.useRef)(/* @__PURE__ */ new Set());
|
|
668
|
+
const currentMediaIdRef = (0, import_react10.useRef)(null);
|
|
669
|
+
const isPlayingRef = (0, import_react10.useRef)(false);
|
|
670
|
+
const formatMedia = (0, import_react10.useCallback)((media) => ({
|
|
621
671
|
media_id: media.mediaId,
|
|
622
672
|
title: media.title,
|
|
623
673
|
duration: media.duration,
|
|
@@ -628,21 +678,21 @@ function useBalanceMedia() {
|
|
|
628
678
|
playlist: media.playlist,
|
|
629
679
|
playlist_position: media.playlistPosition
|
|
630
680
|
}), []);
|
|
631
|
-
const getListenDuration = (0,
|
|
681
|
+
const getListenDuration = (0, import_react10.useCallback)(() => {
|
|
632
682
|
let duration = totalListenTimeRef.current;
|
|
633
683
|
if (isPlayingRef.current && playStartRef.current) {
|
|
634
684
|
duration += (Date.now() - playStartRef.current) / 1e3;
|
|
635
685
|
}
|
|
636
686
|
return Math.round(duration * 100) / 100;
|
|
637
687
|
}, []);
|
|
638
|
-
const reset = (0,
|
|
688
|
+
const reset = (0, import_react10.useCallback)(() => {
|
|
639
689
|
playStartRef.current = null;
|
|
640
690
|
totalListenTimeRef.current = 0;
|
|
641
691
|
milestonesTrackedRef.current.clear();
|
|
642
692
|
currentMediaIdRef.current = null;
|
|
643
693
|
isPlayingRef.current = false;
|
|
644
694
|
}, []);
|
|
645
|
-
const play = (0,
|
|
695
|
+
const play = (0, import_react10.useCallback)((media) => {
|
|
646
696
|
if (currentMediaIdRef.current !== media.mediaId) {
|
|
647
697
|
reset();
|
|
648
698
|
currentMediaIdRef.current = media.mediaId;
|
|
@@ -654,7 +704,7 @@ function useBalanceMedia() {
|
|
|
654
704
|
session_listen_time: totalListenTimeRef.current
|
|
655
705
|
});
|
|
656
706
|
}, [track2, formatMedia, reset]);
|
|
657
|
-
const pause = (0,
|
|
707
|
+
const pause = (0, import_react10.useCallback)((media, currentTime) => {
|
|
658
708
|
if (playStartRef.current && isPlayingRef.current) {
|
|
659
709
|
totalListenTimeRef.current += (Date.now() - playStartRef.current) / 1e3;
|
|
660
710
|
}
|
|
@@ -668,7 +718,7 @@ function useBalanceMedia() {
|
|
|
668
718
|
session_listen_time: totalListenTimeRef.current
|
|
669
719
|
});
|
|
670
720
|
}, [track2, formatMedia]);
|
|
671
|
-
const complete = (0,
|
|
721
|
+
const complete = (0, import_react10.useCallback)((media) => {
|
|
672
722
|
if (playStartRef.current && isPlayingRef.current) {
|
|
673
723
|
totalListenTimeRef.current += (Date.now() - playStartRef.current) / 1e3;
|
|
674
724
|
}
|
|
@@ -679,7 +729,7 @@ function useBalanceMedia() {
|
|
|
679
729
|
});
|
|
680
730
|
reset();
|
|
681
731
|
}, [track2, formatMedia, reset]);
|
|
682
|
-
const seek = (0,
|
|
732
|
+
const seek = (0, import_react10.useCallback)((media, fromTime, toTime) => {
|
|
683
733
|
track2("media_seek", {
|
|
684
734
|
...formatMedia(media),
|
|
685
735
|
from_time: fromTime,
|
|
@@ -688,7 +738,7 @@ function useBalanceMedia() {
|
|
|
688
738
|
seek_direction: toTime > fromTime ? "forward" : "backward"
|
|
689
739
|
});
|
|
690
740
|
}, [track2, formatMedia]);
|
|
691
|
-
const trackProgress = (0,
|
|
741
|
+
const trackProgress = (0, import_react10.useCallback)((media, currentTime) => {
|
|
692
742
|
if (media.duration <= 0)
|
|
693
743
|
return;
|
|
694
744
|
const percentPlayed = currentTime / media.duration * 100;
|
|
@@ -705,28 +755,28 @@ function useBalanceMedia() {
|
|
|
705
755
|
}
|
|
706
756
|
});
|
|
707
757
|
}, [track2, formatMedia, getListenDuration]);
|
|
708
|
-
const buffer = (0,
|
|
758
|
+
const buffer = (0, import_react10.useCallback)((media, currentTime) => {
|
|
709
759
|
track2("media_buffer", {
|
|
710
760
|
...formatMedia(media),
|
|
711
761
|
current_time: currentTime,
|
|
712
762
|
percent_played: media.duration > 0 ? Math.round(currentTime / media.duration * 100) : 0
|
|
713
763
|
});
|
|
714
764
|
}, [track2, formatMedia]);
|
|
715
|
-
const qualityChange = (0,
|
|
765
|
+
const qualityChange = (0, import_react10.useCallback)((media, fromQuality, toQuality) => {
|
|
716
766
|
track2("media_quality_change", {
|
|
717
767
|
...formatMedia(media),
|
|
718
768
|
from_quality: fromQuality,
|
|
719
769
|
to_quality: toQuality
|
|
720
770
|
});
|
|
721
771
|
}, [track2, formatMedia]);
|
|
722
|
-
const volumeChange = (0,
|
|
772
|
+
const volumeChange = (0, import_react10.useCallback)((media, volume, muted) => {
|
|
723
773
|
track2("media_volume_change", {
|
|
724
774
|
...formatMedia(media),
|
|
725
775
|
volume: Math.round(volume * 100),
|
|
726
776
|
muted
|
|
727
777
|
});
|
|
728
778
|
}, [track2, formatMedia]);
|
|
729
|
-
const speedChange = (0,
|
|
779
|
+
const speedChange = (0, import_react10.useCallback)((media, speed) => {
|
|
730
780
|
track2("media_speed_change", {
|
|
731
781
|
...formatMedia(media),
|
|
732
782
|
playback_speed: speed
|
|
@@ -752,30 +802,30 @@ function useBalanceMedia() {
|
|
|
752
802
|
}
|
|
753
803
|
|
|
754
804
|
// src/react/useBalanceEngagement.ts
|
|
755
|
-
var
|
|
805
|
+
var import_react11 = require("react");
|
|
756
806
|
function useBalanceEngagement(contentId, contentTitle) {
|
|
757
807
|
const { track: track2 } = useBalance();
|
|
758
|
-
const scrollMilestonesRef = (0,
|
|
759
|
-
const pageLoadTimeRef = (0,
|
|
760
|
-
const isTrackingTimeRef = (0,
|
|
761
|
-
const timeIntervalsRef = (0,
|
|
762
|
-
const timeTrackedRef = (0,
|
|
763
|
-
const getBaseProps = (0,
|
|
808
|
+
const scrollMilestonesRef = (0, import_react11.useRef)(/* @__PURE__ */ new Set());
|
|
809
|
+
const pageLoadTimeRef = (0, import_react11.useRef)(null);
|
|
810
|
+
const isTrackingTimeRef = (0, import_react11.useRef)(false);
|
|
811
|
+
const timeIntervalsRef = (0, import_react11.useRef)([30, 60, 120, 300]);
|
|
812
|
+
const timeTrackedRef = (0, import_react11.useRef)(/* @__PURE__ */ new Set());
|
|
813
|
+
const getBaseProps = (0, import_react11.useCallback)(() => ({
|
|
764
814
|
content_id: contentId,
|
|
765
815
|
content_title: contentTitle
|
|
766
816
|
}), [contentId, contentTitle]);
|
|
767
|
-
const getTimeOnPage = (0,
|
|
817
|
+
const getTimeOnPage = (0, import_react11.useCallback)(() => {
|
|
768
818
|
if (!pageLoadTimeRef.current)
|
|
769
819
|
return 0;
|
|
770
820
|
return Math.round((Date.now() - pageLoadTimeRef.current) / 1e3);
|
|
771
821
|
}, []);
|
|
772
|
-
const reset = (0,
|
|
822
|
+
const reset = (0, import_react11.useCallback)(() => {
|
|
773
823
|
scrollMilestonesRef.current.clear();
|
|
774
824
|
pageLoadTimeRef.current = null;
|
|
775
825
|
isTrackingTimeRef.current = false;
|
|
776
826
|
timeTrackedRef.current.clear();
|
|
777
827
|
}, []);
|
|
778
|
-
const share = (0,
|
|
828
|
+
const share = (0, import_react11.useCallback)((platform, contentType) => {
|
|
779
829
|
track2("content_shared", {
|
|
780
830
|
...getBaseProps(),
|
|
781
831
|
platform,
|
|
@@ -783,34 +833,34 @@ function useBalanceEngagement(contentId, contentTitle) {
|
|
|
783
833
|
time_on_page: getTimeOnPage()
|
|
784
834
|
});
|
|
785
835
|
}, [track2, getBaseProps, getTimeOnPage]);
|
|
786
|
-
const like = (0,
|
|
836
|
+
const like = (0, import_react11.useCallback)((contentType) => {
|
|
787
837
|
track2("content_liked", {
|
|
788
838
|
...getBaseProps(),
|
|
789
839
|
content_type: contentType,
|
|
790
840
|
time_on_page: getTimeOnPage()
|
|
791
841
|
});
|
|
792
842
|
}, [track2, getBaseProps, getTimeOnPage]);
|
|
793
|
-
const unlike = (0,
|
|
843
|
+
const unlike = (0, import_react11.useCallback)((contentType) => {
|
|
794
844
|
track2("content_unliked", {
|
|
795
845
|
...getBaseProps(),
|
|
796
846
|
content_type: contentType
|
|
797
847
|
});
|
|
798
848
|
}, [track2, getBaseProps]);
|
|
799
|
-
const comment = (0,
|
|
849
|
+
const comment = (0, import_react11.useCallback)((commentLength) => {
|
|
800
850
|
track2("comment_added", {
|
|
801
851
|
...getBaseProps(),
|
|
802
852
|
comment_length: commentLength,
|
|
803
853
|
time_on_page: getTimeOnPage()
|
|
804
854
|
});
|
|
805
855
|
}, [track2, getBaseProps, getTimeOnPage]);
|
|
806
|
-
const save = (0,
|
|
856
|
+
const save = (0, import_react11.useCallback)((contentType) => {
|
|
807
857
|
track2("content_saved", {
|
|
808
858
|
...getBaseProps(),
|
|
809
859
|
content_type: contentType,
|
|
810
860
|
time_on_page: getTimeOnPage()
|
|
811
861
|
});
|
|
812
862
|
}, [track2, getBaseProps, getTimeOnPage]);
|
|
813
|
-
const trackScrollDepth = (0,
|
|
863
|
+
const trackScrollDepth = (0, import_react11.useCallback)((scrollPercent) => {
|
|
814
864
|
const milestones = [25, 50, 75, 100];
|
|
815
865
|
milestones.forEach((milestone) => {
|
|
816
866
|
if (scrollPercent >= milestone && !scrollMilestonesRef.current.has(milestone)) {
|
|
@@ -823,7 +873,7 @@ function useBalanceEngagement(contentId, contentTitle) {
|
|
|
823
873
|
}
|
|
824
874
|
});
|
|
825
875
|
}, [track2, getBaseProps, getTimeOnPage]);
|
|
826
|
-
const trackTimeOnPage = (0,
|
|
876
|
+
const trackTimeOnPage = (0, import_react11.useCallback)(() => {
|
|
827
877
|
if (isTrackingTimeRef.current)
|
|
828
878
|
return;
|
|
829
879
|
pageLoadTimeRef.current = Date.now();
|
|
@@ -847,7 +897,7 @@ function useBalanceEngagement(contentId, contentTitle) {
|
|
|
847
897
|
}, 5e3);
|
|
848
898
|
return () => clearInterval(intervalId);
|
|
849
899
|
}, [track2, getBaseProps, getTimeOnPage]);
|
|
850
|
-
const click = (0,
|
|
900
|
+
const click = (0, import_react11.useCallback)((elementType, elementId) => {
|
|
851
901
|
track2("content_click", {
|
|
852
902
|
...getBaseProps(),
|
|
853
903
|
element_type: elementType,
|
|
@@ -855,14 +905,14 @@ function useBalanceEngagement(contentId, contentTitle) {
|
|
|
855
905
|
time_on_page: getTimeOnPage()
|
|
856
906
|
});
|
|
857
907
|
}, [track2, getBaseProps, getTimeOnPage]);
|
|
858
|
-
const copy = (0,
|
|
908
|
+
const copy = (0, import_react11.useCallback)((textLength) => {
|
|
859
909
|
track2("content_copied", {
|
|
860
910
|
...getBaseProps(),
|
|
861
911
|
text_length: textLength,
|
|
862
912
|
time_on_page: getTimeOnPage()
|
|
863
913
|
});
|
|
864
914
|
}, [track2, getBaseProps, getTimeOnPage]);
|
|
865
|
-
const download = (0,
|
|
915
|
+
const download = (0, import_react11.useCallback)((fileName, fileType) => {
|
|
866
916
|
track2("content_downloaded", {
|
|
867
917
|
...getBaseProps(),
|
|
868
918
|
file_name: fileName,
|
|
@@ -870,14 +920,14 @@ function useBalanceEngagement(contentId, contentTitle) {
|
|
|
870
920
|
time_on_page: getTimeOnPage()
|
|
871
921
|
});
|
|
872
922
|
}, [track2, getBaseProps, getTimeOnPage]);
|
|
873
|
-
const expand = (0,
|
|
923
|
+
const expand = (0, import_react11.useCallback)((sectionName) => {
|
|
874
924
|
track2("content_expanded", {
|
|
875
925
|
...getBaseProps(),
|
|
876
926
|
section_name: sectionName,
|
|
877
927
|
time_on_page: getTimeOnPage()
|
|
878
928
|
});
|
|
879
929
|
}, [track2, getBaseProps, getTimeOnPage]);
|
|
880
|
-
(0,
|
|
930
|
+
(0, import_react11.useEffect)(() => {
|
|
881
931
|
return () => {
|
|
882
932
|
if (isTrackingTimeRef.current && pageLoadTimeRef.current) {
|
|
883
933
|
const finalTime = getTimeOnPage();
|
|
@@ -915,34 +965,34 @@ function useBalanceEngagement(contentId, contentTitle) {
|
|
|
915
965
|
}
|
|
916
966
|
|
|
917
967
|
// src/react/useBalanceForm.ts
|
|
918
|
-
var
|
|
968
|
+
var import_react12 = require("react");
|
|
919
969
|
function useBalanceForm(formId, formName) {
|
|
920
970
|
const { track: track2, identify: identify2 } = useBalance();
|
|
921
|
-
const startTimeRef = (0,
|
|
922
|
-
const fieldsRef = (0,
|
|
923
|
-
const wasSubmittedRef = (0,
|
|
924
|
-
const hasStartedRef = (0,
|
|
925
|
-
const currentStepRef = (0,
|
|
926
|
-
const errorCountRef = (0,
|
|
927
|
-
const getBaseProps = (0,
|
|
971
|
+
const startTimeRef = (0, import_react12.useRef)(null);
|
|
972
|
+
const fieldsRef = (0, import_react12.useRef)(/* @__PURE__ */ new Map());
|
|
973
|
+
const wasSubmittedRef = (0, import_react12.useRef)(false);
|
|
974
|
+
const hasStartedRef = (0, import_react12.useRef)(false);
|
|
975
|
+
const currentStepRef = (0, import_react12.useRef)(1);
|
|
976
|
+
const errorCountRef = (0, import_react12.useRef)(0);
|
|
977
|
+
const getBaseProps = (0, import_react12.useCallback)(() => ({
|
|
928
978
|
form_id: formId,
|
|
929
979
|
form_name: formName
|
|
930
980
|
}), [formId, formName]);
|
|
931
|
-
const getFormDuration = (0,
|
|
981
|
+
const getFormDuration = (0, import_react12.useCallback)(() => {
|
|
932
982
|
if (!startTimeRef.current)
|
|
933
983
|
return 0;
|
|
934
984
|
return Math.round((Date.now() - startTimeRef.current) / 1e3);
|
|
935
985
|
}, []);
|
|
936
|
-
const getFieldsCompleted = (0,
|
|
986
|
+
const getFieldsCompleted = (0, import_react12.useCallback)(() => {
|
|
937
987
|
return Array.from(fieldsRef.current.values()).filter((f) => f.completed).length;
|
|
938
988
|
}, []);
|
|
939
|
-
const hasStarted = (0,
|
|
989
|
+
const hasStarted = (0, import_react12.useCallback)(() => {
|
|
940
990
|
return hasStartedRef.current;
|
|
941
991
|
}, []);
|
|
942
|
-
const wasSubmitted = (0,
|
|
992
|
+
const wasSubmitted = (0, import_react12.useCallback)(() => {
|
|
943
993
|
return wasSubmittedRef.current;
|
|
944
994
|
}, []);
|
|
945
|
-
const reset = (0,
|
|
995
|
+
const reset = (0, import_react12.useCallback)(() => {
|
|
946
996
|
startTimeRef.current = null;
|
|
947
997
|
fieldsRef.current.clear();
|
|
948
998
|
wasSubmittedRef.current = false;
|
|
@@ -950,7 +1000,7 @@ function useBalanceForm(formId, formName) {
|
|
|
950
1000
|
currentStepRef.current = 1;
|
|
951
1001
|
errorCountRef.current = 0;
|
|
952
1002
|
}, []);
|
|
953
|
-
const formStart = (0,
|
|
1003
|
+
const formStart = (0, import_react12.useCallback)(() => {
|
|
954
1004
|
if (hasStartedRef.current)
|
|
955
1005
|
return;
|
|
956
1006
|
startTimeRef.current = Date.now();
|
|
@@ -959,7 +1009,7 @@ function useBalanceForm(formId, formName) {
|
|
|
959
1009
|
...getBaseProps()
|
|
960
1010
|
});
|
|
961
1011
|
}, [track2, getBaseProps]);
|
|
962
|
-
const formSubmit = (0,
|
|
1012
|
+
const formSubmit = (0, import_react12.useCallback)((email, additionalData) => {
|
|
963
1013
|
wasSubmittedRef.current = true;
|
|
964
1014
|
const duration = getFormDuration();
|
|
965
1015
|
const fieldsCompleted = getFieldsCompleted();
|
|
@@ -981,7 +1031,7 @@ function useBalanceForm(formId, formName) {
|
|
|
981
1031
|
...additionalData
|
|
982
1032
|
});
|
|
983
1033
|
}, [track2, identify2, getBaseProps, getFormDuration, getFieldsCompleted, formId, formName]);
|
|
984
|
-
const formAbandoned = (0,
|
|
1034
|
+
const formAbandoned = (0, import_react12.useCallback)((reason) => {
|
|
985
1035
|
if (!hasStartedRef.current || wasSubmittedRef.current)
|
|
986
1036
|
return;
|
|
987
1037
|
const duration = getFormDuration();
|
|
@@ -1007,7 +1057,7 @@ function useBalanceForm(formId, formName) {
|
|
|
1007
1057
|
reason
|
|
1008
1058
|
});
|
|
1009
1059
|
}, [track2, getBaseProps, getFormDuration, getFieldsCompleted]);
|
|
1010
|
-
const fieldFocus = (0,
|
|
1060
|
+
const fieldFocus = (0, import_react12.useCallback)((fieldName, fieldType) => {
|
|
1011
1061
|
if (!hasStartedRef.current) {
|
|
1012
1062
|
formStart();
|
|
1013
1063
|
}
|
|
@@ -1031,7 +1081,7 @@ function useBalanceForm(formId, formName) {
|
|
|
1031
1081
|
existing.focusTime = Date.now();
|
|
1032
1082
|
}
|
|
1033
1083
|
}, [track2, getBaseProps, getFormDuration, formStart]);
|
|
1034
|
-
const fieldBlur = (0,
|
|
1084
|
+
const fieldBlur = (0, import_react12.useCallback)((fieldName, fieldType, hasValue) => {
|
|
1035
1085
|
const field = fieldsRef.current.get(fieldName);
|
|
1036
1086
|
if (field) {
|
|
1037
1087
|
field.blurTime = Date.now();
|
|
@@ -1046,7 +1096,7 @@ function useBalanceForm(formId, formName) {
|
|
|
1046
1096
|
});
|
|
1047
1097
|
}
|
|
1048
1098
|
}, [track2, getBaseProps]);
|
|
1049
|
-
const fieldError = (0,
|
|
1099
|
+
const fieldError = (0, import_react12.useCallback)((fieldName, errorMessage) => {
|
|
1050
1100
|
errorCountRef.current += 1;
|
|
1051
1101
|
const field = fieldsRef.current.get(fieldName);
|
|
1052
1102
|
if (field) {
|
|
@@ -1059,7 +1109,7 @@ function useBalanceForm(formId, formName) {
|
|
|
1059
1109
|
total_errors: errorCountRef.current
|
|
1060
1110
|
});
|
|
1061
1111
|
}, [track2, getBaseProps]);
|
|
1062
|
-
const stepChange = (0,
|
|
1112
|
+
const stepChange = (0, import_react12.useCallback)((fromStep, toStep, stepName) => {
|
|
1063
1113
|
currentStepRef.current = toStep;
|
|
1064
1114
|
track2("form_step_change", {
|
|
1065
1115
|
...getBaseProps(),
|
|
@@ -1092,32 +1142,32 @@ function useBalanceForm(formId, formName) {
|
|
|
1092
1142
|
}
|
|
1093
1143
|
|
|
1094
1144
|
// src/react/useBalanceSearch.ts
|
|
1095
|
-
var
|
|
1145
|
+
var import_react13 = require("react");
|
|
1096
1146
|
function useBalanceSearch(searchContext) {
|
|
1097
1147
|
const { track: track2 } = useBalance();
|
|
1098
|
-
const searchCountRef = (0,
|
|
1099
|
-
const clickCountRef = (0,
|
|
1100
|
-
const filterCountRef = (0,
|
|
1101
|
-
const activeFiltersRef = (0,
|
|
1102
|
-
const lastQueryRef = (0,
|
|
1103
|
-
const getBaseProps = (0,
|
|
1148
|
+
const searchCountRef = (0, import_react13.useRef)(0);
|
|
1149
|
+
const clickCountRef = (0, import_react13.useRef)(0);
|
|
1150
|
+
const filterCountRef = (0, import_react13.useRef)(0);
|
|
1151
|
+
const activeFiltersRef = (0, import_react13.useRef)(/* @__PURE__ */ new Map());
|
|
1152
|
+
const lastQueryRef = (0, import_react13.useRef)("");
|
|
1153
|
+
const getBaseProps = (0, import_react13.useCallback)(() => ({
|
|
1104
1154
|
search_context: searchContext,
|
|
1105
1155
|
session_searches: searchCountRef.current,
|
|
1106
1156
|
session_clicks: clickCountRef.current
|
|
1107
1157
|
}), [searchContext]);
|
|
1108
|
-
const getSearchStats = (0,
|
|
1158
|
+
const getSearchStats = (0, import_react13.useCallback)(() => ({
|
|
1109
1159
|
searches: searchCountRef.current,
|
|
1110
1160
|
clicks: clickCountRef.current,
|
|
1111
1161
|
filters: filterCountRef.current
|
|
1112
1162
|
}), []);
|
|
1113
|
-
const reset = (0,
|
|
1163
|
+
const reset = (0, import_react13.useCallback)(() => {
|
|
1114
1164
|
searchCountRef.current = 0;
|
|
1115
1165
|
clickCountRef.current = 0;
|
|
1116
1166
|
filterCountRef.current = 0;
|
|
1117
1167
|
activeFiltersRef.current.clear();
|
|
1118
1168
|
lastQueryRef.current = "";
|
|
1119
1169
|
}, []);
|
|
1120
|
-
const search = (0,
|
|
1170
|
+
const search = (0, import_react13.useCallback)((query, resultCount, searchType) => {
|
|
1121
1171
|
searchCountRef.current += 1;
|
|
1122
1172
|
lastQueryRef.current = query;
|
|
1123
1173
|
track2("search", {
|
|
@@ -1130,7 +1180,7 @@ function useBalanceSearch(searchContext) {
|
|
|
1130
1180
|
filter_count: activeFiltersRef.current.size
|
|
1131
1181
|
});
|
|
1132
1182
|
}, [track2, getBaseProps]);
|
|
1133
|
-
const selectResult = (0,
|
|
1183
|
+
const selectResult = (0, import_react13.useCallback)((query, resultId, position, resultType) => {
|
|
1134
1184
|
clickCountRef.current += 1;
|
|
1135
1185
|
track2("search_result_click", {
|
|
1136
1186
|
...getBaseProps(),
|
|
@@ -1140,7 +1190,7 @@ function useBalanceSearch(searchContext) {
|
|
|
1140
1190
|
result_type: resultType
|
|
1141
1191
|
});
|
|
1142
1192
|
}, [track2, getBaseProps]);
|
|
1143
|
-
const noResults = (0,
|
|
1193
|
+
const noResults = (0, import_react13.useCallback)((query, searchType) => {
|
|
1144
1194
|
searchCountRef.current += 1;
|
|
1145
1195
|
lastQueryRef.current = query;
|
|
1146
1196
|
track2("search_no_results", {
|
|
@@ -1151,7 +1201,7 @@ function useBalanceSearch(searchContext) {
|
|
|
1151
1201
|
filter_count: activeFiltersRef.current.size
|
|
1152
1202
|
});
|
|
1153
1203
|
}, [track2, getBaseProps]);
|
|
1154
|
-
const applyFilter = (0,
|
|
1204
|
+
const applyFilter = (0, import_react13.useCallback)((filter) => {
|
|
1155
1205
|
filterCountRef.current += 1;
|
|
1156
1206
|
const filterKey = `${filter.category}:${filter.value}`;
|
|
1157
1207
|
activeFiltersRef.current.set(filterKey, filter);
|
|
@@ -1163,7 +1213,7 @@ function useBalanceSearch(searchContext) {
|
|
|
1163
1213
|
last_query: lastQueryRef.current
|
|
1164
1214
|
});
|
|
1165
1215
|
}, [track2, getBaseProps]);
|
|
1166
|
-
const removeFilter = (0,
|
|
1216
|
+
const removeFilter = (0, import_react13.useCallback)((filter) => {
|
|
1167
1217
|
const filterKey = `${filter.category}:${filter.value}`;
|
|
1168
1218
|
activeFiltersRef.current.delete(filterKey);
|
|
1169
1219
|
track2("search_filter_remove", {
|
|
@@ -1174,7 +1224,7 @@ function useBalanceSearch(searchContext) {
|
|
|
1174
1224
|
last_query: lastQueryRef.current
|
|
1175
1225
|
});
|
|
1176
1226
|
}, [track2, getBaseProps]);
|
|
1177
|
-
const clearFilters = (0,
|
|
1227
|
+
const clearFilters = (0, import_react13.useCallback)(() => {
|
|
1178
1228
|
const filterCount = activeFiltersRef.current.size;
|
|
1179
1229
|
activeFiltersRef.current.clear();
|
|
1180
1230
|
track2("search_filters_clear", {
|
|
@@ -1183,7 +1233,7 @@ function useBalanceSearch(searchContext) {
|
|
|
1183
1233
|
last_query: lastQueryRef.current
|
|
1184
1234
|
});
|
|
1185
1235
|
}, [track2, getBaseProps]);
|
|
1186
|
-
const showSuggestions = (0,
|
|
1236
|
+
const showSuggestions = (0, import_react13.useCallback)((query, suggestions) => {
|
|
1187
1237
|
track2("search_suggestions_shown", {
|
|
1188
1238
|
...getBaseProps(),
|
|
1189
1239
|
query,
|
|
@@ -1192,7 +1242,7 @@ function useBalanceSearch(searchContext) {
|
|
|
1192
1242
|
// Limit to first 5
|
|
1193
1243
|
});
|
|
1194
1244
|
}, [track2, getBaseProps]);
|
|
1195
|
-
const selectSuggestion = (0,
|
|
1245
|
+
const selectSuggestion = (0, import_react13.useCallback)((originalQuery, suggestion, position) => {
|
|
1196
1246
|
track2("search_suggestion_click", {
|
|
1197
1247
|
...getBaseProps(),
|
|
1198
1248
|
original_query: originalQuery,
|
|
@@ -1200,7 +1250,7 @@ function useBalanceSearch(searchContext) {
|
|
|
1200
1250
|
suggestion_position: position
|
|
1201
1251
|
});
|
|
1202
1252
|
}, [track2, getBaseProps]);
|
|
1203
|
-
const refineSearch = (0,
|
|
1253
|
+
const refineSearch = (0, import_react13.useCallback)((originalQuery, newQuery) => {
|
|
1204
1254
|
track2("search_refined", {
|
|
1205
1255
|
...getBaseProps(),
|
|
1206
1256
|
original_query: originalQuery,
|
|
@@ -1208,7 +1258,7 @@ function useBalanceSearch(searchContext) {
|
|
|
1208
1258
|
refinement_type: newQuery.includes(originalQuery) ? "extended" : "modified"
|
|
1209
1259
|
});
|
|
1210
1260
|
}, [track2, getBaseProps]);
|
|
1211
|
-
const loadMoreResults = (0,
|
|
1261
|
+
const loadMoreResults = (0, import_react13.useCallback)((query, page2, resultsLoaded) => {
|
|
1212
1262
|
track2("search_load_more", {
|
|
1213
1263
|
...getBaseProps(),
|
|
1214
1264
|
search_term: query,
|
|
@@ -1216,7 +1266,7 @@ function useBalanceSearch(searchContext) {
|
|
|
1216
1266
|
total_results_loaded: resultsLoaded
|
|
1217
1267
|
});
|
|
1218
1268
|
}, [track2, getBaseProps]);
|
|
1219
|
-
const voiceSearch = (0,
|
|
1269
|
+
const voiceSearch = (0, import_react13.useCallback)((transcript, resultCount) => {
|
|
1220
1270
|
searchCountRef.current += 1;
|
|
1221
1271
|
lastQueryRef.current = transcript;
|
|
1222
1272
|
track2("voice_search", {
|
|
@@ -1249,31 +1299,31 @@ function useBalanceSearch(searchContext) {
|
|
|
1249
1299
|
}
|
|
1250
1300
|
|
|
1251
1301
|
// src/react/useBalanceNotification.ts
|
|
1252
|
-
var
|
|
1302
|
+
var import_react14 = require("react");
|
|
1253
1303
|
function useBalanceNotification() {
|
|
1254
1304
|
const { track: track2 } = useBalance();
|
|
1255
|
-
const shownCountRef = (0,
|
|
1256
|
-
const clickedCountRef = (0,
|
|
1257
|
-
const dismissedCountRef = (0,
|
|
1258
|
-
const notificationsSeenRef = (0,
|
|
1259
|
-
const getBaseProps = (0,
|
|
1305
|
+
const shownCountRef = (0, import_react14.useRef)(0);
|
|
1306
|
+
const clickedCountRef = (0, import_react14.useRef)(0);
|
|
1307
|
+
const dismissedCountRef = (0, import_react14.useRef)(0);
|
|
1308
|
+
const notificationsSeenRef = (0, import_react14.useRef)(/* @__PURE__ */ new Set());
|
|
1309
|
+
const getBaseProps = (0, import_react14.useCallback)(() => ({
|
|
1260
1310
|
session_notifications_shown: shownCountRef.current,
|
|
1261
1311
|
session_notifications_clicked: clickedCountRef.current
|
|
1262
1312
|
}), []);
|
|
1263
|
-
const getStats = (0,
|
|
1313
|
+
const getStats = (0, import_react14.useCallback)(() => {
|
|
1264
1314
|
const shown2 = shownCountRef.current;
|
|
1265
1315
|
const clicked2 = clickedCountRef.current;
|
|
1266
1316
|
const dismissed2 = dismissedCountRef.current;
|
|
1267
1317
|
const ctr = shown2 > 0 ? Math.round(clicked2 / shown2 * 100) : 0;
|
|
1268
1318
|
return { shown: shown2, clicked: clicked2, dismissed: dismissed2, ctr };
|
|
1269
1319
|
}, []);
|
|
1270
|
-
const reset = (0,
|
|
1320
|
+
const reset = (0, import_react14.useCallback)(() => {
|
|
1271
1321
|
shownCountRef.current = 0;
|
|
1272
1322
|
clickedCountRef.current = 0;
|
|
1273
1323
|
dismissedCountRef.current = 0;
|
|
1274
1324
|
notificationsSeenRef.current.clear();
|
|
1275
1325
|
}, []);
|
|
1276
|
-
const shown = (0,
|
|
1326
|
+
const shown = (0, import_react14.useCallback)((notificationId, type, campaign) => {
|
|
1277
1327
|
if (notificationsSeenRef.current.has(notificationId))
|
|
1278
1328
|
return;
|
|
1279
1329
|
notificationsSeenRef.current.add(notificationId);
|
|
@@ -1285,7 +1335,7 @@ function useBalanceNotification() {
|
|
|
1285
1335
|
campaign
|
|
1286
1336
|
});
|
|
1287
1337
|
}, [track2, getBaseProps]);
|
|
1288
|
-
const clicked = (0,
|
|
1338
|
+
const clicked = (0, import_react14.useCallback)((notificationId, type, action) => {
|
|
1289
1339
|
clickedCountRef.current += 1;
|
|
1290
1340
|
track2("notification_clicked", {
|
|
1291
1341
|
...getBaseProps(),
|
|
@@ -1294,7 +1344,7 @@ function useBalanceNotification() {
|
|
|
1294
1344
|
action
|
|
1295
1345
|
});
|
|
1296
1346
|
}, [track2, getBaseProps]);
|
|
1297
|
-
const dismissed = (0,
|
|
1347
|
+
const dismissed = (0, import_react14.useCallback)((notificationId, type, reason) => {
|
|
1298
1348
|
dismissedCountRef.current += 1;
|
|
1299
1349
|
track2("notification_dismissed", {
|
|
1300
1350
|
...getBaseProps(),
|
|
@@ -1303,33 +1353,33 @@ function useBalanceNotification() {
|
|
|
1303
1353
|
dismiss_reason: reason
|
|
1304
1354
|
});
|
|
1305
1355
|
}, [track2, getBaseProps]);
|
|
1306
|
-
const optIn = (0,
|
|
1356
|
+
const optIn = (0, import_react14.useCallback)((channel, source) => {
|
|
1307
1357
|
track2("notification_opt_in", {
|
|
1308
1358
|
...getBaseProps(),
|
|
1309
1359
|
channel,
|
|
1310
1360
|
opt_in_source: source
|
|
1311
1361
|
});
|
|
1312
1362
|
}, [track2, getBaseProps]);
|
|
1313
|
-
const optOut = (0,
|
|
1363
|
+
const optOut = (0, import_react14.useCallback)((channel, reason) => {
|
|
1314
1364
|
track2("notification_opt_out", {
|
|
1315
1365
|
...getBaseProps(),
|
|
1316
1366
|
channel,
|
|
1317
1367
|
opt_out_reason: reason
|
|
1318
1368
|
});
|
|
1319
1369
|
}, [track2, getBaseProps]);
|
|
1320
|
-
const permissionRequested = (0,
|
|
1370
|
+
const permissionRequested = (0, import_react14.useCallback)((channel) => {
|
|
1321
1371
|
track2("notification_permission_requested", {
|
|
1322
1372
|
...getBaseProps(),
|
|
1323
1373
|
channel
|
|
1324
1374
|
});
|
|
1325
1375
|
}, [track2, getBaseProps]);
|
|
1326
|
-
const permissionDenied = (0,
|
|
1376
|
+
const permissionDenied = (0, import_react14.useCallback)((channel) => {
|
|
1327
1377
|
track2("notification_permission_denied", {
|
|
1328
1378
|
...getBaseProps(),
|
|
1329
1379
|
channel
|
|
1330
1380
|
});
|
|
1331
1381
|
}, [track2, getBaseProps]);
|
|
1332
|
-
const preferenceUpdated = (0,
|
|
1382
|
+
const preferenceUpdated = (0, import_react14.useCallback)((preferences) => {
|
|
1333
1383
|
track2("notification_preferences_updated", {
|
|
1334
1384
|
...getBaseProps(),
|
|
1335
1385
|
preferences: preferences.map((p) => ({
|
|
@@ -1340,7 +1390,7 @@ function useBalanceNotification() {
|
|
|
1340
1390
|
enabled_channels: preferences.filter((p) => p.enabled).map((p) => p.channel)
|
|
1341
1391
|
});
|
|
1342
1392
|
}, [track2, getBaseProps]);
|
|
1343
|
-
const emailOpened = (0,
|
|
1393
|
+
const emailOpened = (0, import_react14.useCallback)((emailId, campaign, subject) => {
|
|
1344
1394
|
track2("email_opened", {
|
|
1345
1395
|
...getBaseProps(),
|
|
1346
1396
|
email_id: emailId,
|
|
@@ -1348,7 +1398,7 @@ function useBalanceNotification() {
|
|
|
1348
1398
|
subject
|
|
1349
1399
|
});
|
|
1350
1400
|
}, [track2, getBaseProps]);
|
|
1351
|
-
const emailLinkClicked = (0,
|
|
1401
|
+
const emailLinkClicked = (0, import_react14.useCallback)((emailId, linkUrl, linkName) => {
|
|
1352
1402
|
track2("email_link_clicked", {
|
|
1353
1403
|
...getBaseProps(),
|
|
1354
1404
|
email_id: emailId,
|
|
@@ -1356,7 +1406,7 @@ function useBalanceNotification() {
|
|
|
1356
1406
|
link_name: linkName
|
|
1357
1407
|
});
|
|
1358
1408
|
}, [track2, getBaseProps]);
|
|
1359
|
-
const emailUnsubscribed = (0,
|
|
1409
|
+
const emailUnsubscribed = (0, import_react14.useCallback)((emailId, reason, category) => {
|
|
1360
1410
|
track2("email_unsubscribed", {
|
|
1361
1411
|
...getBaseProps(),
|
|
1362
1412
|
email_id: emailId,
|
|
@@ -1364,14 +1414,14 @@ function useBalanceNotification() {
|
|
|
1364
1414
|
category
|
|
1365
1415
|
});
|
|
1366
1416
|
}, [track2, getBaseProps]);
|
|
1367
|
-
const pushReceived = (0,
|
|
1417
|
+
const pushReceived = (0, import_react14.useCallback)((notificationId, campaign) => {
|
|
1368
1418
|
track2("push_received", {
|
|
1369
1419
|
...getBaseProps(),
|
|
1370
1420
|
notification_id: notificationId,
|
|
1371
1421
|
campaign
|
|
1372
1422
|
});
|
|
1373
1423
|
}, [track2, getBaseProps]);
|
|
1374
|
-
const inAppInteraction = (0,
|
|
1424
|
+
const inAppInteraction = (0, import_react14.useCallback)((messageId, interactionType, elementClicked) => {
|
|
1375
1425
|
if (interactionType === "view")
|
|
1376
1426
|
shownCountRef.current += 1;
|
|
1377
1427
|
if (interactionType === "click")
|
|
@@ -1410,33 +1460,33 @@ function useBalanceNotification() {
|
|
|
1410
1460
|
}
|
|
1411
1461
|
|
|
1412
1462
|
// src/react/useBalanceSocial.ts
|
|
1413
|
-
var
|
|
1463
|
+
var import_react15 = require("react");
|
|
1414
1464
|
function useBalanceSocial() {
|
|
1415
1465
|
const { track: track2 } = useBalance();
|
|
1416
|
-
const followsRef = (0,
|
|
1417
|
-
const unfollowsRef = (0,
|
|
1418
|
-
const profileViewsRef = (0,
|
|
1419
|
-
const postsCreatedRef = (0,
|
|
1420
|
-
const viewedProfilesRef = (0,
|
|
1421
|
-
const getBaseProps = (0,
|
|
1466
|
+
const followsRef = (0, import_react15.useRef)(0);
|
|
1467
|
+
const unfollowsRef = (0, import_react15.useRef)(0);
|
|
1468
|
+
const profileViewsRef = (0, import_react15.useRef)(0);
|
|
1469
|
+
const postsCreatedRef = (0, import_react15.useRef)(0);
|
|
1470
|
+
const viewedProfilesRef = (0, import_react15.useRef)(/* @__PURE__ */ new Set());
|
|
1471
|
+
const getBaseProps = (0, import_react15.useCallback)(() => ({
|
|
1422
1472
|
session_follows: followsRef.current,
|
|
1423
1473
|
session_unfollows: unfollowsRef.current,
|
|
1424
1474
|
session_profile_views: profileViewsRef.current
|
|
1425
1475
|
}), []);
|
|
1426
|
-
const getStats = (0,
|
|
1476
|
+
const getStats = (0, import_react15.useCallback)(() => ({
|
|
1427
1477
|
follows: followsRef.current,
|
|
1428
1478
|
unfollows: unfollowsRef.current,
|
|
1429
1479
|
profileViews: profileViewsRef.current,
|
|
1430
1480
|
postsCreated: postsCreatedRef.current
|
|
1431
1481
|
}), []);
|
|
1432
|
-
const reset = (0,
|
|
1482
|
+
const reset = (0, import_react15.useCallback)(() => {
|
|
1433
1483
|
followsRef.current = 0;
|
|
1434
1484
|
unfollowsRef.current = 0;
|
|
1435
1485
|
profileViewsRef.current = 0;
|
|
1436
1486
|
postsCreatedRef.current = 0;
|
|
1437
1487
|
viewedProfilesRef.current.clear();
|
|
1438
1488
|
}, []);
|
|
1439
|
-
const viewProfile = (0,
|
|
1489
|
+
const viewProfile = (0, import_react15.useCallback)((entityId, entityType, source) => {
|
|
1440
1490
|
const profileKey = `${entityType}:${entityId}`;
|
|
1441
1491
|
const isFirstView = !viewedProfilesRef.current.has(profileKey);
|
|
1442
1492
|
if (isFirstView) {
|
|
@@ -1451,7 +1501,7 @@ function useBalanceSocial() {
|
|
|
1451
1501
|
is_first_view: isFirstView
|
|
1452
1502
|
});
|
|
1453
1503
|
}, [track2, getBaseProps]);
|
|
1454
|
-
const follow = (0,
|
|
1504
|
+
const follow = (0, import_react15.useCallback)((entityId, entityType, source) => {
|
|
1455
1505
|
followsRef.current += 1;
|
|
1456
1506
|
track2("follow", {
|
|
1457
1507
|
...getBaseProps(),
|
|
@@ -1460,7 +1510,7 @@ function useBalanceSocial() {
|
|
|
1460
1510
|
source
|
|
1461
1511
|
});
|
|
1462
1512
|
}, [track2, getBaseProps]);
|
|
1463
|
-
const unfollow = (0,
|
|
1513
|
+
const unfollow = (0, import_react15.useCallback)((entityId, entityType, reason) => {
|
|
1464
1514
|
unfollowsRef.current += 1;
|
|
1465
1515
|
track2("unfollow", {
|
|
1466
1516
|
...getBaseProps(),
|
|
@@ -1469,7 +1519,7 @@ function useBalanceSocial() {
|
|
|
1469
1519
|
reason
|
|
1470
1520
|
});
|
|
1471
1521
|
}, [track2, getBaseProps]);
|
|
1472
|
-
const block = (0,
|
|
1522
|
+
const block = (0, import_react15.useCallback)((entityId, entityType, reason) => {
|
|
1473
1523
|
track2("block", {
|
|
1474
1524
|
...getBaseProps(),
|
|
1475
1525
|
entity_id: entityId,
|
|
@@ -1477,14 +1527,14 @@ function useBalanceSocial() {
|
|
|
1477
1527
|
reason
|
|
1478
1528
|
});
|
|
1479
1529
|
}, [track2, getBaseProps]);
|
|
1480
|
-
const mute = (0,
|
|
1530
|
+
const mute = (0, import_react15.useCallback)((entityId, entityType) => {
|
|
1481
1531
|
track2("mute", {
|
|
1482
1532
|
...getBaseProps(),
|
|
1483
1533
|
entity_id: entityId,
|
|
1484
1534
|
entity_type: entityType
|
|
1485
1535
|
});
|
|
1486
1536
|
}, [track2, getBaseProps]);
|
|
1487
|
-
const report = (0,
|
|
1537
|
+
const report = (0, import_react15.useCallback)((entityId, entityType, reason, details) => {
|
|
1488
1538
|
track2("report", {
|
|
1489
1539
|
...getBaseProps(),
|
|
1490
1540
|
entity_id: entityId,
|
|
@@ -1493,7 +1543,7 @@ function useBalanceSocial() {
|
|
|
1493
1543
|
details
|
|
1494
1544
|
});
|
|
1495
1545
|
}, [track2, getBaseProps]);
|
|
1496
|
-
const mention = (0,
|
|
1546
|
+
const mention = (0, import_react15.useCallback)((mentionedId, mentionedType, context) => {
|
|
1497
1547
|
track2("mention_sent", {
|
|
1498
1548
|
...getBaseProps(),
|
|
1499
1549
|
mentioned_id: mentionedId,
|
|
@@ -1501,7 +1551,7 @@ function useBalanceSocial() {
|
|
|
1501
1551
|
context
|
|
1502
1552
|
});
|
|
1503
1553
|
}, [track2, getBaseProps]);
|
|
1504
|
-
const wasMentioned = (0,
|
|
1554
|
+
const wasMentioned = (0, import_react15.useCallback)((byUserId, context, contentId) => {
|
|
1505
1555
|
track2("mention_received", {
|
|
1506
1556
|
...getBaseProps(),
|
|
1507
1557
|
by_user_id: byUserId,
|
|
@@ -1509,21 +1559,21 @@ function useBalanceSocial() {
|
|
|
1509
1559
|
content_id: contentId
|
|
1510
1560
|
});
|
|
1511
1561
|
}, [track2, getBaseProps]);
|
|
1512
|
-
const inviteSent = (0,
|
|
1562
|
+
const inviteSent = (0, import_react15.useCallback)((channel, recipientCount) => {
|
|
1513
1563
|
track2("invite_sent", {
|
|
1514
1564
|
...getBaseProps(),
|
|
1515
1565
|
channel,
|
|
1516
1566
|
recipient_count: recipientCount || 1
|
|
1517
1567
|
});
|
|
1518
1568
|
}, [track2, getBaseProps]);
|
|
1519
|
-
const inviteAccepted = (0,
|
|
1569
|
+
const inviteAccepted = (0, import_react15.useCallback)((inviteCode, inviterId) => {
|
|
1520
1570
|
track2("invite_accepted", {
|
|
1521
1571
|
...getBaseProps(),
|
|
1522
1572
|
invite_code: inviteCode,
|
|
1523
1573
|
inviter_id: inviterId
|
|
1524
1574
|
});
|
|
1525
1575
|
}, [track2, getBaseProps]);
|
|
1526
|
-
const joinCommunity = (0,
|
|
1576
|
+
const joinCommunity = (0, import_react15.useCallback)((communityId, communityName, source) => {
|
|
1527
1577
|
track2("community_joined", {
|
|
1528
1578
|
...getBaseProps(),
|
|
1529
1579
|
community_id: communityId,
|
|
@@ -1531,7 +1581,7 @@ function useBalanceSocial() {
|
|
|
1531
1581
|
source
|
|
1532
1582
|
});
|
|
1533
1583
|
}, [track2, getBaseProps]);
|
|
1534
|
-
const leaveCommunity = (0,
|
|
1584
|
+
const leaveCommunity = (0, import_react15.useCallback)((communityId, communityName, reason) => {
|
|
1535
1585
|
track2("community_left", {
|
|
1536
1586
|
...getBaseProps(),
|
|
1537
1587
|
community_id: communityId,
|
|
@@ -1539,7 +1589,7 @@ function useBalanceSocial() {
|
|
|
1539
1589
|
reason
|
|
1540
1590
|
});
|
|
1541
1591
|
}, [track2, getBaseProps]);
|
|
1542
|
-
const createPost = (0,
|
|
1592
|
+
const createPost = (0, import_react15.useCallback)((postId, postType, communityId) => {
|
|
1543
1593
|
postsCreatedRef.current += 1;
|
|
1544
1594
|
track2("post_created", {
|
|
1545
1595
|
...getBaseProps(),
|
|
@@ -1548,7 +1598,7 @@ function useBalanceSocial() {
|
|
|
1548
1598
|
community_id: communityId
|
|
1549
1599
|
});
|
|
1550
1600
|
}, [track2, getBaseProps]);
|
|
1551
|
-
const replyToPost = (0,
|
|
1601
|
+
const replyToPost = (0, import_react15.useCallback)((postId, replyId, depth) => {
|
|
1552
1602
|
track2("reply_created", {
|
|
1553
1603
|
...getBaseProps(),
|
|
1554
1604
|
post_id: postId,
|
|
@@ -1556,7 +1606,7 @@ function useBalanceSocial() {
|
|
|
1556
1606
|
depth: depth || 1
|
|
1557
1607
|
});
|
|
1558
1608
|
}, [track2, getBaseProps]);
|
|
1559
|
-
const react = (0,
|
|
1609
|
+
const react = (0, import_react15.useCallback)((contentId, reactionType, contentType) => {
|
|
1560
1610
|
track2("reaction", {
|
|
1561
1611
|
...getBaseProps(),
|
|
1562
1612
|
content_id: contentId,
|
|
@@ -1564,27 +1614,27 @@ function useBalanceSocial() {
|
|
|
1564
1614
|
content_type: contentType
|
|
1565
1615
|
});
|
|
1566
1616
|
}, [track2, getBaseProps]);
|
|
1567
|
-
const editProfile = (0,
|
|
1617
|
+
const editProfile = (0, import_react15.useCallback)((fieldsEdited) => {
|
|
1568
1618
|
track2("profile_edited", {
|
|
1569
1619
|
...getBaseProps(),
|
|
1570
1620
|
fields_edited: fieldsEdited,
|
|
1571
1621
|
field_count: fieldsEdited.length
|
|
1572
1622
|
});
|
|
1573
1623
|
}, [track2, getBaseProps]);
|
|
1574
|
-
const changeAvatar = (0,
|
|
1624
|
+
const changeAvatar = (0, import_react15.useCallback)((source) => {
|
|
1575
1625
|
track2("avatar_changed", {
|
|
1576
1626
|
...getBaseProps(),
|
|
1577
1627
|
source
|
|
1578
1628
|
});
|
|
1579
1629
|
}, [track2, getBaseProps]);
|
|
1580
|
-
const connectionRequest = (0,
|
|
1630
|
+
const connectionRequest = (0, import_react15.useCallback)((targetId, targetType) => {
|
|
1581
1631
|
track2("connection_requested", {
|
|
1582
1632
|
...getBaseProps(),
|
|
1583
1633
|
target_id: targetId,
|
|
1584
1634
|
target_type: targetType
|
|
1585
1635
|
});
|
|
1586
1636
|
}, [track2, getBaseProps]);
|
|
1587
|
-
const connectionAccepted = (0,
|
|
1637
|
+
const connectionAccepted = (0, import_react15.useCallback)((requesterId, requesterType) => {
|
|
1588
1638
|
track2("connection_accepted", {
|
|
1589
1639
|
...getBaseProps(),
|
|
1590
1640
|
requester_id: requesterId,
|
|
@@ -1625,34 +1675,34 @@ function useBalanceSocial() {
|
|
|
1625
1675
|
}
|
|
1626
1676
|
|
|
1627
1677
|
// src/react/useBalanceAuth.ts
|
|
1628
|
-
var
|
|
1678
|
+
var import_react16 = require("react");
|
|
1629
1679
|
function useBalanceAuth() {
|
|
1630
1680
|
const { track: track2, identify: identify2 } = useBalance();
|
|
1631
|
-
const loginAttemptsRef = (0,
|
|
1632
|
-
const loginSuccessesRef = (0,
|
|
1633
|
-
const loginFailuresRef = (0,
|
|
1634
|
-
const authStartTimeRef = (0,
|
|
1635
|
-
const getBaseProps = (0,
|
|
1681
|
+
const loginAttemptsRef = (0, import_react16.useRef)(0);
|
|
1682
|
+
const loginSuccessesRef = (0, import_react16.useRef)(0);
|
|
1683
|
+
const loginFailuresRef = (0, import_react16.useRef)(0);
|
|
1684
|
+
const authStartTimeRef = (0, import_react16.useRef)(null);
|
|
1685
|
+
const getBaseProps = (0, import_react16.useCallback)(() => ({
|
|
1636
1686
|
session_login_attempts: loginAttemptsRef.current,
|
|
1637
1687
|
session_login_successes: loginSuccessesRef.current
|
|
1638
1688
|
}), []);
|
|
1639
|
-
const getAuthDuration = (0,
|
|
1689
|
+
const getAuthDuration = (0, import_react16.useCallback)(() => {
|
|
1640
1690
|
if (!authStartTimeRef.current)
|
|
1641
1691
|
return 0;
|
|
1642
1692
|
return Math.round((Date.now() - authStartTimeRef.current) / 1e3);
|
|
1643
1693
|
}, []);
|
|
1644
|
-
const getStats = (0,
|
|
1694
|
+
const getStats = (0, import_react16.useCallback)(() => ({
|
|
1645
1695
|
loginAttempts: loginAttemptsRef.current,
|
|
1646
1696
|
loginSuccesses: loginSuccessesRef.current,
|
|
1647
1697
|
loginFailures: loginFailuresRef.current
|
|
1648
1698
|
}), []);
|
|
1649
|
-
const reset = (0,
|
|
1699
|
+
const reset = (0, import_react16.useCallback)(() => {
|
|
1650
1700
|
loginAttemptsRef.current = 0;
|
|
1651
1701
|
loginSuccessesRef.current = 0;
|
|
1652
1702
|
loginFailuresRef.current = 0;
|
|
1653
1703
|
authStartTimeRef.current = null;
|
|
1654
1704
|
}, []);
|
|
1655
|
-
const signUpStart = (0,
|
|
1705
|
+
const signUpStart = (0, import_react16.useCallback)((method, source) => {
|
|
1656
1706
|
authStartTimeRef.current = Date.now();
|
|
1657
1707
|
track2("sign_up_start", {
|
|
1658
1708
|
...getBaseProps(),
|
|
@@ -1660,7 +1710,7 @@ function useBalanceAuth() {
|
|
|
1660
1710
|
source
|
|
1661
1711
|
});
|
|
1662
1712
|
}, [track2, getBaseProps]);
|
|
1663
|
-
const signUpSuccess = (0,
|
|
1713
|
+
const signUpSuccess = (0, import_react16.useCallback)((method, email) => {
|
|
1664
1714
|
loginSuccessesRef.current += 1;
|
|
1665
1715
|
if (email) {
|
|
1666
1716
|
identify2(email, { auth_method: method, signup_date: (/* @__PURE__ */ new Date()).toISOString() });
|
|
@@ -1672,7 +1722,7 @@ function useBalanceAuth() {
|
|
|
1672
1722
|
});
|
|
1673
1723
|
authStartTimeRef.current = null;
|
|
1674
1724
|
}, [track2, identify2, getBaseProps, getAuthDuration]);
|
|
1675
|
-
const signUpFailed = (0,
|
|
1725
|
+
const signUpFailed = (0, import_react16.useCallback)((method, errorCode, errorMessage) => {
|
|
1676
1726
|
loginFailuresRef.current += 1;
|
|
1677
1727
|
track2("sign_up_failed", {
|
|
1678
1728
|
...getBaseProps(),
|
|
@@ -1682,19 +1732,19 @@ function useBalanceAuth() {
|
|
|
1682
1732
|
duration_seconds: getAuthDuration()
|
|
1683
1733
|
});
|
|
1684
1734
|
}, [track2, getBaseProps, getAuthDuration]);
|
|
1685
|
-
const verificationSent = (0,
|
|
1735
|
+
const verificationSent = (0, import_react16.useCallback)((method) => {
|
|
1686
1736
|
track2("verification_sent", {
|
|
1687
1737
|
...getBaseProps(),
|
|
1688
1738
|
method
|
|
1689
1739
|
});
|
|
1690
1740
|
}, [track2, getBaseProps]);
|
|
1691
|
-
const verified = (0,
|
|
1741
|
+
const verified = (0, import_react16.useCallback)((method) => {
|
|
1692
1742
|
track2("verified", {
|
|
1693
1743
|
...getBaseProps(),
|
|
1694
1744
|
method
|
|
1695
1745
|
});
|
|
1696
1746
|
}, [track2, getBaseProps]);
|
|
1697
|
-
const loginStart = (0,
|
|
1747
|
+
const loginStart = (0, import_react16.useCallback)((method, source) => {
|
|
1698
1748
|
loginAttemptsRef.current += 1;
|
|
1699
1749
|
authStartTimeRef.current = Date.now();
|
|
1700
1750
|
track2("login_start", {
|
|
@@ -1703,7 +1753,7 @@ function useBalanceAuth() {
|
|
|
1703
1753
|
source
|
|
1704
1754
|
});
|
|
1705
1755
|
}, [track2, getBaseProps]);
|
|
1706
|
-
const loginSuccess = (0,
|
|
1756
|
+
const loginSuccess = (0, import_react16.useCallback)((method, email) => {
|
|
1707
1757
|
loginSuccessesRef.current += 1;
|
|
1708
1758
|
if (email) {
|
|
1709
1759
|
identify2(email, { auth_method: method, last_login: (/* @__PURE__ */ new Date()).toISOString() });
|
|
@@ -1715,7 +1765,7 @@ function useBalanceAuth() {
|
|
|
1715
1765
|
});
|
|
1716
1766
|
authStartTimeRef.current = null;
|
|
1717
1767
|
}, [track2, identify2, getBaseProps, getAuthDuration]);
|
|
1718
|
-
const loginFailed = (0,
|
|
1768
|
+
const loginFailed = (0, import_react16.useCallback)((method, errorCode, errorMessage) => {
|
|
1719
1769
|
loginFailuresRef.current += 1;
|
|
1720
1770
|
track2("login_failed", {
|
|
1721
1771
|
...getBaseProps(),
|
|
@@ -1725,108 +1775,108 @@ function useBalanceAuth() {
|
|
|
1725
1775
|
duration_seconds: getAuthDuration()
|
|
1726
1776
|
});
|
|
1727
1777
|
}, [track2, getBaseProps, getAuthDuration]);
|
|
1728
|
-
const logout = (0,
|
|
1778
|
+
const logout = (0, import_react16.useCallback)((reason = "user_initiated") => {
|
|
1729
1779
|
track2("logout", {
|
|
1730
1780
|
...getBaseProps(),
|
|
1731
1781
|
reason
|
|
1732
1782
|
});
|
|
1733
1783
|
}, [track2, getBaseProps]);
|
|
1734
|
-
const passwordResetRequested = (0,
|
|
1784
|
+
const passwordResetRequested = (0, import_react16.useCallback)((method) => {
|
|
1735
1785
|
track2("password_reset_requested", {
|
|
1736
1786
|
...getBaseProps(),
|
|
1737
1787
|
method
|
|
1738
1788
|
});
|
|
1739
1789
|
}, [track2, getBaseProps]);
|
|
1740
|
-
const passwordResetCompleted = (0,
|
|
1790
|
+
const passwordResetCompleted = (0, import_react16.useCallback)(() => {
|
|
1741
1791
|
track2("password_reset_completed", {
|
|
1742
1792
|
...getBaseProps()
|
|
1743
1793
|
});
|
|
1744
1794
|
}, [track2, getBaseProps]);
|
|
1745
|
-
const passwordChanged = (0,
|
|
1795
|
+
const passwordChanged = (0, import_react16.useCallback)((source) => {
|
|
1746
1796
|
track2("password_changed", {
|
|
1747
1797
|
...getBaseProps(),
|
|
1748
1798
|
source
|
|
1749
1799
|
});
|
|
1750
1800
|
}, [track2, getBaseProps]);
|
|
1751
|
-
const mfaSetupStart = (0,
|
|
1801
|
+
const mfaSetupStart = (0, import_react16.useCallback)((method) => {
|
|
1752
1802
|
track2("mfa_setup_start", {
|
|
1753
1803
|
...getBaseProps(),
|
|
1754
1804
|
method
|
|
1755
1805
|
});
|
|
1756
1806
|
}, [track2, getBaseProps]);
|
|
1757
|
-
const mfaSetupCompleted = (0,
|
|
1807
|
+
const mfaSetupCompleted = (0, import_react16.useCallback)((method) => {
|
|
1758
1808
|
track2("mfa_setup_completed", {
|
|
1759
1809
|
...getBaseProps(),
|
|
1760
1810
|
method
|
|
1761
1811
|
});
|
|
1762
1812
|
}, [track2, getBaseProps]);
|
|
1763
|
-
const mfaChallenge = (0,
|
|
1813
|
+
const mfaChallenge = (0, import_react16.useCallback)((method) => {
|
|
1764
1814
|
track2("mfa_challenge", {
|
|
1765
1815
|
...getBaseProps(),
|
|
1766
1816
|
method
|
|
1767
1817
|
});
|
|
1768
1818
|
}, [track2, getBaseProps]);
|
|
1769
|
-
const mfaSuccess = (0,
|
|
1819
|
+
const mfaSuccess = (0, import_react16.useCallback)((method) => {
|
|
1770
1820
|
track2("mfa_success", {
|
|
1771
1821
|
...getBaseProps(),
|
|
1772
1822
|
method
|
|
1773
1823
|
});
|
|
1774
1824
|
}, [track2, getBaseProps]);
|
|
1775
|
-
const mfaFailed = (0,
|
|
1825
|
+
const mfaFailed = (0, import_react16.useCallback)((method, reason) => {
|
|
1776
1826
|
track2("mfa_failed", {
|
|
1777
1827
|
...getBaseProps(),
|
|
1778
1828
|
method,
|
|
1779
1829
|
reason
|
|
1780
1830
|
});
|
|
1781
1831
|
}, [track2, getBaseProps]);
|
|
1782
|
-
const mfaDisabled = (0,
|
|
1832
|
+
const mfaDisabled = (0, import_react16.useCallback)((method) => {
|
|
1783
1833
|
track2("mfa_disabled", {
|
|
1784
1834
|
...getBaseProps(),
|
|
1785
1835
|
method
|
|
1786
1836
|
});
|
|
1787
1837
|
}, [track2, getBaseProps]);
|
|
1788
|
-
const sessionStart = (0,
|
|
1838
|
+
const sessionStart = (0, import_react16.useCallback)((isNewUser, authMethod) => {
|
|
1789
1839
|
track2("session_start", {
|
|
1790
1840
|
...getBaseProps(),
|
|
1791
1841
|
is_new_user: isNewUser,
|
|
1792
1842
|
auth_method: authMethod
|
|
1793
1843
|
});
|
|
1794
1844
|
}, [track2, getBaseProps]);
|
|
1795
|
-
const sessionResume = (0,
|
|
1845
|
+
const sessionResume = (0, import_react16.useCallback)(() => {
|
|
1796
1846
|
track2("session_resume", {
|
|
1797
1847
|
...getBaseProps()
|
|
1798
1848
|
});
|
|
1799
1849
|
}, [track2, getBaseProps]);
|
|
1800
|
-
const sessionExpired = (0,
|
|
1850
|
+
const sessionExpired = (0, import_react16.useCallback)((durationSeconds) => {
|
|
1801
1851
|
track2("session_expired", {
|
|
1802
1852
|
...getBaseProps(),
|
|
1803
1853
|
duration_seconds: durationSeconds
|
|
1804
1854
|
});
|
|
1805
1855
|
}, [track2, getBaseProps]);
|
|
1806
|
-
const sessionRefreshed = (0,
|
|
1856
|
+
const sessionRefreshed = (0, import_react16.useCallback)(() => {
|
|
1807
1857
|
track2("session_refreshed", {
|
|
1808
1858
|
...getBaseProps()
|
|
1809
1859
|
});
|
|
1810
1860
|
}, [track2, getBaseProps]);
|
|
1811
|
-
const accountDeletionRequested = (0,
|
|
1861
|
+
const accountDeletionRequested = (0, import_react16.useCallback)((reason) => {
|
|
1812
1862
|
track2("account_deletion_requested", {
|
|
1813
1863
|
...getBaseProps(),
|
|
1814
1864
|
reason
|
|
1815
1865
|
});
|
|
1816
1866
|
}, [track2, getBaseProps]);
|
|
1817
|
-
const accountDeleted = (0,
|
|
1867
|
+
const accountDeleted = (0, import_react16.useCallback)((reason) => {
|
|
1818
1868
|
track2("account_deleted", {
|
|
1819
1869
|
...getBaseProps(),
|
|
1820
1870
|
reason
|
|
1821
1871
|
});
|
|
1822
1872
|
}, [track2, getBaseProps]);
|
|
1823
|
-
const accountLinked = (0,
|
|
1873
|
+
const accountLinked = (0, import_react16.useCallback)((method) => {
|
|
1824
1874
|
track2("account_linked", {
|
|
1825
1875
|
...getBaseProps(),
|
|
1826
1876
|
method
|
|
1827
1877
|
});
|
|
1828
1878
|
}, [track2, getBaseProps]);
|
|
1829
|
-
const accountUnlinked = (0,
|
|
1879
|
+
const accountUnlinked = (0, import_react16.useCallback)((method) => {
|
|
1830
1880
|
track2("account_unlinked", {
|
|
1831
1881
|
...getBaseProps(),
|
|
1832
1882
|
method
|
|
@@ -1872,25 +1922,25 @@ function useBalanceAuth() {
|
|
|
1872
1922
|
}
|
|
1873
1923
|
|
|
1874
1924
|
// src/react/useBalanceError.ts
|
|
1875
|
-
var
|
|
1925
|
+
var import_react17 = require("react");
|
|
1876
1926
|
function useBalanceError() {
|
|
1877
1927
|
const { track: track2 } = useBalance();
|
|
1878
|
-
const errorCountRef = (0,
|
|
1879
|
-
const apiErrorCountRef = (0,
|
|
1880
|
-
const userReportCountRef = (0,
|
|
1881
|
-
const pageLoadTimesRef = (0,
|
|
1882
|
-
const measureStartTimesRef = (0,
|
|
1883
|
-
const capturedErrorsRef = (0,
|
|
1884
|
-
const getBaseProps = (0,
|
|
1928
|
+
const errorCountRef = (0, import_react17.useRef)(0);
|
|
1929
|
+
const apiErrorCountRef = (0, import_react17.useRef)(0);
|
|
1930
|
+
const userReportCountRef = (0, import_react17.useRef)(0);
|
|
1931
|
+
const pageLoadTimesRef = (0, import_react17.useRef)([]);
|
|
1932
|
+
const measureStartTimesRef = (0, import_react17.useRef)(/* @__PURE__ */ new Map());
|
|
1933
|
+
const capturedErrorsRef = (0, import_react17.useRef)(/* @__PURE__ */ new Set());
|
|
1934
|
+
const getBaseProps = (0, import_react17.useCallback)(() => ({
|
|
1885
1935
|
session_errors: errorCountRef.current,
|
|
1886
1936
|
session_api_errors: apiErrorCountRef.current,
|
|
1887
1937
|
page_url: typeof window !== "undefined" ? window.location.href : void 0,
|
|
1888
1938
|
user_agent: typeof navigator !== "undefined" ? navigator.userAgent : void 0
|
|
1889
1939
|
}), []);
|
|
1890
|
-
const getErrorFingerprint = (0,
|
|
1940
|
+
const getErrorFingerprint = (0, import_react17.useCallback)((error) => {
|
|
1891
1941
|
return `${error.name}:${error.message}:${error.stack?.split("\n")[1] || ""}`;
|
|
1892
1942
|
}, []);
|
|
1893
|
-
const getStats = (0,
|
|
1943
|
+
const getStats = (0, import_react17.useCallback)(() => {
|
|
1894
1944
|
const times = pageLoadTimesRef.current;
|
|
1895
1945
|
const avgPageLoad = times.length > 0 ? Math.round(times.reduce((a, b) => a + b, 0) / times.length) : null;
|
|
1896
1946
|
return {
|
|
@@ -1900,7 +1950,7 @@ function useBalanceError() {
|
|
|
1900
1950
|
avgPageLoad
|
|
1901
1951
|
};
|
|
1902
1952
|
}, []);
|
|
1903
|
-
const reset = (0,
|
|
1953
|
+
const reset = (0, import_react17.useCallback)(() => {
|
|
1904
1954
|
errorCountRef.current = 0;
|
|
1905
1955
|
apiErrorCountRef.current = 0;
|
|
1906
1956
|
userReportCountRef.current = 0;
|
|
@@ -1908,7 +1958,7 @@ function useBalanceError() {
|
|
|
1908
1958
|
measureStartTimesRef.current.clear();
|
|
1909
1959
|
capturedErrorsRef.current.clear();
|
|
1910
1960
|
}, []);
|
|
1911
|
-
const captureError = (0,
|
|
1961
|
+
const captureError = (0, import_react17.useCallback)((error, context, severity = "error") => {
|
|
1912
1962
|
const fingerprint = getErrorFingerprint(error);
|
|
1913
1963
|
if (capturedErrorsRef.current.has(fingerprint))
|
|
1914
1964
|
return;
|
|
@@ -1924,7 +1974,7 @@ function useBalanceError() {
|
|
|
1924
1974
|
...context
|
|
1925
1975
|
});
|
|
1926
1976
|
}, [track2, getBaseProps, getErrorFingerprint]);
|
|
1927
|
-
const captureApiError = (0,
|
|
1977
|
+
const captureApiError = (0, import_react17.useCallback)((details, context) => {
|
|
1928
1978
|
apiErrorCountRef.current += 1;
|
|
1929
1979
|
track2("api_error", {
|
|
1930
1980
|
...getBaseProps(),
|
|
@@ -1937,7 +1987,7 @@ function useBalanceError() {
|
|
|
1937
1987
|
...context
|
|
1938
1988
|
});
|
|
1939
1989
|
}, [track2, getBaseProps]);
|
|
1940
|
-
const captureUserReport = (0,
|
|
1990
|
+
const captureUserReport = (0, import_react17.useCallback)((category, description, metadata) => {
|
|
1941
1991
|
userReportCountRef.current += 1;
|
|
1942
1992
|
track2("user_report", {
|
|
1943
1993
|
...getBaseProps(),
|
|
@@ -1946,7 +1996,7 @@ function useBalanceError() {
|
|
|
1946
1996
|
...metadata
|
|
1947
1997
|
});
|
|
1948
1998
|
}, [track2, getBaseProps]);
|
|
1949
|
-
const captureComponentError = (0,
|
|
1999
|
+
const captureComponentError = (0, import_react17.useCallback)((error, componentName, componentStack) => {
|
|
1950
2000
|
errorCountRef.current += 1;
|
|
1951
2001
|
track2("component_error", {
|
|
1952
2002
|
...getBaseProps(),
|
|
@@ -1956,7 +2006,7 @@ function useBalanceError() {
|
|
|
1956
2006
|
component_stack: componentStack?.slice(0, 1e3)
|
|
1957
2007
|
});
|
|
1958
2008
|
}, [track2, getBaseProps]);
|
|
1959
|
-
const captureUnhandledRejection = (0,
|
|
2009
|
+
const captureUnhandledRejection = (0, import_react17.useCallback)((reason, promiseInfo) => {
|
|
1960
2010
|
errorCountRef.current += 1;
|
|
1961
2011
|
const message = reason instanceof Error ? reason.message : String(reason);
|
|
1962
2012
|
track2("unhandled_rejection", {
|
|
@@ -1965,7 +2015,7 @@ function useBalanceError() {
|
|
|
1965
2015
|
promise_info: promiseInfo
|
|
1966
2016
|
});
|
|
1967
2017
|
}, [track2, getBaseProps]);
|
|
1968
|
-
const captureResourceError = (0,
|
|
2018
|
+
const captureResourceError = (0, import_react17.useCallback)((resourceUrl, resourceType, details) => {
|
|
1969
2019
|
track2("resource_error", {
|
|
1970
2020
|
...getBaseProps(),
|
|
1971
2021
|
resource_url: resourceUrl,
|
|
@@ -1973,7 +2023,7 @@ function useBalanceError() {
|
|
|
1973
2023
|
...details
|
|
1974
2024
|
});
|
|
1975
2025
|
}, [track2, getBaseProps]);
|
|
1976
|
-
const trackPerformance = (0,
|
|
2026
|
+
const trackPerformance = (0, import_react17.useCallback)((metricType, valueMs, context) => {
|
|
1977
2027
|
if (metricType === "page_load") {
|
|
1978
2028
|
pageLoadTimesRef.current.push(valueMs);
|
|
1979
2029
|
}
|
|
@@ -1984,7 +2034,7 @@ function useBalanceError() {
|
|
|
1984
2034
|
...context
|
|
1985
2035
|
});
|
|
1986
2036
|
}, [track2, getBaseProps]);
|
|
1987
|
-
const trackWebVitals = (0,
|
|
2037
|
+
const trackWebVitals = (0, import_react17.useCallback)((vitals) => {
|
|
1988
2038
|
track2("web_vitals", {
|
|
1989
2039
|
...getBaseProps(),
|
|
1990
2040
|
lcp_ms: vitals.lcp ? Math.round(vitals.lcp) : void 0,
|
|
@@ -1994,7 +2044,7 @@ function useBalanceError() {
|
|
|
1994
2044
|
ttfb_ms: vitals.ttfb ? Math.round(vitals.ttfb) : void 0
|
|
1995
2045
|
});
|
|
1996
2046
|
}, [track2, getBaseProps]);
|
|
1997
|
-
const trackSlowInteraction = (0,
|
|
2047
|
+
const trackSlowInteraction = (0, import_react17.useCallback)((interactionType, durationMs, targetElement) => {
|
|
1998
2048
|
track2("slow_interaction", {
|
|
1999
2049
|
...getBaseProps(),
|
|
2000
2050
|
interaction_type: interactionType,
|
|
@@ -2002,10 +2052,10 @@ function useBalanceError() {
|
|
|
2002
2052
|
target_element: targetElement
|
|
2003
2053
|
});
|
|
2004
2054
|
}, [track2, getBaseProps]);
|
|
2005
|
-
const startMeasure = (0,
|
|
2055
|
+
const startMeasure = (0, import_react17.useCallback)((measureName) => {
|
|
2006
2056
|
measureStartTimesRef.current.set(measureName, performance.now());
|
|
2007
2057
|
}, []);
|
|
2008
|
-
const endMeasure = (0,
|
|
2058
|
+
const endMeasure = (0, import_react17.useCallback)((measureName, metricType = "interaction") => {
|
|
2009
2059
|
const startTime = measureStartTimesRef.current.get(measureName);
|
|
2010
2060
|
if (!startTime)
|
|
2011
2061
|
return null;
|
|
@@ -2036,22 +2086,22 @@ function useBalanceError() {
|
|
|
2036
2086
|
}
|
|
2037
2087
|
|
|
2038
2088
|
// src/react/useBalanceAB.ts
|
|
2039
|
-
var
|
|
2089
|
+
var import_react18 = require("react");
|
|
2040
2090
|
function useBalanceAB() {
|
|
2041
2091
|
const { track: track2 } = useBalance();
|
|
2042
|
-
const exposuresRef = (0,
|
|
2043
|
-
const conversionsRef = (0,
|
|
2044
|
-
const activeExperimentsRef = (0,
|
|
2045
|
-
const exposedExperimentsRef = (0,
|
|
2046
|
-
const getBaseProps = (0,
|
|
2092
|
+
const exposuresRef = (0, import_react18.useRef)(0);
|
|
2093
|
+
const conversionsRef = (0, import_react18.useRef)(0);
|
|
2094
|
+
const activeExperimentsRef = (0, import_react18.useRef)(/* @__PURE__ */ new Map());
|
|
2095
|
+
const exposedExperimentsRef = (0, import_react18.useRef)(/* @__PURE__ */ new Set());
|
|
2096
|
+
const getBaseProps = (0, import_react18.useCallback)(() => ({
|
|
2047
2097
|
session_exposures: exposuresRef.current,
|
|
2048
2098
|
session_conversions: conversionsRef.current,
|
|
2049
2099
|
active_experiment_count: activeExperimentsRef.current.size
|
|
2050
2100
|
}), []);
|
|
2051
|
-
const getStorageKey = (0,
|
|
2101
|
+
const getStorageKey = (0, import_react18.useCallback)((experimentId) => {
|
|
2052
2102
|
return `balance_ab_${experimentId}`;
|
|
2053
2103
|
}, []);
|
|
2054
|
-
const getVariant = (0,
|
|
2104
|
+
const getVariant = (0, import_react18.useCallback)((experimentId) => {
|
|
2055
2105
|
if (typeof window === "undefined")
|
|
2056
2106
|
return null;
|
|
2057
2107
|
try {
|
|
@@ -2061,7 +2111,7 @@ function useBalanceAB() {
|
|
|
2061
2111
|
return null;
|
|
2062
2112
|
}
|
|
2063
2113
|
}, [getStorageKey]);
|
|
2064
|
-
const setVariant = (0,
|
|
2114
|
+
const setVariant = (0, import_react18.useCallback)((experimentId, variant) => {
|
|
2065
2115
|
if (typeof window === "undefined")
|
|
2066
2116
|
return;
|
|
2067
2117
|
try {
|
|
@@ -2070,10 +2120,10 @@ function useBalanceAB() {
|
|
|
2070
2120
|
} catch {
|
|
2071
2121
|
}
|
|
2072
2122
|
}, [getStorageKey]);
|
|
2073
|
-
const getActiveExperiments = (0,
|
|
2123
|
+
const getActiveExperiments = (0, import_react18.useCallback)(() => {
|
|
2074
2124
|
return new Map(activeExperimentsRef.current);
|
|
2075
2125
|
}, []);
|
|
2076
|
-
const getStats = (0,
|
|
2126
|
+
const getStats = (0, import_react18.useCallback)(() => {
|
|
2077
2127
|
const exposures = exposuresRef.current;
|
|
2078
2128
|
const conversions = conversionsRef.current;
|
|
2079
2129
|
const conversionRate = exposures > 0 ? Math.round(conversions / exposures * 1e4) / 100 : 0;
|
|
@@ -2084,13 +2134,13 @@ function useBalanceAB() {
|
|
|
2084
2134
|
conversionRate
|
|
2085
2135
|
};
|
|
2086
2136
|
}, []);
|
|
2087
|
-
const reset = (0,
|
|
2137
|
+
const reset = (0, import_react18.useCallback)(() => {
|
|
2088
2138
|
exposuresRef.current = 0;
|
|
2089
2139
|
conversionsRef.current = 0;
|
|
2090
2140
|
activeExperimentsRef.current.clear();
|
|
2091
2141
|
exposedExperimentsRef.current.clear();
|
|
2092
2142
|
}, []);
|
|
2093
|
-
(0,
|
|
2143
|
+
(0, import_react18.useEffect)(() => {
|
|
2094
2144
|
if (typeof window === "undefined")
|
|
2095
2145
|
return;
|
|
2096
2146
|
try {
|
|
@@ -2107,7 +2157,7 @@ function useBalanceAB() {
|
|
|
2107
2157
|
} catch {
|
|
2108
2158
|
}
|
|
2109
2159
|
}, []);
|
|
2110
|
-
const trackExposure = (0,
|
|
2160
|
+
const trackExposure = (0, import_react18.useCallback)((experimentId, variant, context) => {
|
|
2111
2161
|
const exposureKey = `${experimentId}:${variant}`;
|
|
2112
2162
|
if (exposedExperimentsRef.current.has(exposureKey))
|
|
2113
2163
|
return;
|
|
@@ -2122,7 +2172,7 @@ function useBalanceAB() {
|
|
|
2122
2172
|
...context
|
|
2123
2173
|
});
|
|
2124
2174
|
}, [track2, getBaseProps]);
|
|
2125
|
-
const trackConversion = (0,
|
|
2175
|
+
const trackConversion = (0, import_react18.useCallback)((experimentId, variant, conversionData) => {
|
|
2126
2176
|
conversionsRef.current += 1;
|
|
2127
2177
|
track2("experiment_conversion", {
|
|
2128
2178
|
...getBaseProps(),
|
|
@@ -2131,7 +2181,7 @@ function useBalanceAB() {
|
|
|
2131
2181
|
...conversionData
|
|
2132
2182
|
});
|
|
2133
2183
|
}, [track2, getBaseProps]);
|
|
2134
|
-
const trackInteraction = (0,
|
|
2184
|
+
const trackInteraction = (0, import_react18.useCallback)((experimentId, variant, interactionType, details) => {
|
|
2135
2185
|
track2("experiment_interaction", {
|
|
2136
2186
|
...getBaseProps(),
|
|
2137
2187
|
experiment_id: experimentId,
|
|
@@ -2140,7 +2190,7 @@ function useBalanceAB() {
|
|
|
2140
2190
|
...details
|
|
2141
2191
|
});
|
|
2142
2192
|
}, [track2, getBaseProps]);
|
|
2143
|
-
const enrollUser = (0,
|
|
2193
|
+
const enrollUser = (0, import_react18.useCallback)((experimentId, variant, source = "random") => {
|
|
2144
2194
|
setVariant(experimentId, variant);
|
|
2145
2195
|
track2("experiment_enrolled", {
|
|
2146
2196
|
...getBaseProps(),
|
|
@@ -2149,7 +2199,7 @@ function useBalanceAB() {
|
|
|
2149
2199
|
enrollment_source: source
|
|
2150
2200
|
});
|
|
2151
2201
|
}, [track2, getBaseProps, setVariant]);
|
|
2152
|
-
const exitExperiment = (0,
|
|
2202
|
+
const exitExperiment = (0, import_react18.useCallback)((experimentId, reason = "completed") => {
|
|
2153
2203
|
const variant = activeExperimentsRef.current.get(experimentId);
|
|
2154
2204
|
activeExperimentsRef.current.delete(experimentId);
|
|
2155
2205
|
track2("experiment_exit", {
|
|
@@ -2159,7 +2209,7 @@ function useBalanceAB() {
|
|
|
2159
2209
|
exit_reason: reason
|
|
2160
2210
|
});
|
|
2161
2211
|
}, [track2, getBaseProps]);
|
|
2162
|
-
const trackFeatureFlag = (0,
|
|
2212
|
+
const trackFeatureFlag = (0, import_react18.useCallback)((flag) => {
|
|
2163
2213
|
track2("feature_flag_evaluated", {
|
|
2164
2214
|
...getBaseProps(),
|
|
2165
2215
|
flag_key: flag.key,
|
|
@@ -2168,7 +2218,7 @@ function useBalanceAB() {
|
|
|
2168
2218
|
flag_source: flag.source || "unknown"
|
|
2169
2219
|
});
|
|
2170
2220
|
}, [track2, getBaseProps]);
|
|
2171
|
-
const trackFeatureFlagToggle = (0,
|
|
2221
|
+
const trackFeatureFlagToggle = (0, import_react18.useCallback)((flagKey, newValue, previousValue) => {
|
|
2172
2222
|
track2("feature_flag_toggled", {
|
|
2173
2223
|
...getBaseProps(),
|
|
2174
2224
|
flag_key: flagKey,
|
|
@@ -2176,7 +2226,7 @@ function useBalanceAB() {
|
|
|
2176
2226
|
previous_value: previousValue
|
|
2177
2227
|
});
|
|
2178
2228
|
}, [track2, getBaseProps]);
|
|
2179
|
-
const trackGoal = (0,
|
|
2229
|
+
const trackGoal = (0, import_react18.useCallback)((experimentId, goalName, value, context) => {
|
|
2180
2230
|
const variant = activeExperimentsRef.current.get(experimentId);
|
|
2181
2231
|
track2("experiment_goal", {
|
|
2182
2232
|
...getBaseProps(),
|
|
@@ -2187,7 +2237,7 @@ function useBalanceAB() {
|
|
|
2187
2237
|
...context
|
|
2188
2238
|
});
|
|
2189
2239
|
}, [track2, getBaseProps]);
|
|
2190
|
-
const trackSegment = (0,
|
|
2240
|
+
const trackSegment = (0, import_react18.useCallback)((segmentId, segmentName, criteria) => {
|
|
2191
2241
|
track2("segment_assigned", {
|
|
2192
2242
|
...getBaseProps(),
|
|
2193
2243
|
segment_id: segmentId,
|
|
@@ -2219,37 +2269,37 @@ function useBalanceAB() {
|
|
|
2219
2269
|
}
|
|
2220
2270
|
|
|
2221
2271
|
// src/react/useBalanceLive.ts
|
|
2222
|
-
var
|
|
2272
|
+
var import_react19 = require("react");
|
|
2223
2273
|
function useBalanceLive() {
|
|
2224
2274
|
const { track: track2 } = useBalance();
|
|
2225
|
-
const currentStreamRef = (0,
|
|
2226
|
-
const streamStartTimeRef = (0,
|
|
2227
|
-
const totalWatchTimeRef = (0,
|
|
2228
|
-
const messageCountRef = (0,
|
|
2229
|
-
const reactionCountRef = (0,
|
|
2230
|
-
const tipCountRef = (0,
|
|
2231
|
-
const lastMilestoneRef = (0,
|
|
2232
|
-
const watchTimeIntervalRef = (0,
|
|
2233
|
-
const getCurrentWatchTime = (0,
|
|
2275
|
+
const currentStreamRef = (0, import_react19.useRef)(null);
|
|
2276
|
+
const streamStartTimeRef = (0, import_react19.useRef)(null);
|
|
2277
|
+
const totalWatchTimeRef = (0, import_react19.useRef)(0);
|
|
2278
|
+
const messageCountRef = (0, import_react19.useRef)(0);
|
|
2279
|
+
const reactionCountRef = (0, import_react19.useRef)(0);
|
|
2280
|
+
const tipCountRef = (0, import_react19.useRef)(0);
|
|
2281
|
+
const lastMilestoneRef = (0, import_react19.useRef)(0);
|
|
2282
|
+
const watchTimeIntervalRef = (0, import_react19.useRef)(null);
|
|
2283
|
+
const getCurrentWatchTime = (0, import_react19.useCallback)(() => {
|
|
2234
2284
|
if (!streamStartTimeRef.current)
|
|
2235
2285
|
return 0;
|
|
2236
2286
|
return Math.round((Date.now() - streamStartTimeRef.current) / 1e3);
|
|
2237
2287
|
}, []);
|
|
2238
|
-
const getBaseProps = (0,
|
|
2288
|
+
const getBaseProps = (0, import_react19.useCallback)(() => ({
|
|
2239
2289
|
current_stream_id: currentStreamRef.current,
|
|
2240
2290
|
session_watch_time_seconds: totalWatchTimeRef.current + getCurrentWatchTime(),
|
|
2241
2291
|
session_messages: messageCountRef.current,
|
|
2242
2292
|
session_reactions: reactionCountRef.current,
|
|
2243
2293
|
session_tips: tipCountRef.current
|
|
2244
2294
|
}), [getCurrentWatchTime]);
|
|
2245
|
-
const getStats = (0,
|
|
2295
|
+
const getStats = (0, import_react19.useCallback)(() => ({
|
|
2246
2296
|
totalWatchTimeSeconds: totalWatchTimeRef.current + getCurrentWatchTime(),
|
|
2247
2297
|
messagesent: messageCountRef.current,
|
|
2248
2298
|
reactions: reactionCountRef.current,
|
|
2249
2299
|
tips: tipCountRef.current,
|
|
2250
2300
|
currentStreamId: currentStreamRef.current
|
|
2251
2301
|
}), [getCurrentWatchTime]);
|
|
2252
|
-
const reset = (0,
|
|
2302
|
+
const reset = (0, import_react19.useCallback)(() => {
|
|
2253
2303
|
if (watchTimeIntervalRef.current) {
|
|
2254
2304
|
clearInterval(watchTimeIntervalRef.current);
|
|
2255
2305
|
watchTimeIntervalRef.current = null;
|
|
@@ -2262,14 +2312,14 @@ function useBalanceLive() {
|
|
|
2262
2312
|
tipCountRef.current = 0;
|
|
2263
2313
|
lastMilestoneRef.current = 0;
|
|
2264
2314
|
}, []);
|
|
2265
|
-
(0,
|
|
2315
|
+
(0, import_react19.useEffect)(() => {
|
|
2266
2316
|
return () => {
|
|
2267
2317
|
if (watchTimeIntervalRef.current) {
|
|
2268
2318
|
clearInterval(watchTimeIntervalRef.current);
|
|
2269
2319
|
}
|
|
2270
2320
|
};
|
|
2271
2321
|
}, []);
|
|
2272
|
-
const joinStream = (0,
|
|
2322
|
+
const joinStream = (0, import_react19.useCallback)((streamId, streamTitle, artistId, metadata) => {
|
|
2273
2323
|
if (currentStreamRef.current && currentStreamRef.current !== streamId) {
|
|
2274
2324
|
totalWatchTimeRef.current += getCurrentWatchTime();
|
|
2275
2325
|
}
|
|
@@ -2298,7 +2348,7 @@ function useBalanceLive() {
|
|
|
2298
2348
|
}
|
|
2299
2349
|
}, 6e4);
|
|
2300
2350
|
}, [track2, getBaseProps, getCurrentWatchTime]);
|
|
2301
|
-
const leaveStream = (0,
|
|
2351
|
+
const leaveStream = (0, import_react19.useCallback)((streamId, reason = "user") => {
|
|
2302
2352
|
const watchTime = getCurrentWatchTime();
|
|
2303
2353
|
totalWatchTimeRef.current += watchTime;
|
|
2304
2354
|
if (watchTimeIntervalRef.current) {
|
|
@@ -2314,7 +2364,7 @@ function useBalanceLive() {
|
|
|
2314
2364
|
currentStreamRef.current = null;
|
|
2315
2365
|
streamStartTimeRef.current = null;
|
|
2316
2366
|
}, [track2, getBaseProps, getCurrentWatchTime]);
|
|
2317
|
-
const playbackStarted = (0,
|
|
2367
|
+
const playbackStarted = (0, import_react19.useCallback)((streamId, quality, latencyMs) => {
|
|
2318
2368
|
track2("stream_playback_started", {
|
|
2319
2369
|
...getBaseProps(),
|
|
2320
2370
|
stream_id: streamId,
|
|
@@ -2322,7 +2372,7 @@ function useBalanceLive() {
|
|
|
2322
2372
|
latency_ms: latencyMs
|
|
2323
2373
|
});
|
|
2324
2374
|
}, [track2, getBaseProps]);
|
|
2325
|
-
const buffering = (0,
|
|
2375
|
+
const buffering = (0, import_react19.useCallback)((streamId, durationMs, reason) => {
|
|
2326
2376
|
track2("stream_buffering", {
|
|
2327
2377
|
...getBaseProps(),
|
|
2328
2378
|
stream_id: streamId,
|
|
@@ -2330,7 +2380,7 @@ function useBalanceLive() {
|
|
|
2330
2380
|
buffer_reason: reason
|
|
2331
2381
|
});
|
|
2332
2382
|
}, [track2, getBaseProps]);
|
|
2333
|
-
const qualityChanged = (0,
|
|
2383
|
+
const qualityChanged = (0, import_react19.useCallback)((streamId, previousQuality, newQuality, isAutomatic) => {
|
|
2334
2384
|
track2("stream_quality_changed", {
|
|
2335
2385
|
...getBaseProps(),
|
|
2336
2386
|
stream_id: streamId,
|
|
@@ -2339,7 +2389,7 @@ function useBalanceLive() {
|
|
|
2339
2389
|
is_automatic: isAutomatic
|
|
2340
2390
|
});
|
|
2341
2391
|
}, [track2, getBaseProps]);
|
|
2342
|
-
const streamError = (0,
|
|
2392
|
+
const streamError = (0, import_react19.useCallback)((streamId, errorCode, errorMessage) => {
|
|
2343
2393
|
track2("stream_error", {
|
|
2344
2394
|
...getBaseProps(),
|
|
2345
2395
|
stream_id: streamId,
|
|
@@ -2347,7 +2397,7 @@ function useBalanceLive() {
|
|
|
2347
2397
|
error_message: errorMessage
|
|
2348
2398
|
});
|
|
2349
2399
|
}, [track2, getBaseProps]);
|
|
2350
|
-
const sendChat = (0,
|
|
2400
|
+
const sendChat = (0, import_react19.useCallback)((streamId, messageLength, hasEmoji) => {
|
|
2351
2401
|
messageCountRef.current += 1;
|
|
2352
2402
|
track2("stream_chat_sent", {
|
|
2353
2403
|
...getBaseProps(),
|
|
@@ -2356,7 +2406,7 @@ function useBalanceLive() {
|
|
|
2356
2406
|
has_emoji: hasEmoji
|
|
2357
2407
|
});
|
|
2358
2408
|
}, [track2, getBaseProps]);
|
|
2359
|
-
const react = (0,
|
|
2409
|
+
const react = (0, import_react19.useCallback)((streamId, reactionType) => {
|
|
2360
2410
|
reactionCountRef.current += 1;
|
|
2361
2411
|
track2("stream_reaction", {
|
|
2362
2412
|
...getBaseProps(),
|
|
@@ -2364,7 +2414,7 @@ function useBalanceLive() {
|
|
|
2364
2414
|
reaction_type: reactionType
|
|
2365
2415
|
});
|
|
2366
2416
|
}, [track2, getBaseProps]);
|
|
2367
|
-
const tip = (0,
|
|
2417
|
+
const tip = (0, import_react19.useCallback)((streamId, amount, currency, message) => {
|
|
2368
2418
|
tipCountRef.current += 1;
|
|
2369
2419
|
track2("stream_tip", {
|
|
2370
2420
|
...getBaseProps(),
|
|
@@ -2374,7 +2424,7 @@ function useBalanceLive() {
|
|
|
2374
2424
|
has_message: !!message
|
|
2375
2425
|
});
|
|
2376
2426
|
}, [track2, getBaseProps]);
|
|
2377
|
-
const gift = (0,
|
|
2427
|
+
const gift = (0, import_react19.useCallback)((streamId, giftType, recipientId, value) => {
|
|
2378
2428
|
track2("stream_gift", {
|
|
2379
2429
|
...getBaseProps(),
|
|
2380
2430
|
stream_id: streamId,
|
|
@@ -2383,7 +2433,7 @@ function useBalanceLive() {
|
|
|
2383
2433
|
gift_value: value
|
|
2384
2434
|
});
|
|
2385
2435
|
}, [track2, getBaseProps]);
|
|
2386
|
-
const pollVote = (0,
|
|
2436
|
+
const pollVote = (0, import_react19.useCallback)((streamId, pollId, optionId) => {
|
|
2387
2437
|
track2("stream_poll_vote", {
|
|
2388
2438
|
...getBaseProps(),
|
|
2389
2439
|
stream_id: streamId,
|
|
@@ -2391,7 +2441,7 @@ function useBalanceLive() {
|
|
|
2391
2441
|
option_id: optionId
|
|
2392
2442
|
});
|
|
2393
2443
|
}, [track2, getBaseProps]);
|
|
2394
|
-
const submitQuestion = (0,
|
|
2444
|
+
const submitQuestion = (0, import_react19.useCallback)((streamId, questionId, isAnonymous) => {
|
|
2395
2445
|
track2("stream_question_submitted", {
|
|
2396
2446
|
...getBaseProps(),
|
|
2397
2447
|
stream_id: streamId,
|
|
@@ -2399,35 +2449,35 @@ function useBalanceLive() {
|
|
|
2399
2449
|
is_anonymous: isAnonymous
|
|
2400
2450
|
});
|
|
2401
2451
|
}, [track2, getBaseProps]);
|
|
2402
|
-
const share = (0,
|
|
2452
|
+
const share = (0, import_react19.useCallback)((streamId, platform) => {
|
|
2403
2453
|
track2("stream_shared", {
|
|
2404
2454
|
...getBaseProps(),
|
|
2405
2455
|
stream_id: streamId,
|
|
2406
2456
|
share_platform: platform
|
|
2407
2457
|
});
|
|
2408
2458
|
}, [track2, getBaseProps]);
|
|
2409
|
-
const captureClip = (0,
|
|
2459
|
+
const captureClip = (0, import_react19.useCallback)((streamId, clipDurationSeconds) => {
|
|
2410
2460
|
track2("stream_clip_captured", {
|
|
2411
2461
|
...getBaseProps(),
|
|
2412
2462
|
stream_id: streamId,
|
|
2413
2463
|
clip_duration_seconds: clipDurationSeconds
|
|
2414
2464
|
});
|
|
2415
2465
|
}, [track2, getBaseProps]);
|
|
2416
|
-
const toggleFullscreen = (0,
|
|
2466
|
+
const toggleFullscreen = (0, import_react19.useCallback)((streamId, isFullscreen) => {
|
|
2417
2467
|
track2("stream_fullscreen_toggled", {
|
|
2418
2468
|
...getBaseProps(),
|
|
2419
2469
|
stream_id: streamId,
|
|
2420
2470
|
is_fullscreen: isFullscreen
|
|
2421
2471
|
});
|
|
2422
2472
|
}, [track2, getBaseProps]);
|
|
2423
|
-
const togglePiP = (0,
|
|
2473
|
+
const togglePiP = (0, import_react19.useCallback)((streamId, isPiP) => {
|
|
2424
2474
|
track2("stream_pip_toggled", {
|
|
2425
2475
|
...getBaseProps(),
|
|
2426
2476
|
stream_id: streamId,
|
|
2427
2477
|
is_pip: isPiP
|
|
2428
2478
|
});
|
|
2429
2479
|
}, [track2, getBaseProps]);
|
|
2430
|
-
const volumeChanged = (0,
|
|
2480
|
+
const volumeChanged = (0, import_react19.useCallback)((streamId, volume, isMuted) => {
|
|
2431
2481
|
track2("stream_volume_changed", {
|
|
2432
2482
|
...getBaseProps(),
|
|
2433
2483
|
stream_id: streamId,
|
|
@@ -2435,7 +2485,7 @@ function useBalanceLive() {
|
|
|
2435
2485
|
is_muted: isMuted
|
|
2436
2486
|
});
|
|
2437
2487
|
}, [track2, getBaseProps]);
|
|
2438
|
-
const viewerMilestone = (0,
|
|
2488
|
+
const viewerMilestone = (0, import_react19.useCallback)((streamId, minutesWatched) => {
|
|
2439
2489
|
track2("viewer_milestone", {
|
|
2440
2490
|
...getBaseProps(),
|
|
2441
2491
|
stream_id: streamId,
|
|
@@ -2471,34 +2521,34 @@ function useBalanceLive() {
|
|
|
2471
2521
|
}
|
|
2472
2522
|
|
|
2473
2523
|
// src/react/useBalanceSubscription.ts
|
|
2474
|
-
var
|
|
2524
|
+
var import_react20 = require("react");
|
|
2475
2525
|
function useBalanceSubscription() {
|
|
2476
2526
|
const { track: track2, purchase: purchase2 } = useBalance();
|
|
2477
|
-
const subscriptionCountRef = (0,
|
|
2478
|
-
const upgradeCountRef = (0,
|
|
2479
|
-
const downgradeCountRef = (0,
|
|
2480
|
-
const cancellationCountRef = (0,
|
|
2481
|
-
const totalRevenueRef = (0,
|
|
2482
|
-
const getBaseProps = (0,
|
|
2527
|
+
const subscriptionCountRef = (0, import_react20.useRef)(0);
|
|
2528
|
+
const upgradeCountRef = (0, import_react20.useRef)(0);
|
|
2529
|
+
const downgradeCountRef = (0, import_react20.useRef)(0);
|
|
2530
|
+
const cancellationCountRef = (0, import_react20.useRef)(0);
|
|
2531
|
+
const totalRevenueRef = (0, import_react20.useRef)(0);
|
|
2532
|
+
const getBaseProps = (0, import_react20.useCallback)(() => ({
|
|
2483
2533
|
session_subscriptions: subscriptionCountRef.current,
|
|
2484
2534
|
session_upgrades: upgradeCountRef.current,
|
|
2485
2535
|
session_cancellations: cancellationCountRef.current
|
|
2486
2536
|
}), []);
|
|
2487
|
-
const getStats = (0,
|
|
2537
|
+
const getStats = (0, import_react20.useCallback)(() => ({
|
|
2488
2538
|
subscriptions: subscriptionCountRef.current,
|
|
2489
2539
|
upgrades: upgradeCountRef.current,
|
|
2490
2540
|
downgrades: downgradeCountRef.current,
|
|
2491
2541
|
cancellations: cancellationCountRef.current,
|
|
2492
2542
|
totalRevenue: totalRevenueRef.current
|
|
2493
2543
|
}), []);
|
|
2494
|
-
const reset = (0,
|
|
2544
|
+
const reset = (0, import_react20.useCallback)(() => {
|
|
2495
2545
|
subscriptionCountRef.current = 0;
|
|
2496
2546
|
upgradeCountRef.current = 0;
|
|
2497
2547
|
downgradeCountRef.current = 0;
|
|
2498
2548
|
cancellationCountRef.current = 0;
|
|
2499
2549
|
totalRevenueRef.current = 0;
|
|
2500
2550
|
}, []);
|
|
2501
|
-
const subscribe = (0,
|
|
2551
|
+
const subscribe = (0, import_react20.useCallback)((planId, price, currency, interval, metadata) => {
|
|
2502
2552
|
subscriptionCountRef.current += 1;
|
|
2503
2553
|
totalRevenueRef.current += price;
|
|
2504
2554
|
purchase2(price, currency, {
|
|
@@ -2515,7 +2565,7 @@ function useBalanceSubscription() {
|
|
|
2515
2565
|
...metadata
|
|
2516
2566
|
});
|
|
2517
2567
|
}, [track2, purchase2, getBaseProps]);
|
|
2518
|
-
const startTrial = (0,
|
|
2568
|
+
const startTrial = (0, import_react20.useCallback)((planId, trialDays, willConvertTo) => {
|
|
2519
2569
|
track2("trial_started", {
|
|
2520
2570
|
...getBaseProps(),
|
|
2521
2571
|
plan_id: planId,
|
|
@@ -2523,7 +2573,7 @@ function useBalanceSubscription() {
|
|
|
2523
2573
|
will_convert_to: willConvertTo
|
|
2524
2574
|
});
|
|
2525
2575
|
}, [track2, getBaseProps]);
|
|
2526
|
-
const trialConverted = (0,
|
|
2576
|
+
const trialConverted = (0, import_react20.useCallback)((planId, price, currency) => {
|
|
2527
2577
|
subscriptionCountRef.current += 1;
|
|
2528
2578
|
totalRevenueRef.current += price;
|
|
2529
2579
|
purchase2(price, currency, {
|
|
@@ -2537,14 +2587,14 @@ function useBalanceSubscription() {
|
|
|
2537
2587
|
currency
|
|
2538
2588
|
});
|
|
2539
2589
|
}, [track2, purchase2, getBaseProps]);
|
|
2540
|
-
const trialExpired = (0,
|
|
2590
|
+
const trialExpired = (0, import_react20.useCallback)((planId, reason) => {
|
|
2541
2591
|
track2("trial_expired", {
|
|
2542
2592
|
...getBaseProps(),
|
|
2543
2593
|
plan_id: planId,
|
|
2544
2594
|
expiry_reason: reason
|
|
2545
2595
|
});
|
|
2546
2596
|
}, [track2, getBaseProps]);
|
|
2547
|
-
const upgrade = (0,
|
|
2597
|
+
const upgrade = (0, import_react20.useCallback)((fromPlanId, toPlanId, priceDifference, currency) => {
|
|
2548
2598
|
upgradeCountRef.current += 1;
|
|
2549
2599
|
totalRevenueRef.current += priceDifference;
|
|
2550
2600
|
track2("subscription_upgraded", {
|
|
@@ -2555,7 +2605,7 @@ function useBalanceSubscription() {
|
|
|
2555
2605
|
currency
|
|
2556
2606
|
});
|
|
2557
2607
|
}, [track2, getBaseProps]);
|
|
2558
|
-
const downgrade = (0,
|
|
2608
|
+
const downgrade = (0, import_react20.useCallback)((fromPlanId, toPlanId, priceDifference, currency, reason) => {
|
|
2559
2609
|
downgradeCountRef.current += 1;
|
|
2560
2610
|
track2("subscription_downgraded", {
|
|
2561
2611
|
...getBaseProps(),
|
|
@@ -2566,7 +2616,7 @@ function useBalanceSubscription() {
|
|
|
2566
2616
|
downgrade_reason: reason
|
|
2567
2617
|
});
|
|
2568
2618
|
}, [track2, getBaseProps]);
|
|
2569
|
-
const renewal = (0,
|
|
2619
|
+
const renewal = (0, import_react20.useCallback)((planId, price, currency, periodNumber) => {
|
|
2570
2620
|
totalRevenueRef.current += price;
|
|
2571
2621
|
purchase2(price, currency, {
|
|
2572
2622
|
type: "renewal",
|
|
@@ -2581,7 +2631,7 @@ function useBalanceSubscription() {
|
|
|
2581
2631
|
period_number: periodNumber
|
|
2582
2632
|
});
|
|
2583
2633
|
}, [track2, purchase2, getBaseProps]);
|
|
2584
|
-
const cancelInitiated = (0,
|
|
2634
|
+
const cancelInitiated = (0, import_react20.useCallback)((planId, reason, feedback) => {
|
|
2585
2635
|
track2("cancellation_initiated", {
|
|
2586
2636
|
...getBaseProps(),
|
|
2587
2637
|
plan_id: planId,
|
|
@@ -2589,7 +2639,7 @@ function useBalanceSubscription() {
|
|
|
2589
2639
|
feedback: feedback?.slice(0, 500)
|
|
2590
2640
|
});
|
|
2591
2641
|
}, [track2, getBaseProps]);
|
|
2592
|
-
const cancel = (0,
|
|
2642
|
+
const cancel = (0, import_react20.useCallback)((planId, reason, wasInTrial, periodsCompleted) => {
|
|
2593
2643
|
cancellationCountRef.current += 1;
|
|
2594
2644
|
track2("subscription_canceled", {
|
|
2595
2645
|
...getBaseProps(),
|
|
@@ -2599,7 +2649,7 @@ function useBalanceSubscription() {
|
|
|
2599
2649
|
periods_completed: periodsCompleted
|
|
2600
2650
|
});
|
|
2601
2651
|
}, [track2, getBaseProps]);
|
|
2602
|
-
const pause = (0,
|
|
2652
|
+
const pause = (0, import_react20.useCallback)((planId, pauseDurationDays, reason) => {
|
|
2603
2653
|
track2("subscription_paused", {
|
|
2604
2654
|
...getBaseProps(),
|
|
2605
2655
|
plan_id: planId,
|
|
@@ -2607,14 +2657,14 @@ function useBalanceSubscription() {
|
|
|
2607
2657
|
pause_reason: reason
|
|
2608
2658
|
});
|
|
2609
2659
|
}, [track2, getBaseProps]);
|
|
2610
|
-
const resume = (0,
|
|
2660
|
+
const resume = (0, import_react20.useCallback)((planId, pausedDays) => {
|
|
2611
2661
|
track2("subscription_resumed", {
|
|
2612
2662
|
...getBaseProps(),
|
|
2613
2663
|
plan_id: planId,
|
|
2614
2664
|
paused_days: pausedDays
|
|
2615
2665
|
});
|
|
2616
2666
|
}, [track2, getBaseProps]);
|
|
2617
|
-
const reactivate = (0,
|
|
2667
|
+
const reactivate = (0, import_react20.useCallback)((planId, daysSinceCanceled, winbackOffer) => {
|
|
2618
2668
|
subscriptionCountRef.current += 1;
|
|
2619
2669
|
track2("subscription_reactivated", {
|
|
2620
2670
|
...getBaseProps(),
|
|
@@ -2623,27 +2673,27 @@ function useBalanceSubscription() {
|
|
|
2623
2673
|
winback_offer: winbackOffer
|
|
2624
2674
|
});
|
|
2625
2675
|
}, [track2, getBaseProps]);
|
|
2626
|
-
const addPaymentMethod = (0,
|
|
2676
|
+
const addPaymentMethod = (0, import_react20.useCallback)((methodType, isDefault) => {
|
|
2627
2677
|
track2("payment_method_added", {
|
|
2628
2678
|
...getBaseProps(),
|
|
2629
2679
|
method_type: methodType,
|
|
2630
2680
|
is_default: isDefault
|
|
2631
2681
|
});
|
|
2632
2682
|
}, [track2, getBaseProps]);
|
|
2633
|
-
const updatePaymentMethod = (0,
|
|
2683
|
+
const updatePaymentMethod = (0, import_react20.useCallback)((oldMethodType, newMethodType) => {
|
|
2634
2684
|
track2("payment_method_updated", {
|
|
2635
2685
|
...getBaseProps(),
|
|
2636
2686
|
old_method_type: oldMethodType,
|
|
2637
2687
|
new_method_type: newMethodType
|
|
2638
2688
|
});
|
|
2639
2689
|
}, [track2, getBaseProps]);
|
|
2640
|
-
const removePaymentMethod = (0,
|
|
2690
|
+
const removePaymentMethod = (0, import_react20.useCallback)((methodType) => {
|
|
2641
2691
|
track2("payment_method_removed", {
|
|
2642
2692
|
...getBaseProps(),
|
|
2643
2693
|
method_type: methodType
|
|
2644
2694
|
});
|
|
2645
2695
|
}, [track2, getBaseProps]);
|
|
2646
|
-
const paymentFailed = (0,
|
|
2696
|
+
const paymentFailed = (0, import_react20.useCallback)((planId, amount, currency, failureReason, attemptNumber) => {
|
|
2647
2697
|
track2("payment_failed", {
|
|
2648
2698
|
...getBaseProps(),
|
|
2649
2699
|
plan_id: planId,
|
|
@@ -2653,7 +2703,7 @@ function useBalanceSubscription() {
|
|
|
2653
2703
|
attempt_number: attemptNumber
|
|
2654
2704
|
});
|
|
2655
2705
|
}, [track2, getBaseProps]);
|
|
2656
|
-
const paymentRecovered = (0,
|
|
2706
|
+
const paymentRecovered = (0, import_react20.useCallback)((planId, amount, currency, daysOverdue) => {
|
|
2657
2707
|
totalRevenueRef.current += amount;
|
|
2658
2708
|
track2("payment_recovered", {
|
|
2659
2709
|
...getBaseProps(),
|
|
@@ -2663,7 +2713,7 @@ function useBalanceSubscription() {
|
|
|
2663
2713
|
days_overdue: daysOverdue
|
|
2664
2714
|
});
|
|
2665
2715
|
}, [track2, getBaseProps]);
|
|
2666
|
-
const refund = (0,
|
|
2716
|
+
const refund = (0, import_react20.useCallback)((planId, amount, currency, reason, isPartial) => {
|
|
2667
2717
|
totalRevenueRef.current -= amount;
|
|
2668
2718
|
track2("refund_issued", {
|
|
2669
2719
|
...getBaseProps(),
|
|
@@ -2674,7 +2724,7 @@ function useBalanceSubscription() {
|
|
|
2674
2724
|
is_partial: isPartial
|
|
2675
2725
|
});
|
|
2676
2726
|
}, [track2, getBaseProps]);
|
|
2677
|
-
const applyPromo = (0,
|
|
2727
|
+
const applyPromo = (0, import_react20.useCallback)((promoCode, discountPercent, discountAmount, currency) => {
|
|
2678
2728
|
track2("promo_applied", {
|
|
2679
2729
|
...getBaseProps(),
|
|
2680
2730
|
promo_code: promoCode,
|
|
@@ -2683,7 +2733,7 @@ function useBalanceSubscription() {
|
|
|
2683
2733
|
currency
|
|
2684
2734
|
});
|
|
2685
2735
|
}, [track2, getBaseProps]);
|
|
2686
|
-
const giftPurchased = (0,
|
|
2736
|
+
const giftPurchased = (0, import_react20.useCallback)((planId, price, currency, recipientType) => {
|
|
2687
2737
|
totalRevenueRef.current += price;
|
|
2688
2738
|
purchase2(price, currency, {
|
|
2689
2739
|
type: "gift_subscription",
|
|
@@ -2697,7 +2747,7 @@ function useBalanceSubscription() {
|
|
|
2697
2747
|
recipient_type: recipientType
|
|
2698
2748
|
});
|
|
2699
2749
|
}, [track2, purchase2, getBaseProps]);
|
|
2700
|
-
const giftRedeemed = (0,
|
|
2750
|
+
const giftRedeemed = (0, import_react20.useCallback)((planId, giftCode) => {
|
|
2701
2751
|
subscriptionCountRef.current += 1;
|
|
2702
2752
|
track2("gift_subscription_redeemed", {
|
|
2703
2753
|
...getBaseProps(),
|
|
@@ -2705,12 +2755,12 @@ function useBalanceSubscription() {
|
|
|
2705
2755
|
gift_code: giftCode
|
|
2706
2756
|
});
|
|
2707
2757
|
}, [track2, getBaseProps]);
|
|
2708
|
-
const viewBillingPage = (0,
|
|
2758
|
+
const viewBillingPage = (0, import_react20.useCallback)(() => {
|
|
2709
2759
|
track2("billing_page_viewed", {
|
|
2710
2760
|
...getBaseProps()
|
|
2711
2761
|
});
|
|
2712
2762
|
}, [track2, getBaseProps]);
|
|
2713
|
-
const viewPricingPage = (0,
|
|
2763
|
+
const viewPricingPage = (0, import_react20.useCallback)((source) => {
|
|
2714
2764
|
track2("pricing_page_viewed", {
|
|
2715
2765
|
...getBaseProps(),
|
|
2716
2766
|
source
|
|
@@ -2754,15 +2804,15 @@ function useBalanceSubscription() {
|
|
|
2754
2804
|
}
|
|
2755
2805
|
|
|
2756
2806
|
// src/react/BalanceAnalytics.tsx
|
|
2757
|
-
var
|
|
2758
|
-
var
|
|
2807
|
+
var import_react21 = __toESM(require("react"));
|
|
2808
|
+
var import_navigation2 = require("next/navigation");
|
|
2759
2809
|
function BalanceAnalyticsInner() {
|
|
2760
|
-
const pathname = (0,
|
|
2761
|
-
const searchParams = (0,
|
|
2762
|
-
const isFirstRender = (0,
|
|
2763
|
-
const lastTrackedPath = (0,
|
|
2810
|
+
const pathname = (0, import_navigation2.usePathname)();
|
|
2811
|
+
const searchParams = (0, import_navigation2.useSearchParams)();
|
|
2812
|
+
const isFirstRender = (0, import_react21.useRef)(true);
|
|
2813
|
+
const lastTrackedPath = (0, import_react21.useRef)(null);
|
|
2764
2814
|
const balance = useBalanceOptional();
|
|
2765
|
-
(0,
|
|
2815
|
+
(0, import_react21.useEffect)(() => {
|
|
2766
2816
|
if (typeof window === "undefined")
|
|
2767
2817
|
return;
|
|
2768
2818
|
const pageTracker = balance?.page ?? window.balance?.page;
|
|
@@ -2794,11 +2844,14 @@ function BalanceAnalyticsInner() {
|
|
|
2794
2844
|
return null;
|
|
2795
2845
|
}
|
|
2796
2846
|
function BalanceAnalytics() {
|
|
2797
|
-
return /* @__PURE__ */
|
|
2847
|
+
return /* @__PURE__ */ import_react21.default.createElement(import_react21.Suspense, { fallback: null }, /* @__PURE__ */ import_react21.default.createElement(BalanceAnalyticsInner, null));
|
|
2798
2848
|
}
|
|
2799
2849
|
|
|
2850
|
+
// src/react/ConsentBridge.tsx
|
|
2851
|
+
var import_react22 = require("react");
|
|
2852
|
+
|
|
2800
2853
|
// src/react/useBalanceIdentify.ts
|
|
2801
|
-
var
|
|
2854
|
+
var import_react23 = require("react");
|
|
2802
2855
|
|
|
2803
2856
|
// src/storage/StorageManager.ts
|
|
2804
2857
|
var DEFAULT_PREFIX = "balance_";
|
|
@@ -3022,10 +3075,10 @@ function checkAnalyticsConsent() {
|
|
|
3022
3075
|
}
|
|
3023
3076
|
}
|
|
3024
3077
|
function useBalanceIdentify() {
|
|
3025
|
-
const pollIntervalRef = (0,
|
|
3026
|
-
const hasProcessedPending = (0,
|
|
3078
|
+
const pollIntervalRef = (0, import_react23.useRef)(null);
|
|
3079
|
+
const hasProcessedPending = (0, import_react23.useRef)(false);
|
|
3027
3080
|
const storageManager = typeof window !== "undefined" ? getStorageManager() : null;
|
|
3028
|
-
const getPendingIdentify = (0,
|
|
3081
|
+
const getPendingIdentify = (0, import_react23.useCallback)(() => {
|
|
3029
3082
|
if (!storageManager)
|
|
3030
3083
|
return null;
|
|
3031
3084
|
const pending = storageManager.getJSON(PENDING_IDENTIFY_KEY);
|
|
@@ -3037,7 +3090,7 @@ function useBalanceIdentify() {
|
|
|
3037
3090
|
}
|
|
3038
3091
|
return pending;
|
|
3039
3092
|
}, [storageManager]);
|
|
3040
|
-
const setPendingIdentify = (0,
|
|
3093
|
+
const setPendingIdentify = (0, import_react23.useCallback)((email, traits) => {
|
|
3041
3094
|
if (!storageManager)
|
|
3042
3095
|
return;
|
|
3043
3096
|
storageManager.setJSON(PENDING_IDENTIFY_KEY, {
|
|
@@ -3046,12 +3099,12 @@ function useBalanceIdentify() {
|
|
|
3046
3099
|
timestamp: Date.now()
|
|
3047
3100
|
});
|
|
3048
3101
|
}, [storageManager]);
|
|
3049
|
-
const clearPendingIdentify = (0,
|
|
3102
|
+
const clearPendingIdentify = (0, import_react23.useCallback)(() => {
|
|
3050
3103
|
if (!storageManager)
|
|
3051
3104
|
return;
|
|
3052
3105
|
storageManager.removeItem(PENDING_IDENTIFY_KEY);
|
|
3053
3106
|
}, [storageManager]);
|
|
3054
|
-
const identify2 = (0,
|
|
3107
|
+
const identify2 = (0, import_react23.useCallback)((email, traits) => {
|
|
3055
3108
|
const hasConsent2 = checkAnalyticsConsent();
|
|
3056
3109
|
if (!hasConsent2) {
|
|
3057
3110
|
console.log("[useBalanceIdentify] Skipping identify - user declined analytics consent");
|
|
@@ -3070,7 +3123,7 @@ function useBalanceIdentify() {
|
|
|
3070
3123
|
setPendingIdentify(email, traits);
|
|
3071
3124
|
return false;
|
|
3072
3125
|
}, [storageManager, clearPendingIdentify, setPendingIdentify]);
|
|
3073
|
-
const processPendingIdentify = (0,
|
|
3126
|
+
const processPendingIdentify = (0, import_react23.useCallback)(() => {
|
|
3074
3127
|
if (hasProcessedPending.current)
|
|
3075
3128
|
return;
|
|
3076
3129
|
const pending = getPendingIdentify();
|
|
@@ -3093,7 +3146,7 @@ function useBalanceIdentify() {
|
|
|
3093
3146
|
hasProcessedPending.current = true;
|
|
3094
3147
|
}
|
|
3095
3148
|
}, [getPendingIdentify, clearPendingIdentify, storageManager]);
|
|
3096
|
-
(0,
|
|
3149
|
+
(0, import_react23.useEffect)(() => {
|
|
3097
3150
|
processPendingIdentify();
|
|
3098
3151
|
const pending = getPendingIdentify();
|
|
3099
3152
|
if (pending && !hasProcessedPending.current) {
|