@wapitee/typhoonx-hydrogen 0.6.0 → 0.7.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
@@ -48,6 +48,10 @@ const {nonce, header, NonceProvider} = createContentSecurityPolicy({
48
48
  | `shopId` | `string` | yes | Shopify store ID |
49
49
  | `cookieDomain` | `string` | no | Cookie `Domain` for a first-party client id. Defaults to the current hostname's apex domain (e.g. `.example.com`) |
50
50
 
51
+ ### Meta Pixel
52
+
53
+ If the storefront runs Meta Pixel, every event also carries its `_fbp` cookie as `fbp` and its `_fbc` cookie as `fbc`. When `_fbc` is not set yet but the page URL has `fbclid`, `fbc` is built as `fb.1.<timestamp>.<fbclid>`. Missing values are omitted.
54
+
51
55
  ## License
52
56
 
53
57
  [MIT](./LICENSE) © Wapitee Interactive
@@ -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;AAmCD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAK,EAAE,aAAa,sCAqBpD"}
1
+ {"version":3,"file":"TyphoonX.d.ts","sourceRoot":"","sources":["../src/TyphoonX.tsx"],"names":[],"mappings":"AAMA,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAqCD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAK,EAAE,aAAa,sCAuBpD"}
package/dist/TyphoonX.js CHANGED
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { flattenConnection, parseGid, useAnalytics } from '@shopify/hydrogen';
3
3
  import { useEffect, useRef, useState } from 'react';
4
4
  import { getOrCreateClientId, hasClientId } from './client-id.js';
5
+ import { getMetaPixelIds } from './meta-pixel.js';
5
6
  const COLLECT_ENDPOINT = 'https://spell.typhoonx.io/api/v1/receive';
6
7
  export default function TyphoonX(props) {
7
8
  const { subscribe } = useAnalytics();
@@ -59,6 +60,7 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
59
60
  timestamp: new Date().toISOString(),
60
61
  user_agent: window.navigator.userAgent,
61
62
  ...(currency === undefined ? {} : { currency }),
63
+ ...getMetaPixelIds(url),
62
64
  });
63
65
  subscribe('cart_viewed', (data) => {
64
66
  const { cart } = data;
@@ -149,8 +151,8 @@ function TyphoonXClient({ cookieDomain, merchantId, shopId }) {
149
151
  quantity,
150
152
  },
151
153
  ],
152
- value: String(Number(prevLine.cost.totalAmount.amount)
153
- - Number(currentLine?.cost.totalAmount.amount ?? 0)),
154
+ value: String(Number(prevLine.cost.totalAmount.amount) -
155
+ Number(currentLine?.cost.totalAmount.amount ?? 0)),
154
156
  });
155
157
  });
156
158
  subscribe('product_viewed', (data) => {
@@ -0,0 +1,7 @@
1
+ export interface MetaPixelIds {
2
+ fbc?: string;
3
+ fbp?: string;
4
+ }
5
+ /** Meta Pixel `_fbp` / `_fbc` cookies, with `_fbc` falling back to `url`'s `fbclid`. */
6
+ export declare function getMetaPixelIds(url: string): MetaPixelIds;
7
+ //# sourceMappingURL=meta-pixel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta-pixel.d.ts","sourceRoot":"","sources":["../src/meta-pixel.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wFAAwF;AACxF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAQzD"}
@@ -0,0 +1,23 @@
1
+ import CookieLib from 'universal-cookie';
2
+ // Runtime default export is the class.
3
+ const cookies = new CookieLib();
4
+ /** Meta Pixel `_fbp` / `_fbc` cookies, with `_fbc` falling back to `url`'s `fbclid`. */
5
+ export function getMetaPixelIds(url) {
6
+ const fbp = cookies.get('_fbp', { doNotParse: true });
7
+ const fbc = cookies.get('_fbc', { doNotParse: true }) ?? fbcFromUrl(url);
8
+ return {
9
+ ...(fbc === undefined ? {} : { fbc }),
10
+ ...(fbp === undefined ? {} : { fbp }),
11
+ };
12
+ }
13
+ function fbcFromUrl(url) {
14
+ let fbclid;
15
+ try {
16
+ fbclid = new URL(url).searchParams.get('fbclid');
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ // Meta specifies subdomain index 1 for an `_fbc` built outside the Pixel.
22
+ return fbclid ? `fb.1.${String(Date.now())}.${fbclid}` : undefined;
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wapitee/typhoonx-hydrogen",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "TyphoonX Hydrogen Analytics subscriber",
5
5
  "keywords": [
6
6
  "typhoonx",