@wapitee/typhoonx-hydrogen 0.4.3 → 0.4.5
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/TyphoonX.js +7 -11
- package/package.json +1 -1
package/dist/TyphoonX.js
CHANGED
|
@@ -16,18 +16,11 @@ export default function TyphoonX(props) {
|
|
|
16
16
|
function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
|
|
17
17
|
const { canTrack, register, subscribe } = useAnalytics();
|
|
18
18
|
const { ready } = register('TyphoonX');
|
|
19
|
-
const canTrackRef = useRef(canTrack);
|
|
20
|
-
const configRef = useRef({ cookieDomain, merchantId, shopId });
|
|
21
|
-
canTrackRef.current = canTrack;
|
|
22
|
-
configRef.current = { cookieDomain, merchantId, shopId };
|
|
23
19
|
const currentUrlRef = useRef(null);
|
|
24
20
|
const previousUrlRef = useRef(null);
|
|
25
|
-
const startedRef = useRef(false);
|
|
26
21
|
useEffect(() => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
startedRef.current = true;
|
|
30
|
-
const clientId = getOrCreateClientId(configRef.current.cookieDomain);
|
|
22
|
+
let cancelled = false;
|
|
23
|
+
const clientId = getOrCreateClientId(cookieDomain);
|
|
31
24
|
const referrerFor = (url) => {
|
|
32
25
|
if (currentUrlRef.current !== url) {
|
|
33
26
|
previousUrlRef.current = currentUrlRef.current;
|
|
@@ -36,7 +29,7 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
|
|
|
36
29
|
return previousUrlRef.current ?? document.referrer;
|
|
37
30
|
};
|
|
38
31
|
const send = (payload) => {
|
|
39
|
-
if (!
|
|
32
|
+
if (cancelled || !canTrack()) {
|
|
40
33
|
return;
|
|
41
34
|
}
|
|
42
35
|
navigator.sendBeacon(COLLECT_ENDPOINT, new Blob([JSON.stringify(payload)], { type: 'application/json' }));
|
|
@@ -151,6 +144,9 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
|
|
|
151
144
|
});
|
|
152
145
|
});
|
|
153
146
|
ready();
|
|
154
|
-
|
|
147
|
+
return () => {
|
|
148
|
+
cancelled = true;
|
|
149
|
+
};
|
|
150
|
+
}, [canTrack, cookieDomain, merchantId, ready, shopId, subscribe]);
|
|
155
151
|
return null;
|
|
156
152
|
}
|