@instockng/storefront-ui 1.0.70 → 1.0.72
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/contexts/CartContext.d.ts.map +1 -1
- package/dist/hooks/usePageTracking.d.ts +1 -1
- package/dist/hooks/usePageTracking.d.ts.map +1 -1
- package/dist/index.mjs +65 -63
- package/dist/index100.mjs +174 -28
- package/dist/index101.mjs +53 -2
- package/dist/index102.mjs +69 -2
- package/dist/index106.mjs +2 -2
- package/dist/index107.mjs +2 -2
- package/dist/index140.mjs +1 -1
- package/dist/index142.mjs +2 -21
- package/dist/index143.mjs +19 -54
- package/dist/index144.mjs +55 -28
- package/dist/index145.mjs +28 -6
- package/dist/index146.mjs +6 -51
- package/dist/index147.mjs +51 -5
- package/dist/index148.mjs +6 -12
- package/dist/index149.mjs +12 -7
- package/dist/index15.mjs +1 -1
- package/dist/index150.mjs +6 -27
- package/dist/index151.mjs +28 -2
- package/dist/index152.mjs +2 -70
- package/dist/index153.mjs +67 -164
- package/dist/index154.mjs +167 -2
- package/dist/index158.mjs +1 -1
- package/dist/index159.mjs +1 -1
- package/dist/index160.mjs +1 -1
- package/dist/index161.mjs +1 -1
- package/dist/index162.mjs +1 -1
- package/dist/index164.mjs +3 -3
- package/dist/index165.mjs +1 -1
- package/dist/index167.mjs +2 -2
- package/dist/index168.mjs +1 -1
- package/dist/index173.mjs +2 -2
- package/dist/index175.mjs +1 -1
- package/dist/index177.mjs +2 -2
- package/dist/index178.mjs +5 -5
- package/dist/index181.mjs +1 -1
- package/dist/index184.mjs +1 -1
- package/dist/index187.mjs +1 -1
- package/dist/index188.mjs +1 -1
- package/dist/index192.mjs +1 -1
- package/dist/index194.mjs +1 -1
- package/dist/index198.mjs +1 -1
- package/dist/index2.mjs +1 -1
- package/dist/index200.mjs +1 -1
- package/dist/index213.mjs +2 -13
- package/dist/index214.mjs +2 -7
- package/dist/index215.mjs +2 -31
- package/dist/index216.mjs +2 -11
- package/dist/index217.mjs +2 -4
- package/dist/index218.mjs +2 -4
- package/dist/index219.mjs +2 -12
- package/dist/index22.mjs +10 -6
- package/dist/index220.mjs +2 -5
- package/dist/index221.mjs +108 -33
- package/dist/index222.mjs +2 -31
- package/dist/index223.mjs +2 -28
- package/dist/index224.mjs +34 -58
- package/dist/index225.mjs +2 -2
- package/dist/index226.mjs +2 -2
- package/dist/index227.mjs +244 -2
- package/dist/index228.mjs +2 -2
- package/dist/index229.mjs +28 -103
- package/dist/index23.mjs +13 -14
- package/dist/index230.mjs +65 -2
- package/dist/index231.mjs +25 -2
- package/dist/index232.mjs +2 -2
- package/dist/index233.mjs +2 -2
- package/dist/index234.mjs +2 -2
- package/dist/index236.mjs +2 -37
- package/dist/index237.mjs +2 -2
- package/dist/index238.mjs +2 -244
- package/dist/index239.mjs +2 -2
- package/dist/index240.mjs +30 -32
- package/dist/index241.mjs +10 -64
- package/dist/index242.mjs +3 -24
- package/dist/index243.mjs +4 -2
- package/dist/index244.mjs +13 -2
- package/dist/index245.mjs +7 -2
- package/dist/index246.mjs +12 -2
- package/dist/index247.mjs +5 -2
- package/dist/index248.mjs +33 -2
- package/dist/index249.mjs +31 -2
- package/dist/index250.mjs +28 -2
- package/dist/index251.mjs +61 -2
- package/dist/index253.mjs +2 -2
- package/dist/index256.mjs +2 -3
- package/dist/index257.mjs +2 -2
- package/dist/index258.mjs +18 -2
- package/dist/index259.mjs +46 -16
- package/dist/index260.mjs +2 -13
- package/dist/index261.mjs +2 -6
- package/dist/index262.mjs +2 -30
- package/dist/index264.mjs +91 -2
- package/dist/index265.mjs +2 -2
- package/dist/index266.mjs +3 -2
- package/dist/index267.mjs +2 -2
- package/dist/index268.mjs +2 -91
- package/dist/index269.mjs +17 -2
- package/dist/index27.mjs +17 -17
- package/dist/index270.mjs +12 -17
- package/dist/index271.mjs +6 -47
- package/dist/index272.mjs +30 -2
- package/dist/index273.mjs +2 -2
- package/dist/index275.mjs +2 -2
- package/dist/index28.mjs +58 -47
- package/dist/index29.mjs +11 -11
- package/dist/index3.mjs +141 -123
- package/dist/index30.mjs +4 -4
- package/dist/index31.mjs +5 -5
- package/dist/index33.mjs +21 -20
- package/dist/index35.mjs +36 -29
- package/dist/index36.mjs +8 -25
- package/dist/index37.mjs +1 -1
- package/dist/index38.mjs +26 -9
- package/dist/index39.mjs +9 -9
- package/dist/index4.mjs +59 -46
- package/dist/index40.mjs +2 -2
- package/dist/index42.mjs +2 -2
- package/dist/index45.mjs +3 -3
- package/dist/index46.mjs +1 -1
- package/dist/index49.mjs +1 -1
- package/dist/index54.mjs +17 -17
- package/dist/index55.mjs +2 -2
- package/dist/index56.mjs +1 -1
- package/dist/index57.mjs +1 -1
- package/dist/index58.mjs +1 -1
- package/dist/index59.mjs +1 -1
- package/dist/index6.mjs +7 -7
- package/dist/index60.mjs +1 -1
- package/dist/index61.mjs +1 -1
- package/dist/index62.mjs +1 -1
- package/dist/index63.mjs +1 -1
- package/dist/index64.mjs +1 -1
- package/dist/index65.mjs +1 -1
- package/dist/index66.mjs +1 -1
- package/dist/index67.mjs +1 -1
- package/dist/index68.mjs +23 -4
- package/dist/index69.mjs +149 -19
- package/dist/index7.mjs +1 -1
- package/dist/index70.mjs +2 -24
- package/dist/index71.mjs +19 -149
- package/dist/index72.mjs +75 -2
- package/dist/index73.mjs +14 -74
- package/dist/index74.mjs +62 -14
- package/dist/index75.mjs +4 -62
- package/dist/index76.mjs +2 -34
- package/dist/index77.mjs +5 -42
- package/dist/index78.mjs +1129 -230
- package/dist/index79.mjs +19 -5
- package/dist/index80.mjs +48 -127
- package/dist/index81.mjs +32 -67
- package/dist/index82.mjs +2 -87
- package/dist/index83.mjs +2 -29
- package/dist/index84.mjs +34 -9
- package/dist/index85.mjs +39 -71
- package/dist/index86.mjs +234 -3
- package/dist/index87.mjs +6 -2
- package/dist/index88.mjs +128 -77
- package/dist/index89.mjs +67 -53
- package/dist/index90.mjs +86 -5
- package/dist/index91.mjs +28 -4
- package/dist/index92.mjs +7 -177
- package/dist/index93.mjs +72 -50
- package/dist/index94.mjs +4 -69
- package/dist/index95.mjs +2 -2
- package/dist/index96.mjs +82 -5
- package/dist/index97.mjs +53 -1133
- package/dist/index98.mjs +5 -19
- package/dist/index99.mjs +4 -54
- package/dist/lib/utils.d.ts +5 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/providers/MetaPixelProvider.d.ts +3 -2
- package/dist/providers/MetaPixelProvider.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/contexts/CartContext.tsx +50 -22
- package/src/hooks/usePageTracking.ts +3 -3
- package/src/lib/utils.ts +11 -0
- package/src/providers/MetaPixelProvider.tsx +20 -6
package/dist/index98.mjs
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var o;
|
|
7
|
-
function d() {
|
|
8
|
-
return o ? e : (o = 1, function(t) {
|
|
9
|
-
Object.defineProperty(t, "__esModule", {
|
|
10
|
-
value: !0
|
|
11
|
-
}), Object.defineProperty(t, "RouterContext", {
|
|
12
|
-
enumerable: !0,
|
|
13
|
-
get: function() {
|
|
14
|
-
return r;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
const r = (/* @__PURE__ */ n._(u)).default.createContext(null);
|
|
18
|
-
process.env.NODE_ENV !== "production" && (r.displayName = "RouterContext");
|
|
19
|
-
}(e), e);
|
|
2
|
+
function u(n) {
|
|
3
|
+
return function(r) {
|
|
4
|
+
return n.apply(null, r);
|
|
5
|
+
};
|
|
20
6
|
}
|
|
21
7
|
export {
|
|
22
|
-
|
|
8
|
+
u as default
|
|
23
9
|
};
|
package/dist/index99.mjs
CHANGED
|
@@ -1,58 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function m() {
|
|
6
|
-
return u ? o : (u = 1, function(i) {
|
|
7
|
-
Object.defineProperty(i, "__esModule", {
|
|
8
|
-
value: !0
|
|
9
|
-
});
|
|
10
|
-
function f(e, r) {
|
|
11
|
-
for (var t in r) Object.defineProperty(e, t, {
|
|
12
|
-
enumerable: !0,
|
|
13
|
-
get: r[t]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
f(i, {
|
|
17
|
-
/**
|
|
18
|
-
* Checks whether the given value is a NextError.
|
|
19
|
-
* This can be used to print a more detailed error message with properties like `code` & `digest`.
|
|
20
|
-
*/
|
|
21
|
-
default: function() {
|
|
22
|
-
return s;
|
|
23
|
-
},
|
|
24
|
-
getProperError: function() {
|
|
25
|
-
return a;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
const c = p();
|
|
29
|
-
function s(e) {
|
|
30
|
-
return typeof e == "object" && e !== null && "name" in e && "message" in e;
|
|
31
|
-
}
|
|
32
|
-
function d(e) {
|
|
33
|
-
const r = /* @__PURE__ */ new WeakSet();
|
|
34
|
-
return JSON.stringify(e, (t, n) => {
|
|
35
|
-
if (typeof n == "object" && n !== null) {
|
|
36
|
-
if (r.has(n))
|
|
37
|
-
return "[Circular]";
|
|
38
|
-
r.add(n);
|
|
39
|
-
}
|
|
40
|
-
return n;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
function a(e) {
|
|
44
|
-
if (s(e))
|
|
45
|
-
return e;
|
|
46
|
-
if (process.env.NODE_ENV === "development") {
|
|
47
|
-
if (typeof e > "u")
|
|
48
|
-
return new Error("An undefined error was thrown, see here for more info: https://nextjs.org/docs/messages/threw-undefined");
|
|
49
|
-
if (e === null)
|
|
50
|
-
return new Error("A null error was thrown, see here for more info: https://nextjs.org/docs/messages/threw-undefined");
|
|
51
|
-
}
|
|
52
|
-
return new Error((0, c.isPlainObject)(e) ? d(e) : e + "");
|
|
53
|
-
}
|
|
54
|
-
}(o), o);
|
|
2
|
+
import i from "./index86.mjs";
|
|
3
|
+
function o(r) {
|
|
4
|
+
return i.isObject(r) && r.isAxiosError === !0;
|
|
55
5
|
}
|
|
56
6
|
export {
|
|
57
|
-
|
|
7
|
+
o as default
|
|
58
8
|
};
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -20,4 +20,9 @@ export declare function getTikTokCookies(): {
|
|
|
20
20
|
ttp: string | undefined;
|
|
21
21
|
ttclid: string | undefined;
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Generate a unique event ID for deduplication
|
|
25
|
+
* Matches the format used by the backend: {type}_{id}_{suffix}
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateClientEventId(type: 'cart' | 'order', id: string, suffix?: string): string;
|
|
23
28
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAQ,MAAM,MAAM,CAAA;AAG5C,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAOrD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAOtD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAS1D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAUrD;AAsBD;;;GAGG;AACH,wBAAgB,YAAY,IAAI;IAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAKnF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI;IAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAK1F"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAQ,MAAM,MAAM,CAAA;AAG5C,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAOrD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAOtD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAS1D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAUrD;AAsBD;;;GAGG;AACH,wBAAgB,YAAY,IAAI;IAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAKnF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI;IAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAK1F;AACD;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,GAAG,OAAO,EACtB,EAAE,EAAE,MAAM,EACV,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CAER"}
|
|
@@ -19,7 +19,7 @@ interface MetaPixelContextValue {
|
|
|
19
19
|
/**
|
|
20
20
|
* Track a page view
|
|
21
21
|
*/
|
|
22
|
-
trackPageView: () => void;
|
|
22
|
+
trackPageView: (eventID?: string) => void;
|
|
23
23
|
/**
|
|
24
24
|
* Track product view
|
|
25
25
|
*/
|
|
@@ -37,9 +37,10 @@ interface MetaPixelContextValue {
|
|
|
37
37
|
* Track begin checkout event
|
|
38
38
|
* @param cartTotal - Total cart value
|
|
39
39
|
* @param itemCount - Number of items
|
|
40
|
+
* @param contents - Array of items in cart
|
|
40
41
|
* @param eventID - Optional event ID for deduplication with CAPI
|
|
41
42
|
*/
|
|
42
|
-
trackInitiateCheckout: (cartTotal: number, itemCount: number, eventID?: string) => void;
|
|
43
|
+
trackInitiateCheckout: (cartTotal: number, itemCount: number, contents?: PurchaseItem[], eventID?: string) => void;
|
|
43
44
|
/**
|
|
44
45
|
* Track purchase event
|
|
45
46
|
* @param orderTotal - Total order value
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaPixelProvider.d.ts","sourceRoot":"","sources":["../../src/providers/MetaPixelProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAkD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvF,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,qBAAqB;IAC7B;;OAEG;IACH,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAEjF;;OAEG;IACH,aAAa,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"MetaPixelProvider.d.ts","sourceRoot":"","sources":["../../src/providers/MetaPixelProvider.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAkD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvF,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,qBAAqB;IAC7B;;OAEG;IACH,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAEjF;;OAEG;IACH,aAAa,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1C;;OAEG;IACH,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAEpG;;;;;;;OAOG;IACH,cAAc,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAEpH;;;;;;OAMG;IACH,qBAAqB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,YAAY,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAEnH;;;;;;;OAOG;IACH,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAExH;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;CACxB;AAID,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,SAAS,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,sBAAsB,2CA+IrF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,0BAQ3B;AAED,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instockng/storefront-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.72",
|
|
4
4
|
"description": "Pre-built UI components for OMS e-commerce sites",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"author": "Ola Wale",
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@instockng/api-client": "^1.0.
|
|
48
|
+
"@instockng/api-client": "^1.0.27",
|
|
49
49
|
"class-variance-authority": "^0.7.1",
|
|
50
50
|
"clsx": "^2.1.0",
|
|
51
51
|
"react-facebook-pixel": "^1.0.4",
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
useApplyDiscount,
|
|
20
20
|
useRemoveDiscount,
|
|
21
21
|
useCheckoutCart,
|
|
22
|
+
useInitiateCheckout,
|
|
22
23
|
queryKeys,
|
|
23
24
|
type Cart,
|
|
24
25
|
} from '@instockng/api-client';
|
|
@@ -26,7 +27,7 @@ import { useQueryClient } from '@tanstack/react-query';
|
|
|
26
27
|
import { ShoppingCart } from '../components/ShoppingCart';
|
|
27
28
|
import { useMetaPixel } from '../providers/MetaPixelProvider';
|
|
28
29
|
import { useTikTokPixel } from '../providers/TikTokPixelProvider';
|
|
29
|
-
import { getFbCookies, getTikTokCookies } from '../lib/utils';
|
|
30
|
+
import { getFbCookies, getTikTokCookies, generateClientEventId } from '../lib/utils';
|
|
30
31
|
|
|
31
32
|
const CART_ID_KEY = 'oms_cart_id';
|
|
32
33
|
|
|
@@ -242,6 +243,8 @@ export function CartProvider({ children, brandSlug, initialCartId, shoppingCartP
|
|
|
242
243
|
},
|
|
243
244
|
});
|
|
244
245
|
|
|
246
|
+
const initiateCheckoutMutation = useInitiateCheckout(cartId || '');
|
|
247
|
+
|
|
245
248
|
// Store cartId in localStorage when it changes
|
|
246
249
|
useEffect(() => {
|
|
247
250
|
if (cartId && typeof window !== 'undefined') {
|
|
@@ -285,13 +288,13 @@ export function CartProvider({ children, brandSlug, initialCartId, shoppingCartP
|
|
|
285
288
|
const eventID = `cart_${cartId}_item_${addedItem.id}`;
|
|
286
289
|
|
|
287
290
|
// Track AddToCart event with Meta Pixel and matching event ID
|
|
288
|
-
trackMetaAddToCart(
|
|
291
|
+
trackMetaAddToCart(sku, productName, price, quantity, eventID);
|
|
289
292
|
|
|
290
293
|
// Track AddToCart event with TikTok Pixel and matching event ID
|
|
291
294
|
trackTikTokAddToCart(productSlug, productName, price, quantity, eventID);
|
|
292
295
|
} else {
|
|
293
296
|
// Fallback without event ID if item not found
|
|
294
|
-
trackMetaAddToCart(
|
|
297
|
+
trackMetaAddToCart(sku, productName, price, quantity);
|
|
295
298
|
trackTikTokAddToCart(productSlug, productName, price, quantity);
|
|
296
299
|
}
|
|
297
300
|
},
|
|
@@ -355,31 +358,56 @@ export function CartProvider({ children, brandSlug, initialCartId, shoppingCartP
|
|
|
355
358
|
setIsOpen(false);
|
|
356
359
|
}, []);
|
|
357
360
|
|
|
358
|
-
const trackCheckoutInitiated = useCallback(() => {
|
|
359
|
-
if (!cart || !
|
|
361
|
+
const trackCheckoutInitiated = useCallback(async () => {
|
|
362
|
+
if (!cart || !cart.pricing) return;
|
|
360
363
|
|
|
361
|
-
|
|
362
|
-
|
|
364
|
+
try {
|
|
365
|
+
const eventID = generateClientEventId('cart', cart.id, 'checkout');
|
|
366
|
+
const cartTotal = cart.pricing.total;
|
|
367
|
+
const itemCount = cart.items.reduce((sum, item) => sum + item.quantity, 0);
|
|
363
368
|
|
|
364
|
-
|
|
365
|
-
|
|
369
|
+
// Prepare rich data for Pixel and CAPI
|
|
370
|
+
const contents = cart.items.map(item => ({
|
|
371
|
+
id: item.variant.sku,
|
|
372
|
+
quantity: item.quantity,
|
|
373
|
+
item_price: Number(item.variant.price),
|
|
374
|
+
}));
|
|
366
375
|
|
|
367
|
-
|
|
368
|
-
|
|
376
|
+
// 1. Track Client-Side Pixel with Rich Data
|
|
377
|
+
if (trackMetaInitiateCheckout) {
|
|
378
|
+
trackMetaInitiateCheckout(cartTotal, itemCount, contents, eventID);
|
|
379
|
+
}
|
|
369
380
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
381
|
+
// 2. Trigger Server-Side CAPI via API Client hook
|
|
382
|
+
// We fire and forget this request to not block the UI
|
|
383
|
+
if (cart.brand.metaPixelId || cart.brand.tiktokPixelId) {
|
|
384
|
+
// Get attribution cookies
|
|
385
|
+
const { fbc, fbp } = getFbCookies();
|
|
386
|
+
const { ttp, ttclid } = getTikTokCookies();
|
|
387
|
+
|
|
388
|
+
initiateCheckoutMutation.mutate({
|
|
389
|
+
email: cart.customerEmail,
|
|
390
|
+
phone: cart.customerPhone,
|
|
391
|
+
fbc,
|
|
392
|
+
fbp,
|
|
393
|
+
ttp,
|
|
394
|
+
ttclid,
|
|
395
|
+
});
|
|
396
|
+
}
|
|
376
397
|
|
|
377
|
-
|
|
378
|
-
|
|
398
|
+
// Track TikTok Event
|
|
399
|
+
if (trackTikTokInitiateCheckout) {
|
|
400
|
+
trackTikTokInitiateCheckout(cartTotal, itemCount, eventID, contents.map(c => ({
|
|
401
|
+
content_id: c.id,
|
|
402
|
+
quantity: c.quantity,
|
|
403
|
+
price: c.item_price
|
|
404
|
+
})));
|
|
405
|
+
}
|
|
379
406
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
407
|
+
} catch (error) {
|
|
408
|
+
console.error('Error tracking initiate checkout:', error);
|
|
409
|
+
}
|
|
410
|
+
}, [cart, trackMetaInitiateCheckout, trackTikTokInitiateCheckout, initiateCheckoutMutation]);
|
|
383
411
|
|
|
384
412
|
const value: CartContextValue = {
|
|
385
413
|
cart: cart || null,
|
|
@@ -40,12 +40,12 @@ import { useMetaPixel } from '../providers/MetaPixelProvider';
|
|
|
40
40
|
* }
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
-
export function usePageTracking() {
|
|
43
|
+
export function usePageTracking(initialEventId?: string) {
|
|
44
44
|
const { trackPageView } = useMetaPixel();
|
|
45
45
|
|
|
46
46
|
useEffect(() => {
|
|
47
|
-
// Track initial page view
|
|
48
|
-
trackPageView();
|
|
47
|
+
// Track initial page view (with optional deduplication ID)
|
|
48
|
+
trackPageView(initialEventId);
|
|
49
49
|
|
|
50
50
|
// For Next.js Pages Router, track route changes
|
|
51
51
|
if (typeof window !== 'undefined') {
|
package/src/lib/utils.ts
CHANGED
|
@@ -87,3 +87,14 @@ export function getTikTokCookies(): { ttp: string | undefined; ttclid: string |
|
|
|
87
87
|
ttclid: getUrlParam('ttclid'),
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Generate a unique event ID for deduplication
|
|
92
|
+
* Matches the format used by the backend: {type}_{id}_{suffix}
|
|
93
|
+
*/
|
|
94
|
+
export function generateClientEventId(
|
|
95
|
+
type: 'cart' | 'order',
|
|
96
|
+
id: string,
|
|
97
|
+
suffix?: string
|
|
98
|
+
): string {
|
|
99
|
+
return suffix ? `${type}_${id}_${suffix}` : `${type}_${id}`;
|
|
100
|
+
}
|
|
@@ -23,7 +23,7 @@ interface MetaPixelContextValue {
|
|
|
23
23
|
/**
|
|
24
24
|
* Track a page view
|
|
25
25
|
*/
|
|
26
|
-
trackPageView: () => void;
|
|
26
|
+
trackPageView: (eventID?: string) => void;
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Track product view
|
|
@@ -44,9 +44,10 @@ interface MetaPixelContextValue {
|
|
|
44
44
|
* Track begin checkout event
|
|
45
45
|
* @param cartTotal - Total cart value
|
|
46
46
|
* @param itemCount - Number of items
|
|
47
|
+
* @param contents - Array of items in cart
|
|
47
48
|
* @param eventID - Optional event ID for deduplication with CAPI
|
|
48
49
|
*/
|
|
49
|
-
trackInitiateCheckout: (cartTotal: number, itemCount: number, eventID?: string) => void;
|
|
50
|
+
trackInitiateCheckout: (cartTotal: number, itemCount: number, contents?: PurchaseItem[], eventID?: string) => void;
|
|
50
51
|
|
|
51
52
|
/**
|
|
52
53
|
* Track purchase event
|
|
@@ -149,7 +150,7 @@ export function MetaPixelProvider({ children, pixelId, debug }: MetaPixelProvide
|
|
|
149
150
|
}
|
|
150
151
|
};
|
|
151
152
|
|
|
152
|
-
const trackPageView = () => {
|
|
153
|
+
const trackPageView = (eventID?: string) => {
|
|
153
154
|
if (!isInitialized || !reactPixel) {
|
|
154
155
|
if (shouldDebug) {
|
|
155
156
|
console.log('[Meta Pixel] PageView (not initialized)');
|
|
@@ -157,7 +158,8 @@ export function MetaPixelProvider({ children, pixelId, debug }: MetaPixelProvide
|
|
|
157
158
|
return;
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
|
|
161
|
+
const eventData = eventID ? { eventID } : undefined;
|
|
162
|
+
reactPixel.pageView(eventID ? eventData : undefined);
|
|
161
163
|
|
|
162
164
|
if (shouldDebug) {
|
|
163
165
|
console.log('[Meta Pixel] PageView');
|
|
@@ -179,17 +181,29 @@ export function MetaPixelProvider({ children, pixelId, debug }: MetaPixelProvide
|
|
|
179
181
|
content_ids: [productId],
|
|
180
182
|
content_name: productName,
|
|
181
183
|
content_type: 'product',
|
|
182
|
-
value: price,
|
|
184
|
+
value: price * quantity,
|
|
183
185
|
currency: 'NGN',
|
|
184
186
|
num_items: quantity,
|
|
187
|
+
contents: [{
|
|
188
|
+
id: productId,
|
|
189
|
+
quantity: quantity,
|
|
190
|
+
item_price: price,
|
|
191
|
+
}],
|
|
185
192
|
}, eventID);
|
|
186
193
|
};
|
|
187
194
|
|
|
188
|
-
const trackInitiateCheckout = (cartTotal: number, itemCount: number, eventID?: string) => {
|
|
195
|
+
const trackInitiateCheckout = (cartTotal: number, itemCount: number, contents: PurchaseItem[] = [], eventID?: string) => {
|
|
189
196
|
track('InitiateCheckout', {
|
|
190
197
|
value: cartTotal,
|
|
191
198
|
currency: 'NGN',
|
|
192
199
|
num_items: itemCount,
|
|
200
|
+
contents: contents.map((item) => ({
|
|
201
|
+
id: item.id,
|
|
202
|
+
quantity: item.quantity,
|
|
203
|
+
item_price: item.item_price,
|
|
204
|
+
})),
|
|
205
|
+
content_ids: contents.map((item) => item.id),
|
|
206
|
+
content_type: 'product',
|
|
193
207
|
}, eventID);
|
|
194
208
|
};
|
|
195
209
|
|