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