@anker-in/shopify-react 1.2.3 → 1.3.0-beta.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/dist/hooks/index.d.mts +47 -101
- package/dist/hooks/index.d.ts +47 -101
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +14 -28
- package/dist/provider/index.d.ts +14 -28
- package/dist/{types-DfR13pDe.d.mts → types-CMMWxyUF.d.mts} +11 -184
- package/dist/{types-DfR13pDe.d.ts → types-CMMWxyUF.d.ts} +11 -184
- package/package.json +4 -4
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import Decimal from 'decimal.js';
|
|
1
|
+
import { NormalizedProductVariant, NormalizedProduct, MoneyV2, NormalizedCart } from '@anker-in/shopify-sdk';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Tracking Types
|
|
@@ -19,30 +18,19 @@ interface GtmParams {
|
|
|
19
18
|
|
|
20
19
|
declare global {
|
|
21
20
|
interface Window {
|
|
22
|
-
dataLayer?:
|
|
23
|
-
gtag?:
|
|
24
|
-
(command: 'config', targetId: string, config?: Record<string, unknown>): void;
|
|
25
|
-
(command: 'set', config: Record<string, unknown>): void;
|
|
26
|
-
(command: 'event', eventName: string, eventParams?: Record<string, unknown>): void;
|
|
27
|
-
(command: 'get', targetId: string, fieldName: string, callback?: (value: string) => void): void;
|
|
28
|
-
(command: 'consent', consentArg: string, consentParams?: Record<string, unknown>): void;
|
|
29
|
-
};
|
|
21
|
+
dataLayer?: any[];
|
|
22
|
+
gtag?: (...args: any) => void;
|
|
30
23
|
}
|
|
31
24
|
}
|
|
32
25
|
/**
|
|
33
26
|
* Push event to GA4 dataLayer
|
|
34
27
|
*/
|
|
35
|
-
declare const gaTrack: (data:
|
|
28
|
+
declare const gaTrack: (data: any) => void;
|
|
36
29
|
/**
|
|
37
30
|
* Track add to cart event in GA4
|
|
38
31
|
*/
|
|
39
32
|
declare const trackAddToCartGA: ({ lineItems, gtmParams, }: {
|
|
40
|
-
lineItems:
|
|
41
|
-
finalPrice?: MoneyV2;
|
|
42
|
-
gtmParams?: {
|
|
43
|
-
item_category_id?: number | string;
|
|
44
|
-
};
|
|
45
|
-
}>;
|
|
33
|
+
lineItems: AddToCartLineItem[];
|
|
46
34
|
gtmParams?: GtmParams;
|
|
47
35
|
}) => void;
|
|
48
36
|
/**
|
|
@@ -58,59 +46,26 @@ declare const trackBeginCheckoutGA: ({ lineItems, currencyCode, gtmParams, }: {
|
|
|
58
46
|
* This triggers begin_checkout event for buy now actions
|
|
59
47
|
*/
|
|
60
48
|
declare const trackBuyNowGA: ({ lineItems, gtmParams, }: {
|
|
61
|
-
lineItems:
|
|
62
|
-
gtmParams?: {
|
|
63
|
-
item_category_id?: number | string;
|
|
64
|
-
};
|
|
65
|
-
}>;
|
|
49
|
+
lineItems: AddToCartLineItem[];
|
|
66
50
|
gtmParams?: GtmParams;
|
|
67
51
|
}) => void;
|
|
68
|
-
/**
|
|
69
|
-
* GA4 Data
|
|
70
|
-
*/
|
|
71
|
-
interface GA4Data {
|
|
72
|
-
clientId: string;
|
|
73
|
-
sessionId: string;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Wait for gtag to be ready
|
|
77
|
-
*/
|
|
78
|
-
declare function waitForGtagReady(timeout?: number): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Get GA4 client ID
|
|
81
|
-
*/
|
|
82
|
-
declare const getGA4ClientId: (measurementId?: string) => Promise<string>;
|
|
83
|
-
/**
|
|
84
|
-
* Get GA4 session ID
|
|
85
|
-
*/
|
|
86
|
-
declare const getGA4SessionId: (measurementId?: string) => Promise<string>;
|
|
87
|
-
/**
|
|
88
|
-
* Get GA4 data (client ID and session ID)
|
|
89
|
-
*/
|
|
90
|
-
declare const getGA4Data: (measurementId?: string) => Promise<GA4Data>;
|
|
91
52
|
|
|
92
53
|
/**
|
|
93
54
|
* Facebook Pixel Tracking
|
|
94
55
|
* FBQ event tracking utilities
|
|
95
56
|
*/
|
|
96
57
|
|
|
97
|
-
type FbqCommand = 'track' | 'trackCustom' | 'trackSingle' | 'trackCustom';
|
|
98
|
-
type FbqEventName = 'AddToCart' | 'Purchase' | 'InitiateCheckout' | 'ViewContent' | string;
|
|
99
|
-
type FbqEventParams = Record<string, unknown>;
|
|
100
58
|
declare global {
|
|
101
59
|
interface Window {
|
|
102
|
-
fbq?: (
|
|
60
|
+
fbq?: (...args: any[]) => void;
|
|
61
|
+
gtag?: (...args: any[]) => void;
|
|
103
62
|
}
|
|
104
63
|
}
|
|
105
64
|
/**
|
|
106
65
|
* Track add to cart event in Facebook Pixel
|
|
107
66
|
*/
|
|
108
|
-
declare const trackAddToCartFBQ: ({ lineItems
|
|
109
|
-
lineItems:
|
|
110
|
-
gtmParams?: {
|
|
111
|
-
item_category_id?: number | string;
|
|
112
|
-
};
|
|
113
|
-
}>;
|
|
67
|
+
declare const trackAddToCartFBQ: ({ lineItems }: {
|
|
68
|
+
lineItems: AddToCartLineItem[];
|
|
114
69
|
}) => void;
|
|
115
70
|
/**
|
|
116
71
|
* Configuration for Buy Now tracking events
|
|
@@ -147,9 +102,6 @@ type AddToCartLineItem = {
|
|
|
147
102
|
code: string;
|
|
148
103
|
amount: number;
|
|
149
104
|
};
|
|
150
|
-
gtmParams?: {
|
|
151
|
-
item_category_id?: number | string;
|
|
152
|
-
};
|
|
153
105
|
};
|
|
154
106
|
interface AddToCartInput {
|
|
155
107
|
/** Lines to add */
|
|
@@ -182,131 +134,6 @@ interface UseAddToCartOptions {
|
|
|
182
134
|
withTrack?: boolean;
|
|
183
135
|
}
|
|
184
136
|
|
|
185
|
-
/**
|
|
186
|
-
* Auto Remove Free Gifts Hook
|
|
187
|
-
*
|
|
188
|
-
* Automatically removes Function and Script free gifts from cart on page load.
|
|
189
|
-
* This ensures gifts are only added at checkout time, not kept in cart permanently.
|
|
190
|
-
*
|
|
191
|
-
* Based on storefront-anker production implementation.
|
|
192
|
-
*/
|
|
193
|
-
|
|
194
|
-
interface UseAutoRemoveFreeGiftsOptions {
|
|
195
|
-
/**
|
|
196
|
-
* Whether to remove Function gifts (with _discounts_function_env attribute)
|
|
197
|
-
* @default true
|
|
198
|
-
*/
|
|
199
|
-
removeFunctionGifts?: boolean;
|
|
200
|
-
/**
|
|
201
|
-
* Whether to remove Script gifts (with _giveaway_gradient_gifts attribute)
|
|
202
|
-
* @default true
|
|
203
|
-
*/
|
|
204
|
-
removeScriptGifts?: boolean;
|
|
205
|
-
/**
|
|
206
|
-
* Custom function to identify additional gift line items
|
|
207
|
-
* @param line - Line item to check
|
|
208
|
-
* @returns true if line item is a gift that should be removed
|
|
209
|
-
*/
|
|
210
|
-
isGiftLineItem?: (line: NormalizedLineItem) => boolean;
|
|
211
|
-
}
|
|
212
|
-
interface UseAutoRemoveFreeGiftsResult {
|
|
213
|
-
/** Whether removal is in progress */
|
|
214
|
-
isRemoving: boolean;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Automatically removes free gifts from cart on initialization
|
|
218
|
-
*
|
|
219
|
-
* Function满赠和Script满赠的赠品都会被添加到购物车,需要在返回购物车页面时自动删除。
|
|
220
|
-
* - Function 赠品:带 _discounts_function_env 属性
|
|
221
|
-
* - Script 赠品:带 _giveaway_gradient_gifts 属性
|
|
222
|
-
*
|
|
223
|
-
* @example
|
|
224
|
-
* ```tsx
|
|
225
|
-
* function CartPage() {
|
|
226
|
-
* // Auto-remove all gifts on page load
|
|
227
|
-
* useAutoRemoveFreeGifts()
|
|
228
|
-
*
|
|
229
|
-
* return <Cart />
|
|
230
|
-
* }
|
|
231
|
-
* ```
|
|
232
|
-
*
|
|
233
|
-
* @example
|
|
234
|
-
* ```tsx
|
|
235
|
-
* // Only remove Function gifts, keep Script gifts
|
|
236
|
-
* useAutoRemoveFreeGifts({
|
|
237
|
-
* removeFunctionGifts: true,
|
|
238
|
-
* removeScriptGifts: false
|
|
239
|
-
* })
|
|
240
|
-
* ```
|
|
241
|
-
*
|
|
242
|
-
* @example
|
|
243
|
-
* ```tsx
|
|
244
|
-
* // Custom gift identification
|
|
245
|
-
* useAutoRemoveFreeGifts({
|
|
246
|
-
* isGiftLineItem: (line) => {
|
|
247
|
-
* // Also remove other campaign gifts
|
|
248
|
-
* return line.customAttributes?.some(
|
|
249
|
-
* attr => attr.key === '_giveaway_summer_campaign'
|
|
250
|
-
* )
|
|
251
|
-
* }
|
|
252
|
-
* })
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
declare function useAutoRemoveFreeGifts(options?: UseAutoRemoveFreeGiftsOptions): UseAutoRemoveFreeGiftsResult;
|
|
256
|
-
/**
|
|
257
|
-
* Helper function to check if a line item is a Function gift
|
|
258
|
-
*/
|
|
259
|
-
declare function isFunctionGift(line: NormalizedLineItem): boolean;
|
|
260
|
-
/**
|
|
261
|
-
* Helper function to check if a line item is a Script gift
|
|
262
|
-
*/
|
|
263
|
-
declare function isScriptGift(line: NormalizedLineItem): boolean;
|
|
264
|
-
/**
|
|
265
|
-
* Helper function to check if a line item is a buy-get gift (买赠)
|
|
266
|
-
*/
|
|
267
|
-
declare function isBuyGetGift(line: NormalizedLineItem): boolean;
|
|
268
|
-
/**
|
|
269
|
-
* Helper function to check if a line item is any type of gift
|
|
270
|
-
*/
|
|
271
|
-
declare function isAnyGift(line: NormalizedLineItem): boolean;
|
|
272
|
-
|
|
273
|
-
interface GiveawayProduct {
|
|
274
|
-
handle: string;
|
|
275
|
-
sku: string;
|
|
276
|
-
}
|
|
277
|
-
interface Breakpoint {
|
|
278
|
-
breakpoint: string;
|
|
279
|
-
giveawayProducts: GiveawayProduct[];
|
|
280
|
-
}
|
|
281
|
-
interface ScriptAutoFreeGiftConfig {
|
|
282
|
-
activityAvailableQuery?: string;
|
|
283
|
-
activityQroperty?: string;
|
|
284
|
-
breakpoints?: Array<{
|
|
285
|
-
breakpoint: string;
|
|
286
|
-
giveawayProducts: GiveawayProduct[];
|
|
287
|
-
}>;
|
|
288
|
-
includeTags?: string[];
|
|
289
|
-
useTotalAmount?: boolean;
|
|
290
|
-
requireLogin?: boolean;
|
|
291
|
-
}
|
|
292
|
-
interface UseScriptAutoFreeGiftResult {
|
|
293
|
-
involvedLines: NormalizedLineItem[];
|
|
294
|
-
reorder: (a: NormalizedLineItem, b: NormalizedLineItem) => number;
|
|
295
|
-
disableCodeRemove: boolean;
|
|
296
|
-
nextFreeGiftLevel: Breakpoint | null;
|
|
297
|
-
freeGiftLevel: Breakpoint | null;
|
|
298
|
-
involvedSubTotal: Decimal;
|
|
299
|
-
giftProductsResult?: NormalizedProduct[];
|
|
300
|
-
}
|
|
301
|
-
declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, lines, profile, }: {
|
|
302
|
-
campaign?: ScriptAutoFreeGiftConfig;
|
|
303
|
-
_giveaway: string;
|
|
304
|
-
cart: NormalizedCart | undefined;
|
|
305
|
-
locale?: string;
|
|
306
|
-
lines?: AddToCartLineItem[];
|
|
307
|
-
profile?: any;
|
|
308
|
-
}) => UseScriptAutoFreeGiftResult;
|
|
309
|
-
|
|
310
137
|
/**
|
|
311
138
|
* Plus Member Types
|
|
312
139
|
* Type definitions for Plus Member functionality
|
|
@@ -683,4 +510,4 @@ type DeliveryCustomData = {
|
|
|
683
510
|
plus_type?: DeliveryPlusType;
|
|
684
511
|
};
|
|
685
512
|
|
|
686
|
-
export { type AddToCartLineItem as A,
|
|
513
|
+
export { type AddToCartLineItem as A, type BuyNowTrackConfig as B, DeliveryPlusType as D, type GtmParams as G, PLUS_MEMBER_TYPE as P, ShippingMethodMode as S, type UseAddToCartOptions as U, type AddToCartInput as a, PlusMemberMode as b, type PlusMemberShippingMethodMetafields as c, type PlusMemberShippingMethodConfig as d, type PlusMemberSettingsMetafields as e, type SelectedPlusMemberVariant as f, type DeliveryCustomData as g, gaTrack as h, trackBeginCheckoutGA as i, trackBuyNowGA as j, trackAddToCartFBQ as k, trackBuyNowFBQ as l, trackAddToCartGA as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anker-in/shopify-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-beta.0",
|
|
4
4
|
"description": "React hooks and components for Shopify SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"decimal.js": "^10.6.0",
|
|
32
32
|
"js-cookie": "^3.0.5",
|
|
33
33
|
"swr": "^2.2.0",
|
|
34
|
-
"@anker-in/shopify-sdk": "1.
|
|
34
|
+
"@anker-in/shopify-sdk": "1.2.0-beta.0",
|
|
35
35
|
"@anker-in/shopify-core": "1.0.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"react-dom": "^19.1.0",
|
|
48
48
|
"tsup": "^8.0.0",
|
|
49
49
|
"typescript": "5.9.2",
|
|
50
|
-
"@repo/
|
|
51
|
-
"@repo/
|
|
50
|
+
"@repo/typescript-config": "0.0.1",
|
|
51
|
+
"@repo/eslint-config": "0.0.1"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|