@wapitee/typhoonx-hydrogen 0.1.0 → 0.2.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/README.md CHANGED
@@ -30,6 +30,18 @@ export function App() {
30
30
 
31
31
  The component renders `null`.
32
32
 
33
+ Also update `app/entry.server.tsx` to allow TyphoonX in the content security policy:
34
+
35
+ ```javascript
36
+ const {nonce, header, NonceProvider} = createContentSecurityPolicy({
37
+ shop: {
38
+ checkoutDomain: context.env.PUBLIC_CHECKOUT_DOMAIN,
39
+ storeDomain: context.env.PUBLIC_STORE_DOMAIN,
40
+ },
41
+ connectSrc: ['https://spell.typhoonx.io'], // add this line
42
+ });
43
+ ```
44
+
33
45
  ### Props
34
46
 
35
47
  | Prop | Type | Required | Description |
@@ -42,18 +54,6 @@ The component renders `null`.
42
54
  import type {TyphoonXProps} from '@wapitee/typhoonx-hydrogen';
43
55
  ```
44
56
 
45
- ### Events
46
-
47
- | Hydrogen | TyphoonX |
48
- | ----------------------- | ------------- |
49
- | `page_viewed` | `page_view` |
50
- | `product_viewed` | `view_item` |
51
- | `product_added_to_cart` | `add_to_cart` |
52
-
53
- Beacons go to `https://spell.typhoonx.io/api/v1/receive`. Checkout and purchase are out of scope.
54
-
55
- Sends are gated by Hydrogen `canTrack()` (Customer Privacy). The anonymous visitor id lives in `__typhoon_client_id` (one year, `SameSite=Lax`, `Secure` on HTTPS).
56
-
57
57
  ## License
58
58
 
59
59
  [MIT](./LICENSE) © Wapitee Interactive
package/dist/TyphoonX.js CHANGED
@@ -90,6 +90,28 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
90
90
  value: currentLine.cost.totalAmount.amount,
91
91
  });
92
92
  });
93
+ subscribe('product_removed_from_cart', (data) => {
94
+ const { currentLine, prevLine } = data;
95
+ const quantity = (prevLine?.quantity ?? 0) - (currentLine?.quantity ?? 0);
96
+ if (prevLine === undefined || quantity <= 0) {
97
+ return;
98
+ }
99
+ send({
100
+ ...shared(window.location.href, data.shop?.currency),
101
+ event: 'remove_from_cart',
102
+ items: [
103
+ {
104
+ item_brand: prevLine.merchandise.product.vendor,
105
+ item_id: parseGid(prevLine.merchandise.product.id).id,
106
+ item_name: prevLine.merchandise.product.title,
107
+ price: prevLine.merchandise.price.amount,
108
+ quantity,
109
+ },
110
+ ],
111
+ value: String(Number(prevLine.cost.totalAmount.amount)
112
+ - Number(currentLine?.cost.totalAmount.amount ?? 0)),
113
+ });
114
+ });
93
115
  ready();
94
116
  return () => {
95
117
  cancelled = true;
@@ -1,2 +1,18 @@
1
+ /**
2
+ * Returns the TyphoonX client id from the `__typhoon_client_id` cookie, or
3
+ * creates a new UUID and writes it when the cookie is missing.
4
+ *
5
+ * The cookie is scoped to `Path=/`, uses `SameSite=Lax`, and expires after
6
+ * one year. When `cookieDomain` is set, that value is used as the cookie
7
+ * `Domain` so the id can be shared across subdomains. The `Secure` flag is
8
+ * added automatically on HTTPS pages.
9
+ *
10
+ * @remarks
11
+ * This helper must run in the browser. It reads and writes `document.cookie`.
12
+ *
13
+ * @param cookieDomain - Optional cookie `Domain` attribute, typically the
14
+ * storefront apex domain.
15
+ * @returns The existing or newly created client id.
16
+ */
1
17
  export declare function getOrCreateClientId(cookieDomain?: string): string;
2
18
  //# sourceMappingURL=client-id.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client-id.d.ts","sourceRoot":"","sources":["../src/client-id.ts"],"names":[],"mappings":"AAGA,wBAAgB,mBAAmB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CA8BjE"}
1
+ {"version":3,"file":"client-id.d.ts","sourceRoot":"","sources":["../src/client-id.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CA8BjE"}
package/dist/client-id.js CHANGED
@@ -1,5 +1,23 @@
1
+ /** Cookie name that stores the anonymous TyphoonX client identifier. */
1
2
  const COOKIE = '__typhoon_client_id';
3
+ /** Cookie lifetime in seconds (365 days). */
2
4
  const MAX_AGE = 31_536_000;
5
+ /**
6
+ * Returns the TyphoonX client id from the `__typhoon_client_id` cookie, or
7
+ * creates a new UUID and writes it when the cookie is missing.
8
+ *
9
+ * The cookie is scoped to `Path=/`, uses `SameSite=Lax`, and expires after
10
+ * one year. When `cookieDomain` is set, that value is used as the cookie
11
+ * `Domain` so the id can be shared across subdomains. The `Secure` flag is
12
+ * added automatically on HTTPS pages.
13
+ *
14
+ * @remarks
15
+ * This helper must run in the browser. It reads and writes `document.cookie`.
16
+ *
17
+ * @param cookieDomain - Optional cookie `Domain` attribute, typically the
18
+ * storefront apex domain.
19
+ * @returns The existing or newly created client id.
20
+ */
3
21
  export function getOrCreateClientId(cookieDomain) {
4
22
  const prefix = `${COOKIE}=`;
5
23
  const existing = document.cookie
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wapitee/typhoonx-hydrogen",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "TyphoonX Hydrogen Analytics subscriber",
5
5
  "homepage": "https://github.com/Wapitee-Interactive-Marketing-Limited/typhoonx-js/tree/main/packages/typhoonx-hydrogen",
6
6
  "bugs": {