@wapitee/typhoonx-hydrogen 0.4.5 → 0.5.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.
@@ -1 +1 @@
1
- {"version":3,"file":"TyphoonX.d.ts","sourceRoot":"","sources":["../src/TyphoonX.tsx"],"names":[],"mappings":"AAKA,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA0BD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAK,EAAE,aAAa,sCAYpD"}
1
+ {"version":3,"file":"TyphoonX.d.ts","sourceRoot":"","sources":["../src/TyphoonX.tsx"],"names":[],"mappings":"AAKA,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA2BD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAK,EAAE,aAAa,sCAYpD"}
package/dist/TyphoonX.js CHANGED
@@ -19,7 +19,6 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
19
19
  const currentUrlRef = useRef(null);
20
20
  const previousUrlRef = useRef(null);
21
21
  useEffect(() => {
22
- let cancelled = false;
23
22
  const clientId = getOrCreateClientId(cookieDomain);
24
23
  const referrerFor = (url) => {
25
24
  if (currentUrlRef.current !== url) {
@@ -29,9 +28,8 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
29
28
  return previousUrlRef.current ?? document.referrer;
30
29
  };
31
30
  const send = (payload) => {
32
- if (cancelled || !canTrack()) {
31
+ if (!canTrack())
33
32
  return;
34
- }
35
33
  navigator.sendBeacon(COLLECT_ENDPOINT, new Blob([JSON.stringify(payload)], { type: 'application/json' }));
36
34
  };
37
35
  const shared = (url, currency) => ({
@@ -46,9 +44,8 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
46
44
  });
47
45
  subscribe('cart_viewed', (data) => {
48
46
  const { cart } = data;
49
- if (!cart?.lines) {
47
+ if (!cart?.lines)
50
48
  return;
51
- }
52
49
  const cartLines = flattenConnection(cart.lines);
53
50
  send({
54
51
  ...shared(data.url, data.shop?.currency),
@@ -65,9 +62,8 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
65
62
  });
66
63
  subscribe('collection_viewed', (data) => {
67
64
  const { collection } = data;
68
- if (!collection.id) {
65
+ if (!collection.id)
69
66
  return;
70
- }
71
67
  send({
72
68
  ...shared(data.url, data.shop?.currency),
73
69
  event: 'view_item_list',
@@ -83,9 +79,8 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
83
79
  });
84
80
  subscribe('product_added_to_cart', (data) => {
85
81
  const { currentLine } = data;
86
- if (currentLine === undefined) {
82
+ if (currentLine === undefined)
87
83
  return;
88
- }
89
84
  send({
90
85
  ...shared(window.location.href, data.shop?.currency),
91
86
  event: 'add_to_cart',
@@ -104,9 +99,8 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
104
99
  subscribe('product_removed_from_cart', (data) => {
105
100
  const { currentLine, prevLine } = data;
106
101
  const quantity = (prevLine?.quantity ?? 0) - (currentLine?.quantity ?? 0);
107
- if (prevLine === undefined || quantity <= 0) {
102
+ if (prevLine === undefined || quantity <= 0)
108
103
  return;
109
- }
110
104
  send({
111
105
  ...shared(window.location.href, data.shop?.currency),
112
106
  event: 'remove_from_cart',
@@ -125,9 +119,8 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
125
119
  });
126
120
  subscribe('product_viewed', (data) => {
127
121
  const product = data.products[0];
128
- if (product === undefined) {
122
+ if (product === undefined)
129
123
  return;
130
- }
131
124
  send({
132
125
  ...shared(data.url, data.shop?.currency),
133
126
  event: 'view_item',
@@ -143,10 +136,17 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
143
136
  value: product.price,
144
137
  });
145
138
  });
139
+ subscribe('search_viewed', (data) => {
140
+ const { searchTerm } = data;
141
+ if (!searchTerm)
142
+ return;
143
+ send({
144
+ ...shared(data.url, data.shop?.currency),
145
+ event: 'search',
146
+ search_term: searchTerm,
147
+ });
148
+ });
146
149
  ready();
147
- return () => {
148
- cancelled = true;
149
- };
150
- }, [canTrack, cookieDomain, merchantId, ready, shopId, subscribe]);
150
+ }, [cookieDomain, merchantId, shopId, canTrack, ready, subscribe]);
151
151
  return null;
152
152
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wapitee/typhoonx-hydrogen",
3
- "version": "0.4.5",
3
+ "version": "0.5.0",
4
4
  "description": "TyphoonX Hydrogen Analytics subscriber",
5
5
  "keywords": [
6
6
  "typhoonx",