@wapitee/typhoonx-hydrogen 0.4.2 → 0.4.3

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