@eventlook/sdk 1.4.5 → 1.4.8
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/cjs/form/PaymentSuccess.js +39 -2
- package/dist/cjs/form/PaymentSuccess.js.map +1 -1
- package/dist/cjs/form/TicketForm.js +11 -12
- package/dist/cjs/form/TicketForm.js.map +1 -1
- package/dist/cjs/form/extra-field/ExtraField.js.map +1 -1
- package/dist/cjs/form/extra-field/ReleaseExtraFields.js +1 -1
- package/dist/cjs/form/extra-field/ReleaseExtraFields.js.map +1 -1
- package/dist/cjs/utils/gtm.js +20 -0
- package/dist/cjs/utils/gtm.js.map +1 -1
- package/dist/esm/form/PaymentSuccess.js +39 -2
- package/dist/esm/form/PaymentSuccess.js.map +1 -1
- package/dist/esm/form/TicketForm.js +11 -12
- package/dist/esm/form/TicketForm.js.map +1 -1
- package/dist/esm/form/extra-field/ExtraField.js.map +1 -1
- package/dist/esm/form/extra-field/ReleaseExtraFields.js +1 -1
- package/dist/esm/form/extra-field/ReleaseExtraFields.js.map +1 -1
- package/dist/esm/utils/gtm.js +19 -1
- package/dist/esm/utils/gtm.js.map +1 -1
- package/dist/types/form/PaymentSuccess.d.ts +2 -0
- package/dist/types/form/extra-field/ExtraField.d.ts +1 -1
- package/dist/types/utils/gtm.d.ts +3 -1
- package/dist/types/utils/types/gtm.type.d.ts +5 -0
- package/dist/types/utils/types/order.type.d.ts +1 -0
- package/package.json +1 -1
- package/src/form/PaymentSuccess.tsx +46 -3
- package/src/form/TicketForm.tsx +11 -12
- package/src/form/extra-field/ExtraField.tsx +3 -1
- package/src/form/extra-field/ReleaseExtraFields.tsx +1 -1
- package/src/utils/gtm.ts +29 -0
- package/src/utils/types/gtm.type.ts +6 -0
- package/src/utils/types/order.type.ts +1 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IPageView, IPageType, ISearchShow, IViewItem, IEcommerce, ICheckout, IEcommerceCartItems, IAddPaymentInfo, IPurchase, IEcommercePurchase, IUserData, IPixels, IViewItemList, ISelectItem, IAddToCart, IRemoveFromCart } from '@utils/types/gtm.type';
|
|
1
|
+
import { IPageView, IPageType, ISearchShow, IViewItem, IEcommerce, ICheckout, IEcommerceCartItems, IAddPaymentInfo, IPurchase, IEcommercePurchase, IUserData, IPixels, IViewItemList, ISelectItem, IAddToCart, IRemoveFromCart, IPurchasePaid } from '@utils/types/gtm.type';
|
|
2
2
|
import { IUser } from '@utils/types/user.type';
|
|
3
3
|
export declare const getGtmPageView: (url: string, userData?: IUserData) => IPageView;
|
|
4
4
|
export declare const gtmPageView: (url: string, userData?: IUserData) => IPageView;
|
|
@@ -18,6 +18,8 @@ export declare const getGtmAddPaymentInfo: (item: IEcommerceCartItems, pixels?:
|
|
|
18
18
|
export declare const gtmAddPaymentInfo: (item: IEcommerceCartItems, pixels?: IPixels) => IAddPaymentInfo & IPixels;
|
|
19
19
|
export declare const getGtmPurchase: (item: IEcommercePurchase | null, pixels?: IPixels, userData?: IUserData) => IPurchase & IPixels;
|
|
20
20
|
export declare const gtmPurchase: (item: IEcommercePurchase | null, pixels?: IPixels, userData?: IUserData) => IPurchase & IPixels;
|
|
21
|
+
export declare const getGtmPurchasePaid: (item: IEcommercePurchase | null, pixels?: IPixels, userData?: IUserData) => IPurchasePaid & IPixels;
|
|
22
|
+
export declare const gtmPurchasePaid: (item: IEcommercePurchase | null, pixels?: IPixels, userData?: IUserData) => IPurchasePaid & IPixels;
|
|
21
23
|
export declare const mapUserToUserData: (user: IUser) => {
|
|
22
24
|
em: string;
|
|
23
25
|
ph: string;
|
|
@@ -78,6 +78,11 @@ export interface IPurchase extends IBase {
|
|
|
78
78
|
ecommerce: IEcommercePurchase | null;
|
|
79
79
|
user_data: IUserData | null;
|
|
80
80
|
}
|
|
81
|
+
export interface IPurchasePaid extends IBase {
|
|
82
|
+
event: 'purchase_paid';
|
|
83
|
+
ecommerce: IEcommercePurchase | null;
|
|
84
|
+
user_data: IUserData | null;
|
|
85
|
+
}
|
|
81
86
|
export interface IPixels {
|
|
82
87
|
fb_pixel_id?: number | string;
|
|
83
88
|
tiktok_pixel_id?: number | string;
|
package/package.json
CHANGED
|
@@ -9,20 +9,23 @@ import { PropsWithChildren } from '@utils/types/global.type';
|
|
|
9
9
|
import { IPaidTicket } from '@utils/types/ticket.type';
|
|
10
10
|
import useResponsive from '@hooks/useResponsive';
|
|
11
11
|
import { getPlaceAsString } from '@utils/place';
|
|
12
|
-
import { fCurrency
|
|
12
|
+
import { fCurrency } from '@utils/formatNumber';
|
|
13
13
|
import { useTheme } from '@mui/material/styles';
|
|
14
14
|
import { IPaidProduct } from '@utils/types/product.type';
|
|
15
15
|
import dayjs from 'dayjs';
|
|
16
16
|
import useGlobal from '@hooks/useGlobal';
|
|
17
17
|
import { Trans } from '@components/Trans';
|
|
18
|
+
import { getGtmPurchasePaid, gtmPurchasePaid, mapUserToUserData } from '@utils/gtm.ts';
|
|
19
|
+
import { IPixels } from '@utils/types/gtm.type.ts';
|
|
18
20
|
|
|
19
21
|
interface Props {
|
|
20
22
|
setIsPaying: Dispatch<SetStateAction<boolean>>;
|
|
21
23
|
isIframe?: boolean;
|
|
24
|
+
pixels?: IPixels;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
const PaymentSuccess: React.FC<Props> = ({ setIsPaying, isIframe }) => {
|
|
25
|
-
const { showSnackbar, t, lang, callbacks, content } = useGlobal();
|
|
27
|
+
const PaymentSuccess: React.FC<Props> = ({ setIsPaying, isIframe, pixels }) => {
|
|
28
|
+
const { showSnackbar, t, lang, callbacks, content, user } = useGlobal();
|
|
26
29
|
const theme = useTheme();
|
|
27
30
|
const defaultState = 'PROCESSING';
|
|
28
31
|
const errorState = 'ERROR';
|
|
@@ -53,9 +56,49 @@ const PaymentSuccess: React.FC<Props> = ({ setIsPaying, isIframe }) => {
|
|
|
53
56
|
setProducts(products);
|
|
54
57
|
setState(data.state);
|
|
55
58
|
setGwUrl(data.gwUrl);
|
|
59
|
+
|
|
60
|
+
const items = [
|
|
61
|
+
...data.tickets.map((ticket) => ({
|
|
62
|
+
item_id: ticket.number,
|
|
63
|
+
item_name: `${ticket.eventName} - ${ticket.releaseCategoryName} - ${ticket.releaseName}`,
|
|
64
|
+
price: ticket.price,
|
|
65
|
+
quantity: 1,
|
|
66
|
+
})),
|
|
67
|
+
];
|
|
68
|
+
if (data.extraFee) {
|
|
69
|
+
items.push({
|
|
70
|
+
item_id: 'service_fee',
|
|
71
|
+
item_name: `Service fee`,
|
|
72
|
+
price: data.extraFee,
|
|
73
|
+
quantity: 1,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const item = {
|
|
77
|
+
currency: data.currency,
|
|
78
|
+
value: data.totalPrice,
|
|
79
|
+
tax: 0,
|
|
80
|
+
payment_type: data.paymentType,
|
|
81
|
+
transaction_id: String(data.orderNumber),
|
|
82
|
+
coupon: data?.promoCodes?.map((p) => p.code) || [],
|
|
83
|
+
items,
|
|
84
|
+
};
|
|
85
|
+
|
|
56
86
|
switch (data.state) {
|
|
57
87
|
case GopayState.PAID:
|
|
58
88
|
setTitle('event.tickets.payment_success.paid.title');
|
|
89
|
+
if (isIframe) {
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
parent.postMessage(
|
|
92
|
+
{
|
|
93
|
+
type: 'eventlookFrameGtm',
|
|
94
|
+
item: getGtmPurchasePaid(item, pixels),
|
|
95
|
+
},
|
|
96
|
+
'*'
|
|
97
|
+
);
|
|
98
|
+
}, 1000);
|
|
99
|
+
} else {
|
|
100
|
+
gtmPurchasePaid(item, pixels, user ? mapUserToUserData(user) : undefined);
|
|
101
|
+
}
|
|
59
102
|
break;
|
|
60
103
|
default:
|
|
61
104
|
setTitle('event.tickets.payment_success.unpaid');
|
package/src/form/TicketForm.tsx
CHANGED
|
@@ -324,17 +324,16 @@ const TicketForm: React.FC<Props> = ({
|
|
|
324
324
|
data.callback = isIframe && iframeCallback ? String(iframeCallback) : window.location.href;
|
|
325
325
|
data.tickets = Object.entries(values.tickets).reduce(
|
|
326
326
|
(acc, [eventId, items]) => {
|
|
327
|
-
acc[Number(eventId)] =
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
})) || [];
|
|
327
|
+
acc[Number(eventId)] = items
|
|
328
|
+
.filter((item) => !!item.quantity && !!item.releaseId)
|
|
329
|
+
.map((item) => ({
|
|
330
|
+
releaseId: Number(item.releaseId),
|
|
331
|
+
quantity: Number(item.quantity),
|
|
332
|
+
price: Number(item.price),
|
|
333
|
+
itemName: item.itemName,
|
|
334
|
+
products: item.products,
|
|
335
|
+
extraFields: item.extraFields,
|
|
336
|
+
}));
|
|
338
337
|
return acc;
|
|
339
338
|
},
|
|
340
339
|
{} as Record<number, ITicketFormTicket[]>
|
|
@@ -474,7 +473,7 @@ const TicketForm: React.FC<Props> = ({
|
|
|
474
473
|
return (
|
|
475
474
|
<Box id={EVENTLOOK_ORDER_FORM_ID}>
|
|
476
475
|
{hasGopayId ? (
|
|
477
|
-
<PaymentSuccess setIsPaying={setIsPaying} isIframe={isIframe} />
|
|
476
|
+
<PaymentSuccess setIsPaying={setIsPaying} isIframe={isIframe} pixels={pixels} />
|
|
478
477
|
) : isPaying ? (
|
|
479
478
|
<PaymentPending />
|
|
480
479
|
) : paymentRedirect ? (
|
|
@@ -8,7 +8,9 @@ import useGlobal from '@hooks/useGlobal.ts';
|
|
|
8
8
|
|
|
9
9
|
interface Props {
|
|
10
10
|
extraField: IEventExtraField;
|
|
11
|
-
name:
|
|
11
|
+
name:
|
|
12
|
+
| `extraFields.${number}.value`
|
|
13
|
+
| `tickets.${number}.${number}.extraFields.${number}.${number}.value`;
|
|
12
14
|
size?: 'small' | 'medium';
|
|
13
15
|
}
|
|
14
16
|
|
|
@@ -78,7 +78,7 @@ const ReleaseExtraFields: React.FC<Props> = ({ release, eventId, releaseIndex, q
|
|
|
78
78
|
<Grid key={field.id} item xs={12} md={6}>
|
|
79
79
|
<ExtraField
|
|
80
80
|
extraField={field}
|
|
81
|
-
name={`tickets.${releaseIndex}.extraFields.${rowIdx}.${colIdx}.value`}
|
|
81
|
+
name={`tickets.${eventId}.${releaseIndex}.extraFields.${rowIdx}.${colIdx}.value`}
|
|
82
82
|
size="small"
|
|
83
83
|
/>
|
|
84
84
|
</Grid>
|
package/src/utils/gtm.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
ISelectItem,
|
|
18
18
|
IAddToCart,
|
|
19
19
|
IRemoveFromCart,
|
|
20
|
+
IPurchasePaid,
|
|
20
21
|
} from '@utils/types/gtm.type';
|
|
21
22
|
import { UserIpCookie } from '@utils/data/cookie';
|
|
22
23
|
import { IUser } from '@utils/types/user.type';
|
|
@@ -225,6 +226,34 @@ export const gtmPurchase = (
|
|
|
225
226
|
return pageEvent;
|
|
226
227
|
};
|
|
227
228
|
|
|
229
|
+
export const getGtmPurchasePaid = (
|
|
230
|
+
item: IEcommercePurchase | null,
|
|
231
|
+
pixels?: IPixels,
|
|
232
|
+
userData?: IUserData
|
|
233
|
+
) => {
|
|
234
|
+
const userIp = Cookies.get(UserIpCookie);
|
|
235
|
+
const pageEvent: IPurchasePaid & IPixels = {
|
|
236
|
+
event: 'purchase_paid',
|
|
237
|
+
fb_pixel_id: pixels?.fb_pixel_id || '',
|
|
238
|
+
tiktok_pixel_id: pixels?.tiktok_pixel_id || '',
|
|
239
|
+
ecommerce: item,
|
|
240
|
+
user_data: userData || null,
|
|
241
|
+
ip: userIp || '',
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
return pageEvent;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
export const gtmPurchasePaid = (
|
|
248
|
+
item: IEcommercePurchase | null,
|
|
249
|
+
pixels?: IPixels,
|
|
250
|
+
userData?: IUserData
|
|
251
|
+
) => {
|
|
252
|
+
const pageEvent = getGtmPurchasePaid(item, pixels, userData);
|
|
253
|
+
if (isBrowser() && window.dataLayer) setTimeout(() => window.dataLayer.push(pageEvent), 500);
|
|
254
|
+
return pageEvent;
|
|
255
|
+
};
|
|
256
|
+
|
|
228
257
|
export const mapUserToUserData = (user: IUser) => ({
|
|
229
258
|
em: user.email,
|
|
230
259
|
ph: user.phone,
|
|
@@ -96,6 +96,12 @@ export interface IPurchase extends IBase {
|
|
|
96
96
|
user_data: IUserData | null;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
export interface IPurchasePaid extends IBase {
|
|
100
|
+
event: 'purchase_paid';
|
|
101
|
+
ecommerce: IEcommercePurchase | null;
|
|
102
|
+
user_data: IUserData | null;
|
|
103
|
+
}
|
|
104
|
+
|
|
99
105
|
export interface IPixels {
|
|
100
106
|
fb_pixel_id?: number | string;
|
|
101
107
|
tiktok_pixel_id?: number | string;
|