@antscorp/antsomi-ui 1.3.7-beta.1 → 1.3.7-beta.3

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.
@@ -21,7 +21,13 @@ export const ItemEvent = forwardRef((props, ref) => {
21
21
  const { etype: eType } = item;
22
22
  const renderSingleEvent = (dataEvent) => {
23
23
  const dataActivity = dataEvent.data.firstActivities;
24
- const { titleEvent: title, fullContentEvent = '', infoEvent, validateExtra, perShow, limitShowSlide, } = getInfoEvent(eType, dataActivity[0], eventTracking, objectName, appConfig);
24
+ const { titleEvent: title, fullContentEvent = '', infoEvent, validateExtra, perShow, limitShowSlide, } = getInfoEvent({
25
+ eType,
26
+ itemEvent: dataActivity[0],
27
+ eventTracking,
28
+ customerName: objectName,
29
+ config: appConfig,
30
+ });
25
31
  return (_jsxs(TimelineSection, { title: title, bgIcon: infoEvent.backgroundIcon, iconName: infoEvent.iconName, children: [_jsx(List, { type: "timeline", children: _jsxs(ListItem, { children: [_jsx(ListItemTimeLine, { children: _jsx(ListItemTitle, { ellipsis: { tooltip: true }, children: htmlParse(fullContentEvent) }) }), _jsx(ListItemTime, { ellipsis: { tooltip: true }, children: formatDateHeader(dataActivity[0].trackedDateTimeUTC) })] }) }), infoEvent.showRedeem && validateExtra.loyalty_card ? (_jsxs(WrapperContainerRedeem, { children: [_jsx(CardMember, { info: validateExtra.loyalty_card }), checkShowRedeem(validateExtra) && (_jsx(Redeem, { point: safeParse(validateExtra.point, 'N/A'), redeemType: safeParse(validateExtra.point_type, 'N/A') }))] })) : (infoEvent.showRedeem &&
26
32
  checkShowRedeem(validateExtra) && (_jsx(Redeem, { point: safeParse(validateExtra.point, 'N/A'), redeemType: safeParse(validateExtra.point_type, 'N/A') }))), dataActivity[0].items.length > 0 && dataActivity[0].items[0].item_type === 'product' && (_jsx(ListItemContent, { children: _jsx(ActionHistory, { revenue: infoEvent.showRevenue
27
33
  ? `${safeParse(validateExtra.revenue, '--') === '--'
@@ -45,12 +45,24 @@ export const ItemGroupEvent = forwardRef((props, ref) => {
45
45
  const { etype: eType } = item;
46
46
  const renderGroupEvent = (dataEvent) => {
47
47
  const dataActivity = dataEvent.data.firstActivities;
48
- const { titleEvent: title, infoEvent: infoEventLast } = getInfoEvent(eType, dataActivity[0], eventTracking, objectName, appConfig);
48
+ const { titleEvent: title, infoEvent: infoEventLast } = getInfoEvent({
49
+ eType,
50
+ itemEvent: dataActivity[0],
51
+ eventTracking,
52
+ customerName: objectName,
53
+ config: appConfig,
54
+ });
49
55
  const rearTitle = translate(translations._EVENT_DES_PERFORM_OTHER_EVENT, 'and performed other {{x}} actions', { x: dataActivity.length - 1 });
50
56
  if (isEmpty(dataActivity))
51
57
  return null;
52
58
  return (_jsx(TimelineSection, { title: `${title}, ${rearTitle}`, bgIcon: infoEventLast.backgroundIcon, iconName: infoEventLast.iconName ? infoEventLast.iconName : 'cus web', children: _jsx(List, { type: "timeline", loadMore: true, limit: 5, noPaddingBottom: true, children: dataActivity.map((itemEvent, index) => {
53
- const { titleEvent, fullContentEvent = '', infoEvent, validateExtra, perShow, limitShowSlide, } = getInfoEvent(eType, itemEvent, eventTracking, objectName, appConfig);
59
+ const { titleEvent, fullContentEvent = '', infoEvent, validateExtra, perShow, limitShowSlide, } = getInfoEvent({
60
+ eType,
61
+ itemEvent,
62
+ eventTracking,
63
+ customerName: objectName,
64
+ config: appConfig,
65
+ });
54
66
  return (_jsxs(React.Fragment, { children: [_jsxs(ListItem, { children: [_jsx(ListItemTimeLine, { children: _jsx(ListItemTitle, { ellipsis: { tooltip: true }, children: htmlParse(fullContentEvent) }) }), _jsx(ListItemTime, { ellipsis: { tooltip: true }, children: formatDateHeader(itemEvent.trackedDateTimeUTC, timezone) })] }), infoEvent.showRedeem && validateExtra.loyalty_card ? (_jsxs(WrapperContainerRedeem, { children: [_jsx(CardMember, { info: validateExtra.loyalty_card }), checkShowRedeem(validateExtra) && (_jsx(Redeem, { point: safeParse(validateExtra.point, 'N/A'), redeemType: safeParse(validateExtra.point_type, 'N/A') }))] })) : (infoEvent.showRedeem &&
55
67
  checkShowRedeem(validateExtra) && (_jsx(Redeem, { point: safeParse(validateExtra.point, 'N/A'), redeemType: safeParse(validateExtra.point_type, 'N/A') }))), itemEvent.items.length > 0 && itemEvent.items[0].item_type === 'product' && (_jsx(ListItemContent, { children: _jsx(ActionHistory, { revenue: infoEvent.showRevenue
56
68
  ? `${safeParse(validateExtra.revenue, '--') === '--'
@@ -214,7 +214,7 @@ export declare const MAP_LIST_INFO_EVENT: {
214
214
  readonly showSlideImageAndPrice: false;
215
215
  readonly showQuantity: false;
216
216
  readonly showRevenue: false;
217
- readonly objectReplace: readonly ["customer_name", "page_name"];
217
+ readonly objectReplace: readonly ["customer_name", "page_type", "event_source_name"];
218
218
  readonly iconName: "cus web_asset";
219
219
  readonly backgroundIcon: "#005fd8";
220
220
  readonly showRedeem: false;
@@ -357,7 +357,7 @@ export declare const MAP_LIST_INFO_EVENT: {
357
357
  readonly showSlideImageAndPrice: false;
358
358
  readonly showQuantity: false;
359
359
  readonly showRevenue: false;
360
- readonly objectReplace: readonly ["customer_name", "page_name"];
360
+ readonly objectReplace: readonly ["customer_name", "page_type", "event_source_name"];
361
361
  readonly iconName: "cus web_asset";
362
362
  readonly backgroundIcon: "#005fd8";
363
363
  readonly showRedeem: false;
@@ -370,7 +370,7 @@ export declare const MAP_LIST_INFO_EVENT: {
370
370
  readonly showSlideImageAndPrice: false;
371
371
  readonly showQuantity: false;
372
372
  readonly showRevenue: false;
373
- readonly objectReplace: readonly ["customer_name", "screen_type"];
373
+ readonly objectReplace: readonly ["customer_name", "screen_type", "event_source_name"];
374
374
  readonly iconName: "cus mobile_friendly";
375
375
  readonly backgroundIcon: "#005fd8";
376
376
  readonly showRedeem: false;
@@ -694,7 +694,7 @@ export declare const DATA_EVENT: {
694
694
  readonly showSlideImageAndPrice: false;
695
695
  readonly showQuantity: false;
696
696
  readonly showRevenue: false;
697
- readonly objectReplace: readonly ["customer_name", "page_name"];
697
+ readonly objectReplace: readonly ["customer_name", "page_type", "event_source_name"];
698
698
  readonly iconName: "cus web_asset";
699
699
  readonly backgroundIcon: "#005fd8";
700
700
  readonly showRedeem: false;
@@ -826,7 +826,7 @@ export declare const DATA_EVENT: {
826
826
  readonly showSlideImageAndPrice: false;
827
827
  readonly showQuantity: false;
828
828
  readonly showRevenue: false;
829
- readonly objectReplace: readonly ["customer_name", "page_name"];
829
+ readonly objectReplace: readonly ["customer_name", "page_type", "event_source_name"];
830
830
  readonly iconName: "cus web_asset";
831
831
  readonly backgroundIcon: "#005fd8";
832
832
  readonly showRedeem: false;
@@ -838,7 +838,7 @@ export declare const DATA_EVENT: {
838
838
  readonly showSlideImageAndPrice: false;
839
839
  readonly showQuantity: false;
840
840
  readonly showRevenue: false;
841
- readonly objectReplace: readonly ["customer_name", "screen_type"];
841
+ readonly objectReplace: readonly ["customer_name", "screen_type", "event_source_name"];
842
842
  readonly iconName: "cus mobile_friendly";
843
843
  readonly backgroundIcon: "#005fd8";
844
844
  readonly showRedeem: false;
@@ -1168,7 +1168,7 @@ export declare const DATA_EVENT: {
1168
1168
  readonly showSlideImageAndPrice: false;
1169
1169
  readonly showQuantity: false;
1170
1170
  readonly showRevenue: false;
1171
- readonly objectReplace: readonly ["customer_name", "page_name"];
1171
+ readonly objectReplace: readonly ["customer_name", "page_type", "event_source_name"];
1172
1172
  readonly iconName: "cus web_asset";
1173
1173
  readonly backgroundIcon: "#005fd8";
1174
1174
  readonly showRedeem: false;
@@ -1311,7 +1311,7 @@ export declare const DATA_EVENT: {
1311
1311
  readonly showSlideImageAndPrice: false;
1312
1312
  readonly showQuantity: false;
1313
1313
  readonly showRevenue: false;
1314
- readonly objectReplace: readonly ["customer_name", "page_name"];
1314
+ readonly objectReplace: readonly ["customer_name", "page_type", "event_source_name"];
1315
1315
  readonly iconName: "cus web_asset";
1316
1316
  readonly backgroundIcon: "#005fd8";
1317
1317
  readonly showRedeem: false;
@@ -1324,7 +1324,7 @@ export declare const DATA_EVENT: {
1324
1324
  readonly showSlideImageAndPrice: false;
1325
1325
  readonly showQuantity: false;
1326
1326
  readonly showRevenue: false;
1327
- readonly objectReplace: readonly ["customer_name", "screen_type"];
1327
+ readonly objectReplace: readonly ["customer_name", "screen_type", "event_source_name"];
1328
1328
  readonly iconName: "cus mobile_friendly";
1329
1329
  readonly backgroundIcon: "#005fd8";
1330
1330
  readonly showRedeem: false;
@@ -1,5 +1,4 @@
1
- /* eslint-disable no-underscore-dangle */
2
- import { translations } from '@antscorp/antsomi-ui/es/locales/translations';
1
+ import { translations } from '@antscorp/antsomi-locales';
3
2
  export const MAP_LIST_INFO_EVENT = {
4
3
  'click product': {
5
4
  eventType: 'click product',
@@ -229,7 +228,7 @@ export const MAP_LIST_INFO_EVENT = {
229
228
  showSlideImageAndPrice: false,
230
229
  showQuantity: false,
231
230
  showRevenue: false,
232
- objectReplace: ['customer_name', 'page_name'],
231
+ objectReplace: ['customer_name', 'page_type', 'event_source_name'],
233
232
  iconName: 'cus web_asset',
234
233
  backgroundIcon: '#005fd8',
235
234
  showRedeem: false,
@@ -372,7 +371,7 @@ export const MAP_LIST_INFO_EVENT = {
372
371
  showSlideImageAndPrice: false,
373
372
  showQuantity: false,
374
373
  showRevenue: false,
375
- objectReplace: ['customer_name', 'page_name'],
374
+ objectReplace: ['customer_name', 'page_type', 'event_source_name'],
376
375
  iconName: 'cus web_asset',
377
376
  backgroundIcon: '#005fd8',
378
377
  showRedeem: false,
@@ -385,7 +384,7 @@ export const MAP_LIST_INFO_EVENT = {
385
384
  showSlideImageAndPrice: false,
386
385
  showQuantity: false,
387
386
  showRevenue: false,
388
- objectReplace: ['customer_name', 'screen_type'],
387
+ objectReplace: ['customer_name', 'screen_type', 'event_source_name'],
389
388
  iconName: 'cus mobile_friendly',
390
389
  backgroundIcon: '#005fd8',
391
390
  showRedeem: false,
@@ -13,6 +13,10 @@ export const StyledRoot = styled.div `
13
13
  text-decoration: underline;
14
14
  }
15
15
  }
16
+
17
+ .title-no-url {
18
+ font-weight: bold;
19
+ }
16
20
  `;
17
21
  export const StyldTitle = styled.div `
18
22
  font-size: 16px;
@@ -3,7 +3,13 @@ import { AppConfigProviderProps } from '../../../providers/AppConfigProvider/con
3
3
  export declare const getValuesReplace: (objectReplace: any[], data: Record<string, any>) => {};
4
4
  export declare const getStringHtmlByType: (item: Record<string, any>, eType?: string) => string;
5
5
  export declare const getProductName: (data: any[]) => string;
6
- export declare const getInfoEvent: (eType: string, itemEvent: Record<string, any>, eventTracking: EventTrackingWithMap, customerName: string, config: AppConfigProviderProps) => {
6
+ export declare const getInfoEvent: (params: {
7
+ eType: string;
8
+ itemEvent: Record<string, any>;
9
+ eventTracking: EventTrackingWithMap;
10
+ config: AppConfigProviderProps;
11
+ customerName?: string;
12
+ }) => {
7
13
  titleEvent: string;
8
14
  fullContentEvent: string;
9
15
  infoEvent: any;
@@ -19,7 +19,7 @@ export const getValuesReplace = (objectReplace, data) => {
19
19
  return values;
20
20
  }
21
21
  objectReplace.forEach((item) => {
22
- if (item !== 'product_name' && item !== 'page_name') {
22
+ if (item !== 'product_name' && item !== 'page_name' && item !== 'page_type') {
23
23
  if (item === 'x_point' || item === 'store_link') {
24
24
  if (item === 'store_link') {
25
25
  values[item] =
@@ -119,7 +119,175 @@ export const getProductName = (data) => {
119
119
  productNames = arrayProductName.join(', ');
120
120
  return productNames;
121
121
  };
122
- export const getInfoEvent = (eType, itemEvent, eventTracking, customerName, config) => {
122
+ // Handler functions for each eType
123
+ const handleProductEvent = (itemEvent, validateExtra, data, eType) => {
124
+ let listProductName = 'N/A';
125
+ listProductName = getProductName(itemEvent.items);
126
+ data.product_name = listProductName;
127
+ if (itemEvent.pageType === 'order_completed') {
128
+ data.order_id = validateExtra.order_id || 'N/A';
129
+ }
130
+ else if (itemEvent.pageType === 'purchase') {
131
+ data.order_id = validateExtra.order_id || 'N/A';
132
+ data.num_of_products = itemEvent.items.length || 'N/A';
133
+ }
134
+ else if (itemEvent.pageType === 'search') {
135
+ data.keywords = validateExtra.src_search_term || 'N/A';
136
+ }
137
+ else if (itemEvent.pageType === 'product_list_view') {
138
+ data.product_list = getProductName(itemEvent.items);
139
+ }
140
+ else if (itemEvent.pageType === 'click' ||
141
+ itemEvent.pageType === 'view' ||
142
+ itemEvent.pageType === 'add_to_cart') {
143
+ data.product_name = getStringHtmlByType(itemEvent.items[0], eType);
144
+ }
145
+ };
146
+ const handleOrderEvent = (validateExtra, data) => {
147
+ data.order_id = safeParse(validateExtra.order_id, 'N/A');
148
+ };
149
+ const handleTransactionEvent = (itemEvent, validateExtra, data) => {
150
+ if (itemEvent.pageType === 'purchase') {
151
+ data.order_id = safeParse(validateExtra.order_id, 'N/A');
152
+ const { num_of_products } = getStoreLinkAndNumberProduct(validateExtra, itemEvent);
153
+ data.num_of_products = num_of_products;
154
+ }
155
+ else {
156
+ data.transaction_id = safeParse(validateExtra.transaction_id, 'N/A');
157
+ const { num_of_products, store_link } = getStoreLinkAndNumberProduct(validateExtra, itemEvent);
158
+ data.num_of_products = num_of_products;
159
+ data.store_link = store_link;
160
+ }
161
+ };
162
+ const handlePageEvent = (itemEvent, data) => {
163
+ if (itemEvent.pageType === 'view') {
164
+ const validateExtra = itemEvent.extra || {};
165
+ const locationUrl = safeParse(validateExtra.location_url, '');
166
+ const pageTitle = safeParse(validateExtra.page_title, '');
167
+ // Use page_title if available, otherwise fallback to location_url
168
+ const pageTypeText = pageTitle.length > 0 ? pageTitle : locationUrl;
169
+ // Build clickable link to location_url
170
+ if (locationUrl.length > 0 && pageTypeText.length > 0) {
171
+ data.page_type = `<a class="title-have-url" href="${encodeURI(locationUrl)}" target="_blank">${pageTypeText}</a>`;
172
+ }
173
+ else {
174
+ data.page_type = `<span class="title-no-url">${pageTypeText || 'N/A'}</span>`;
175
+ }
176
+ // Add event_source_name from insightPropertyName
177
+ data.event_source_name = safeParse(itemEvent.insightPropertyName, 'N/A');
178
+ }
179
+ };
180
+ const handleTicketEvent = (itemEvent, data) => {
181
+ if (itemEvent.pageType === 'send') {
182
+ data.array_ticket_names = getProductName(itemEvent.items);
183
+ }
184
+ };
185
+ const handleConversationEvent = (itemEvent, data) => {
186
+ if (itemEvent.pageType === 'chat') {
187
+ data.channel_name = itemEvent.items[0].category || 'N/A';
188
+ }
189
+ };
190
+ const handleUserEvent = (itemEvent, validateExtra, data) => {
191
+ if (itemEvent.pageType === 'identify' || itemEvent.pageType === 'reset_anonymous_id') {
192
+ data.user_id = itemEvent.userId;
193
+ }
194
+ else if (itemEvent.pageType === 'redeem_point' || itemEvent.pageType === 'earn_point') {
195
+ data.x_point = validateExtra.point || 'N/A';
196
+ data.transaction_id = validateExtra.transaction_id || 'N/A';
197
+ const { store_link } = getStoreLinkAndNumberProduct(validateExtra, itemEvent);
198
+ data.store_link = store_link;
199
+ }
200
+ };
201
+ const handleAdvertisingEvent = (itemEvent, validateExtra, data) => {
202
+ if (itemEvent.pageType === 'impression' ||
203
+ itemEvent.pageType === 'viewable' ||
204
+ itemEvent.pageType === 'click') {
205
+ data.campaign_name = safeParse(validateExtra.utm_campaign, 'N/A');
206
+ }
207
+ };
208
+ const handleBrowsingEvent = (itemEvent, validateExtra, data) => {
209
+ if (itemEvent.pageType === 'product_search') {
210
+ data.keyword = safeParse(validateExtra.src_search_term, '');
211
+ }
212
+ };
213
+ const handleEvoucherEvent = (itemEvent, validateExtra, data) => {
214
+ if (itemEvent.pageType === 'received') {
215
+ data.x_code = safeParse(validateExtra.coupon_code, 'N/A');
216
+ data.campaign_name = safeParse((validateExtra.campaign || {}).name, 'N/A');
217
+ }
218
+ };
219
+ const handleStoreEvent = (itemEvent, data) => {
220
+ if (itemEvent.pageType === 'visit') {
221
+ data.step_section = itemEvent.extra.step_section;
222
+ }
223
+ };
224
+ const handleScreenviewEvent = (itemEvent, validateExtra, data) => {
225
+ if (itemEvent.pageType === 'view' && validateExtra.screen_type) {
226
+ data.screen_type = validateExtra.screen_type;
227
+ // Add event_source_name from insightPropertyName
228
+ data.event_source_name = safeParse(itemEvent.insightPropertyName, 'N/A');
229
+ }
230
+ };
231
+ const handleEventTrackingCode = (eventTracking, keyTitleEvent, validateExtra, valuesReplace, infoEvent, config) => {
232
+ const { story = {} } = validateExtra;
233
+ if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'promotion_code_sent_tracking') {
234
+ valuesReplace.promotion_code = valuesReplace.event_name;
235
+ delete valuesReplace.event_name;
236
+ valuesReplace.journey_name = `<a class="title-have-url" href=${urlJourney(validateExtra, config)} target="_blank">${story.storyName}</a>`;
237
+ if (validateExtra.channel &&
238
+ mapTranslateCode.promotion_code_sent_tracking[parseInt(validateExtra.channel.id)]) {
239
+ infoEvent.translateCode =
240
+ mapTranslateCode.promotion_code_sent_tracking[parseInt(validateExtra.channel.id)].translateLabel;
241
+ }
242
+ }
243
+ else if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'promotion_code_used_tracking') {
244
+ valuesReplace.promotion_code = valuesReplace.event_name;
245
+ delete valuesReplace.event_name;
246
+ infoEvent.translateCode = translations._EVENT_CODE_USED_SMS;
247
+ }
248
+ else if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'viewable_advertising') {
249
+ valuesReplace.journey_name = `<a class="title-have-url" href=${urlJourney(validateExtra, config)} target="_blank">${story.storyName}</a>`;
250
+ delete valuesReplace.campaign_name;
251
+ if (validateExtra.channel &&
252
+ mapTranslateCode.viewable_advertising[parseInt(validateExtra.channel.id)]) {
253
+ infoEvent.translateCode =
254
+ mapTranslateCode.viewable_advertising[parseInt(validateExtra.channel.id)].translateLabel;
255
+ }
256
+ }
257
+ else if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'impression_advertising') {
258
+ valuesReplace.journey_name = `<a class="title-have-url" href=${urlJourney(validateExtra, config)} target="_blank">${story.storyName}</a>`;
259
+ delete valuesReplace.campaign_name;
260
+ if (validateExtra.channel &&
261
+ mapTranslateCode.impression_advertising[parseInt(validateExtra.channel.id)]) {
262
+ infoEvent.translateCode =
263
+ mapTranslateCode.impression_advertising[parseInt(validateExtra.channel.id)].translateLabel;
264
+ }
265
+ }
266
+ else if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'click_advertising') {
267
+ valuesReplace.journey_name = `<a class="title-have-url" href=${urlJourney(validateExtra, config)} target="_blank">${story.storyName}</a>`;
268
+ delete valuesReplace.campaign_name;
269
+ if (validateExtra.channel &&
270
+ mapTranslateCode.click_advertising[parseInt(validateExtra.channel.id)]) {
271
+ infoEvent.translateCode =
272
+ mapTranslateCode.click_advertising[parseInt(validateExtra.channel.id)].translateLabel;
273
+ }
274
+ }
275
+ else if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'sent_tracking') {
276
+ valuesReplace.journey_name = `<a class="title-have-url" href=${urlJourney(validateExtra, config)} target="_blank">${story.storyName}</a>`;
277
+ delete valuesReplace.campaign_name;
278
+ if (validateExtra.channel &&
279
+ mapTranslateCode.sent_tracking[parseInt(validateExtra.channel.id)]) {
280
+ infoEvent.translateCode =
281
+ mapTranslateCode.sent_tracking[parseInt(validateExtra.channel.id)].translateLabel;
282
+ }
283
+ }
284
+ else if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'journey_bo_update_info') {
285
+ valuesReplace.journey_name = `<strong>${story.storyName}</strong>`;
286
+ delete valuesReplace.campaign_name;
287
+ infoEvent.translateCode = translations._EVENT_BO_UPDATE;
288
+ }
289
+ };
290
+ const prepareInitialData = (itemEvent, eType, eventTracking, customerName) => {
123
291
  const keyTitleEvent = `${itemEvent.eventCategoryId}@@${itemEvent.eventActionId}`;
124
292
  const validateExtra = itemEvent.extra || {};
125
293
  const promotionCodes = itemEvent.items
@@ -127,142 +295,64 @@ export const getInfoEvent = (eType, itemEvent, eventTracking, customerName, conf
127
295
  .map((item) => item.name || item.id)
128
296
  .join(', ');
129
297
  let titleEvent = `${itemEvent.pageType} ${eType}`;
130
- let infoEvent = DATA_EVENT.map[titleEvent];
131
298
  titleEvent = `${titleEvent}${promotionCodes.length > 0
132
299
  ? `: <strong style="color: rgb(239, 51, 63);">${promotionCodes}</strong>`
133
300
  : ''}`;
134
- const data = {};
135
- data.event_name = titleEvent;
301
+ const data = {
302
+ event_name: titleEvent,
303
+ customer_name: customerName === '_THIS_PERSON_UPPERCASE'
304
+ ? translate(translations._THIS_PERSON_UPPERCASE, 'This user')
305
+ : customerName,
306
+ };
136
307
  if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'promotion_code_sent_tracking' ||
137
308
  eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'promotion_code_used_tracking') {
138
309
  data.event_name = `<strong style="color: rgb(239, 51, 63);">${promotionCodes}</strong>`;
139
310
  }
140
- data.customer_name =
141
- customerName === '_THIS_PERSON_UPPERCASE'
142
- ? translate(translations._THIS_PERSON_UPPERCASE, 'This user')
143
- : customerName;
144
- if (eventTracking.map[keyTitleEvent]) {
145
- titleEvent = eventTracking.map[keyTitleEvent].translateLabel;
146
- }
147
311
  if (validateExtra.store !== undefined) {
148
312
  const { store_link } = getStoreLinkAndNumberProduct(validateExtra, itemEvent);
149
313
  data.store_link = store_link;
150
314
  }
151
- // ETYPE === PRODUCT
315
+ return { keyTitleEvent, validateExtra, titleEvent, data, promotionCodes };
316
+ };
317
+ const processEventByType = (eType, itemEvent, validateExtra, data) => {
152
318
  if (eType === 'product') {
153
- let listProductName = 'N/A';
154
- listProductName = getProductName(itemEvent.items);
155
- data.product_name = listProductName;
156
- if (itemEvent.pageType === 'order_completed') {
157
- // PAGETYPE ORDER_COMPLETE
158
- data.order_id = validateExtra.order_id || 'N/A';
159
- }
160
- else if (itemEvent.pageType === 'purchase') {
161
- // PAGETYPE PURCHASE
162
- data.order_id = validateExtra.order_id || 'N/A';
163
- data.num_of_products = itemEvent.items.length || 'N/A';
164
- }
165
- else if (itemEvent.pageType === 'search') {
166
- // PAGETYPE SEARCH
167
- data.keywords = validateExtra.src_search_term || 'N/A';
168
- }
169
- else if (itemEvent.pageType === 'product_list_view') {
170
- // PAGETYPE PRODUCT_LIST_VIEW
171
- data.product_list = getProductName(itemEvent.items);
172
- }
173
- else if (itemEvent.pageType === 'click' ||
174
- itemEvent.pageType === 'view' ||
175
- itemEvent.pageType === 'add_to_cart') {
176
- // PAGETYPE CLICK OR VIEW
177
- // eslint-disable-next-line no-console
178
- console.log('itemEvent.items[0]', itemEvent);
179
- data.product_name = getStringHtmlByType(itemEvent.items[0], eType);
180
- }
319
+ handleProductEvent(itemEvent, validateExtra, data, eType);
181
320
  }
182
321
  else if (eType === 'order') {
183
- // PAGETYPE ORDER
184
- data.order_id = safeParse(validateExtra.order_id, 'N/A');
322
+ handleOrderEvent(validateExtra, data);
185
323
  }
186
324
  else if (eType === 'transaction') {
187
- // ETYPE TRANSACTION
188
- if (itemEvent.pageType === 'purchase') {
189
- data.order_id = safeParse(validateExtra.order_id, 'N/A');
190
- const { num_of_products } = getStoreLinkAndNumberProduct(validateExtra, itemEvent);
191
- data.num_of_products = num_of_products;
192
- }
193
- else {
194
- // PAGETYPE PURCHASE_OFFLINE
195
- data.transaction_id = safeParse(validateExtra.transaction_id, 'N/A');
196
- const { num_of_products, store_link } = getStoreLinkAndNumberProduct(validateExtra, itemEvent);
197
- data.num_of_products = num_of_products;
198
- data.store_link = store_link;
199
- }
325
+ handleTransactionEvent(itemEvent, validateExtra, data);
200
326
  }
201
327
  else if (eType === 'page' || eType === 'pageview') {
202
- // ETYPE PAGE OR PAGEVIEW
203
- if (itemEvent.pageType === 'view') {
204
- // PAGETYPE VIEW
205
- data.page_name = getStringHtmlByType(itemEvent.items[0], eType);
206
- }
328
+ handlePageEvent(itemEvent, data);
207
329
  }
208
330
  else if (eType === 'ticket') {
209
- // ETYPE TICKET
210
- if (itemEvent.pageType === 'send') {
211
- // PAGETYPE SEND
212
- data.array_ticket_names = getProductName(itemEvent.items);
213
- }
331
+ handleTicketEvent(itemEvent, data);
214
332
  }
215
333
  else if (eType === 'conversation') {
216
- // ETYPE CONVERSATION
217
- if (itemEvent.pageType === 'chat') {
218
- // PAGETYPE CHAT
219
- data.channel_name = itemEvent.items[0].category || 'N/A';
220
- }
334
+ handleConversationEvent(itemEvent, data);
221
335
  }
222
336
  else if (eType === 'user') {
223
- // ETYPE USER
224
- if (itemEvent.pageType === 'identify' || itemEvent.pageType === 'reset_anonymous_id') {
225
- // PAGETYPE IDENTIFY OR RESET_ANONYMUS_ID
226
- data.user_id = itemEvent.userId;
227
- }
228
- else if (itemEvent.pageType === 'redeem_point' || itemEvent.pageType === 'earn_point') {
229
- // PAGETYPE REDEEM_POINT OR EARN_POINT
230
- data.x_point = validateExtra.point || 'N/A';
231
- data.transaction_id = validateExtra.transaction_id || 'N/A';
232
- const { store_link } = getStoreLinkAndNumberProduct(validateExtra, itemEvent);
233
- data.store_link = store_link;
234
- }
337
+ handleUserEvent(itemEvent, validateExtra, data);
235
338
  }
236
339
  else if (eType === 'advertising') {
237
- // ETYPE ADVERTISING
238
- if (itemEvent.pageType === 'impression' ||
239
- itemEvent.pageType === 'viewable' ||
240
- itemEvent.pageType === 'click') {
241
- // PAGETYPE IMPRESSION , VIEWABLE, CLICK
242
- data.campaign_name = safeParse(validateExtra.utm_campaign, 'N/A');
243
- }
340
+ handleAdvertisingEvent(itemEvent, validateExtra, data);
244
341
  }
245
342
  else if (eType === 'browsing') {
246
- if (itemEvent.pageType === 'product_search') {
247
- data.keyword = safeParse(validateExtra.src_search_term, '');
248
- }
343
+ handleBrowsingEvent(itemEvent, validateExtra, data);
249
344
  }
250
345
  else if (eType === 'evoucher') {
251
- if (itemEvent.pageType === 'received') {
252
- data.x_code = safeParse(validateExtra.coupon_code, 'N/A');
253
- data.campaign_name = safeParse((validateExtra.campaign || {}).name, 'N/A');
254
- }
346
+ handleEvoucherEvent(itemEvent, validateExtra, data);
255
347
  }
256
348
  else if (eType === 'store') {
257
- if (itemEvent.pageType === 'visit') {
258
- data.step_section = itemEvent.extra.step_section;
259
- }
349
+ handleStoreEvent(itemEvent, data);
260
350
  }
261
351
  else if (eType === 'screenview') {
262
- if (itemEvent.pageType === 'view' && validateExtra.screen_type) {
263
- data.screen_type = validateExtra.screen_type;
264
- }
352
+ handleScreenviewEvent(itemEvent, validateExtra, data);
265
353
  }
354
+ };
355
+ const buildInfoEvent = (infoEvent, eventTracking, keyTitleEvent, validateExtra, data, config) => {
266
356
  let valuesReplace = {};
267
357
  if (infoEvent) {
268
358
  infoEvent.iconName = get(eventTracking, `map.${keyTitleEvent}.iconUrl`);
@@ -281,66 +371,12 @@ export const getInfoEvent = (eType, itemEvent, eventTracking, customerName, conf
281
371
  iconName: eventTracking.map[keyTitleEvent]?.iconUrl,
282
372
  showRedeem: false,
283
373
  };
284
- const { story = {} } = validateExtra;
285
- // data.event_name = titleEvent;
286
374
  valuesReplace = getValuesReplace(infoEvent.objectReplace, data);
287
- if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'promotion_code_sent_tracking') {
288
- valuesReplace.promotion_code = valuesReplace.event_name;
289
- delete valuesReplace.event_name;
290
- valuesReplace.journey_name = `<a class="title-have-url" href=${urlJourney(validateExtra, config)} target="_blank">${story.storyName}</a>`;
291
- if (validateExtra.channel &&
292
- mapTranslateCode.promotion_code_sent_tracking[parseInt(validateExtra.channel.id)]) {
293
- infoEvent.translateCode =
294
- mapTranslateCode.promotion_code_sent_tracking[parseInt(validateExtra.channel.id)].translateLabel;
295
- }
296
- }
297
- else if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'promotion_code_used_tracking') {
298
- valuesReplace.promotion_code = valuesReplace.event_name;
299
- delete valuesReplace.event_name;
300
- infoEvent.translateCode = translations._EVENT_CODE_USED_SMS;
301
- }
302
- else if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'viewable_advertising') {
303
- valuesReplace.journey_name = `<a class="title-have-url" href=${urlJourney(validateExtra, config)} target="_blank">${story.storyName}</a>`;
304
- delete valuesReplace.campaign_name;
305
- if (validateExtra.channel &&
306
- mapTranslateCode.viewable_advertising[parseInt(validateExtra.channel.id)]) {
307
- infoEvent.translateCode =
308
- mapTranslateCode.viewable_advertising[parseInt(validateExtra.channel.id)].translateLabel;
309
- }
310
- }
311
- else if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'impression_advertising') {
312
- valuesReplace.journey_name = `<a class="title-have-url" href=${urlJourney(validateExtra, config)} target="_blank">${story.storyName}</a>`;
313
- delete valuesReplace.campaign_name;
314
- if (validateExtra.channel &&
315
- mapTranslateCode.impression_advertising[parseInt(validateExtra.channel.id)]) {
316
- infoEvent.translateCode =
317
- mapTranslateCode.impression_advertising[parseInt(validateExtra.channel.id)].translateLabel;
318
- }
319
- }
320
- else if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'click_advertising') {
321
- valuesReplace.journey_name = `<a class="title-have-url" href=${urlJourney(validateExtra, config)} target="_blank">${story.storyName}</a>`;
322
- delete valuesReplace.campaign_name;
323
- if (validateExtra.channel &&
324
- mapTranslateCode.click_advertising[parseInt(validateExtra.channel.id)]) {
325
- infoEvent.translateCode =
326
- mapTranslateCode.click_advertising[parseInt(validateExtra.channel.id)].translateLabel;
327
- }
328
- }
329
- else if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'sent_tracking') {
330
- valuesReplace.journey_name = `<a class="title-have-url" href=${urlJourney(validateExtra, config)} target="_blank">${story.storyName}</a>`;
331
- delete valuesReplace.campaign_name;
332
- if (validateExtra.channel &&
333
- mapTranslateCode.sent_tracking[parseInt(validateExtra.channel.id)]) {
334
- infoEvent.translateCode =
335
- mapTranslateCode.sent_tracking[parseInt(validateExtra.channel.id)].translateLabel;
336
- }
337
- }
338
- else if (eventTracking.map[keyTitleEvent]?.eventTrackingCode === 'journey_bo_update_info') {
339
- valuesReplace.journey_name = `<strong>${story.storyName}</strong>`;
340
- delete valuesReplace.campaign_name;
341
- infoEvent.translateCode = translations._EVENT_BO_UPDATE;
342
- }
375
+ handleEventTrackingCode(eventTracking, keyTitleEvent, validateExtra, valuesReplace, infoEvent, config);
343
376
  }
377
+ return { infoEvent, valuesReplace };
378
+ };
379
+ const buildFullContentEvent = (infoEvent, titleEvent, valuesReplace, data) => {
344
380
  let fullContentEvent = translate(infoEvent.translateCode, titleEvent, valuesReplace);
345
381
  if (infoEvent.objectReplace.includes('store_link') === false && data.store_link !== undefined) {
346
382
  fullContentEvent += ` ${translateAt} <strong style="color: rgb(239, 51, 63);">${data.store_link}</strong>`;
@@ -348,6 +384,9 @@ export const getInfoEvent = (eType, itemEvent, eventTracking, customerName, conf
348
384
  else if (data.step_section) {
349
385
  fullContentEvent += ` ${translateAt} <strong style="color: rgb(239, 51, 63);">${data.step_section}</strong>`;
350
386
  }
387
+ return fullContentEvent;
388
+ };
389
+ const calculateSlideSettings = (itemEvent, infoEvent) => {
351
390
  let perShow = 2;
352
391
  if (itemEvent.items.length > 0 && itemEvent.items[0].item_type === 'product') {
353
392
  perShow = itemEvent.items.length < 2 ? itemEvent.items.length : 2;
@@ -358,6 +397,28 @@ export const getInfoEvent = (eType, itemEvent, eventTracking, customerName, conf
358
397
  limitShowSlide = infoEvent.limitShowSlide;
359
398
  }
360
399
  }
400
+ return { perShow, limitShowSlide };
401
+ };
402
+ export const getInfoEvent = (params) => {
403
+ const { eType, itemEvent, eventTracking, config, customerName: customerNameParam } = params;
404
+ const customerName = customerNameParam || '_THIS_PERSON_UPPERCASE';
405
+ // Step 1: Prepare initial data and extract common fields
406
+ const { keyTitleEvent, validateExtra, titleEvent: initialTitleEvent, data, } = prepareInitialData(itemEvent, eType, eventTracking, customerName);
407
+ // Step 2: Update titleEvent if eventTracking has a mapping
408
+ let titleEvent = initialTitleEvent;
409
+ if (eventTracking.map[keyTitleEvent]) {
410
+ titleEvent = eventTracking.map[keyTitleEvent].translateLabel;
411
+ }
412
+ // Step 3: Process event based on eType
413
+ processEventByType(eType, itemEvent, validateExtra, data);
414
+ // Step 4: Build infoEvent and valuesReplace
415
+ let infoEvent = DATA_EVENT.map[`${itemEvent.pageType} ${eType}`];
416
+ const { infoEvent: processedInfoEvent, valuesReplace } = buildInfoEvent(infoEvent, eventTracking, keyTitleEvent, validateExtra, data, config);
417
+ infoEvent = processedInfoEvent;
418
+ // Step 5: Build full content event text
419
+ const fullContentEvent = buildFullContentEvent(infoEvent, titleEvent, valuesReplace, data);
420
+ // Step 6: Calculate slide settings
421
+ const { perShow, limitShowSlide } = calculateSlideSettings(itemEvent, infoEvent);
361
422
  return {
362
423
  titleEvent,
363
424
  fullContentEvent,