@eventlook/sdk 1.4.6 → 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/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;
@@ -42,6 +42,7 @@ export interface IOrderPaid {
42
42
  products: IPaidProduct[];
43
43
  extraFee: number;
44
44
  currency: Currencies;
45
+ promoCodes: IPromoCode[] | null;
45
46
  }
46
47
 
47
48
  export interface IAllowedPaymentMethod {