@mparticle/web-facebook-kit 2.1.1 → 2.3.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.
@@ -12,6 +12,7 @@ function isObject(val) {
12
12
  }
13
13
 
14
14
  var isobject = /*#__PURE__*/Object.freeze({
15
+ __proto__: null,
15
16
  'default': isObject
16
17
  });
17
18
 
@@ -35,369 +36,473 @@ var isobject$1 = getCjsExportFromNamespace(isobject);
35
36
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36
37
  // See the License for the specific language governing permissions and
37
38
  // limitations under the License.
38
-
39
-
40
- var name = 'Facebook',
41
- moduleId = 45,
42
- MessageType = {
43
- SessionStart: 1,
44
- SessionEnd: 2,
45
- PageView: 3,
46
- PageEvent: 4,
47
- CrashReport: 5,
48
- OptOut: 6,
49
- Commerce: 16,
50
- },
51
- IdentityType = {
52
- Other: 0,
53
- CustomerId: 1,
54
- Facebook: 2,
55
- Twitter: 3,
56
- Google: 4,
57
- Microsoft: 5,
58
- Yahoo: 6,
59
- Email: 7,
60
- FacebookCustomAudienceId: 9,
61
- Other2: 10,
62
- Other3: 11,
63
- Other4: 12,
64
- Other5: 13,
65
- Other6: 14,
66
- Other7: 15,
67
- Other8: 16,
68
- Other9: 17,
69
- Other10: 18,
70
- MobileNumber: 19,
71
- PhoneNumber2: 20,
72
- PhoneNumber3: 21,
73
- },
74
- SupportedCommerceTypes = [],
75
- // Standard FB Event Names from https://developers.facebook.com/docs/facebook-pixel/reference#standard-events
76
- ADD_TO_CART_EVENT_NAME = 'AddToCart',
77
- ADD_TO_WISHLIST_EVENT_NAME = 'AddToWishlist',
78
- CHECKOUT_EVENT_NAME = 'InitiateCheckout',
79
- PAGE_VIEW_EVENT_NAME = 'PageView',
80
- PURCHASE_EVENT_NAME = 'Purchase',
81
- REMOVE_FROM_CART_EVENT_NAME = 'RemoveFromCart',
82
- VIEW_CONTENT_EVENT_NAME = 'ViewContent',
83
- constructor = function () {
84
- var self = this,
85
- isInitialized = false,
86
- reportingService = null;
87
-
88
- self.name = name;
89
-
90
- function initForwarder(settings, service, testMode, trackerId, userAttributes, userIdentities) {
91
- reportingService = service;
92
-
93
- SupportedCommerceTypes = [
94
- mParticle.ProductActionType.Checkout,
95
- mParticle.ProductActionType.Purchase,
96
- mParticle.ProductActionType.AddToCart,
97
- mParticle.ProductActionType.RemoveFromCart,
98
- mParticle.ProductActionType.AddToWishlist,
99
- mParticle.ProductActionType.ViewDetail
100
- ];
101
39
 
102
- try {
103
- if (!testMode) {
104
- !function (f, b, e, v, n, t, s) {
105
- if (f.fbq) return; n = f.fbq = function () { n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments); }; if (!f._fbq) f._fbq = n;
106
- n.push = n; n.loaded = !0; n.version = '2.0'; n.queue = []; t = b.createElement(e); t.async = !0; t.src = v; s = b.getElementsByTagName(e)[0];
107
- s.parentNode.insertBefore(t, s);
108
- } (window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
109
-
110
- var visitorData = {};
111
-
112
- if(settings.externalUserIdentityType && userIdentities && userIdentities.length > 0) {
113
- var selectedType = IdentityType[settings.externalUserIdentityType];
114
- var selectedIdentity = userIdentities.filter(function (identityElement) {
115
- if (identityElement.Type === selectedType) {
116
- return identityElement.Identity;
117
- }
118
- });
119
-
120
- if (selectedIdentity.length > 0) {
121
- visitorData['external_id'] = selectedIdentity[0].Identity;
40
+
41
+ var name = 'Facebook',
42
+ moduleId = 45,
43
+ MessageType = {
44
+ SessionStart: 1,
45
+ SessionEnd: 2,
46
+ PageView: 3,
47
+ PageEvent: 4,
48
+ CrashReport: 5,
49
+ OptOut: 6,
50
+ Commerce: 16,
51
+ },
52
+ IdentityType = {
53
+ Other: 0,
54
+ CustomerId: 1,
55
+ Facebook: 2,
56
+ Twitter: 3,
57
+ Google: 4,
58
+ Microsoft: 5,
59
+ Yahoo: 6,
60
+ Email: 7,
61
+ FacebookCustomAudienceId: 9,
62
+ Other2: 10,
63
+ Other3: 11,
64
+ Other4: 12,
65
+ Other5: 13,
66
+ Other6: 14,
67
+ Other7: 15,
68
+ Other8: 16,
69
+ Other9: 17,
70
+ Other10: 18,
71
+ MobileNumber: 19,
72
+ PhoneNumber2: 20,
73
+ PhoneNumber3: 21,
74
+ },
75
+ SupportedCommerceTypes = [],
76
+ // Standard FB Event Names from https://developers.facebook.com/docs/facebook-pixel/reference#standard-events
77
+ ADD_TO_CART_EVENT_NAME = 'AddToCart',
78
+ ADD_TO_WISHLIST_EVENT_NAME = 'AddToWishlist',
79
+ CHECKOUT_EVENT_NAME = 'InitiateCheckout',
80
+ PAGE_VIEW_EVENT_NAME = 'PageView',
81
+ PURCHASE_EVENT_NAME = 'Purchase',
82
+ REMOVE_FROM_CART_EVENT_NAME = 'RemoveFromCart',
83
+ VIEW_CONTENT_EVENT_NAME = 'ViewContent',
84
+ constructor = function () {
85
+ var self = this,
86
+ isInitialized = false,
87
+ reportingService = null,
88
+ settings,
89
+ productAttributeMapping;
90
+
91
+ self.name = name;
92
+
93
+ function initForwarder(forwarderSettings, service, testMode, trackerId, userAttributes, userIdentities) {
94
+ settings = forwarderSettings;
95
+ reportingService = service;
96
+
97
+ SupportedCommerceTypes = [
98
+ mParticle.ProductActionType.Checkout,
99
+ mParticle.ProductActionType.Purchase,
100
+ mParticle.ProductActionType.AddToCart,
101
+ mParticle.ProductActionType.RemoveFromCart,
102
+ mParticle.ProductActionType.AddToWishlist,
103
+ mParticle.ProductActionType.ViewDetail
104
+ ];
105
+
106
+ try {
107
+ if (!testMode) {
108
+ !function (f, b, e, v, n, t, s) {
109
+ if (f.fbq) return; n = f.fbq = function () { n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments); }; if (!f._fbq) f._fbq = n;
110
+ n.push = n; n.loaded = !0; n.version = '2.0'; n.queue = []; t = b.createElement(e); t.async = !0; t.src = v; s = b.getElementsByTagName(e)[0];
111
+ s.parentNode.insertBefore(t, s);
112
+ } (window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
113
+
114
+ var visitorData = {};
115
+
116
+ if(settings.externalUserIdentityType && userIdentities && userIdentities.length > 0) {
117
+ var selectedType = IdentityType[settings.externalUserIdentityType];
118
+ var selectedIdentity = userIdentities.filter(function (identityElement) {
119
+ if (identityElement.Type === selectedType) {
120
+ return identityElement.Identity;
122
121
  }
122
+ });
123
+
124
+ if (selectedIdentity.length > 0) {
125
+ visitorData['external_id'] = selectedIdentity[0].Identity;
123
126
  }
124
127
  }
128
+ }
125
129
 
126
- if (settings.disablePushState === 'True') {
127
- // Facebook will automatically track page views whenever a new state is pushed to the HTML 5 History State API
128
- // this option can be disabled to prevent duplicate page views
129
- // https://developers.facebook.com/docs/facebook-pixel/implementation/tag_spa/#tagging-single-page-applications
130
- fbq.disablePushState = true;
131
- }
132
- fbq('init', settings.pixelId, visitorData);
130
+ if (settings.disablePushState === 'True') {
131
+ // Facebook will automatically track page views whenever a new state is pushed to the HTML 5 History State API
132
+ // this option can be disabled to prevent duplicate page views
133
+ // https://developers.facebook.com/docs/facebook-pixel/implementation/tag_spa/#tagging-single-page-applications
134
+ fbq.disablePushState = true;
135
+ }
136
+ fbq('init', settings.pixelId, visitorData);
137
+
138
+ loadMappings();
133
139
 
134
- isInitialized = true;
140
+ isInitialized = true;
135
141
 
136
- return 'Successfully initialized: ' + name;
142
+ return 'Successfully initialized: ' + name;
137
143
 
138
- }
139
- catch (e) {
140
- return 'Can\'t initialize forwarder: ' + name + ':' + e;
141
- }
142
144
  }
145
+ catch (e) {
146
+ return 'Can\'t initialize forwarder: ' + name + ':' + e;
147
+ }
148
+ }
143
149
 
144
- function processEvent(event) {
145
- var reportEvent = false;
146
-
147
- if (!isInitialized) {
148
- return 'Can\'t send forwarder ' + name + ', not initialized';
149
- }
150
+ function loadMappings() {
151
+ productAttributeMapping = settings.productAttributeMapping
152
+ ? JSON.parse(settings.productAttributeMapping.replace(/"/g, '"'))
153
+ : [];
154
+ }
150
155
 
151
- try {
152
- if (event.EventDataType == MessageType.PageView) {
153
- reportEvent = true;
154
- logPageView(event);
155
- }
156
- else if (event.EventDataType == MessageType.PageEvent) {
157
- reportEvent = true;
158
- logPageEvent(event);
159
- }
160
- else if (event.EventDataType == MessageType.Commerce) {
161
- reportEvent = logCommerceEvent(event);
162
- }
156
+ function processEvent(event) {
157
+ var reportEvent = false;
163
158
 
164
- if (reportEvent && reportingService) {
165
- reportingService(self, event);
166
- }
159
+ if (!isInitialized) {
160
+ return 'Can\'t send forwarder ' + name + ', not initialized';
161
+ }
167
162
 
168
- return 'Successfully sent to forwarder ' + name;
163
+ try {
164
+ if (event.EventDataType == MessageType.PageView) {
165
+ reportEvent = true;
166
+ logPageView(event);
167
+ }
168
+ else if (event.EventDataType == MessageType.PageEvent) {
169
+ reportEvent = true;
170
+ logPageEvent(event);
169
171
  }
170
- catch (error) {
171
- return 'Can\'t send to forwarder: ' + name + ' ' + error;
172
+ else if (event.EventDataType == MessageType.Commerce) {
173
+ reportEvent = logCommerceEvent(event);
172
174
  }
175
+
176
+ if (reportEvent && reportingService) {
177
+ reportingService(self, event);
178
+ }
179
+
180
+ return 'Successfully sent to forwarder ' + name;
181
+ }
182
+ catch (error) {
183
+ return 'Can\'t send to forwarder: ' + name + ' ' + error;
173
184
  }
185
+ }
186
+
187
+ function logCommerceEvent(event) {
188
+ if (event.ProductAction &&
189
+ event.ProductAction.ProductList &&
190
+ event.ProductAction.ProductActionType &&
191
+ SupportedCommerceTypes.indexOf(event.ProductAction.ProductActionType) > -1) {
192
+ var eventName,
193
+ totalValue,
194
+ params = cloneEventAttributes(event),
195
+ eventID = createEventId(event),
196
+ sendProductNamesAsContents = settings.sendProductNamesasContents || false;
174
197
 
175
- function logCommerceEvent(event) {
176
- if (event.ProductAction &&
177
- event.ProductAction.ProductList &&
178
- event.ProductAction.ProductActionType &&
179
- SupportedCommerceTypes.indexOf(event.ProductAction.ProductActionType) > -1) {
198
+ params['currency'] = event.CurrencyCode || 'USD';
180
199
 
181
- var eventName,
182
- totalValue,
183
- params = cloneEventAttributes(event),
184
- eventID = createEventId(event);
185
- params['currency'] = event.CurrencyCode || 'USD';
200
+ if (event.EventName) {
201
+ params['content_name'] = event.EventName;
202
+ }
186
203
 
187
- if (event.EventName) {
188
- params['content_name'] = event.EventName;
204
+ var productSkus = event.ProductAction.ProductList.reduce(function (arr, curr) {
205
+ if (curr.Sku) {
206
+ arr.push(curr.Sku);
189
207
  }
208
+ return arr;
209
+ }, []);
190
210
 
191
- var productSkus = event.ProductAction.ProductList.reduce(function (arr, curr) {
192
- if (curr.Sku) {
193
- arr.push(curr.Sku);
194
- }
195
- return arr;
196
- }, []);
211
+ if (productSkus && productSkus.length > 0) {
212
+ params['content_ids'] = productSkus;
213
+ }
197
214
 
198
- if (productSkus && productSkus.length > 0) {
199
- params['content_ids'] = productSkus;
215
+ // Override content_name with product names array if setting enabled
216
+ if (sendProductNamesAsContents) {
217
+ var productNames = buildProductNames(event.ProductAction.ProductList);
218
+ if (productNames && productNames.length > 0) {
219
+ params['content_name'] = productNames;
200
220
  }
221
+ }
201
222
 
202
- if (event.ProductAction.ProductActionType == mParticle.ProductActionType.AddToWishlist ||
203
- event.ProductAction.ProductActionType == mParticle.ProductActionType.Checkout) {
204
- var eventCategory = getEventCategoryString(event);
205
- if (eventCategory) {
206
- params['content_category'] = eventCategory;
207
- }
208
- if (event.ProductAction.ProductActionType == mParticle.ProductActionType.Checkout && event.ProductAction.CheckoutStep) {
209
- params['checkout_step'] = event.ProductAction.CheckoutStep;
210
- }
211
- }
223
+ // Set order_id if TransactionId exists
224
+ if (event.ProductAction.TransactionId) {
225
+ params['order_id'] = event.ProductAction.TransactionId;
226
+ }
212
227
 
213
- if (event.ProductAction.ProductActionType == mParticle.ProductActionType.AddToCart ||
214
- event.ProductAction.ProductActionType == mParticle.ProductActionType.AddToWishlist ||
215
- event.ProductAction.ProductActionType == mParticle.ProductActionType.ViewDetail) {
228
+ // Build contents array
229
+ var contents = buildProductContents(event.ProductAction.ProductList);
230
+ if (contents && contents.length > 0) {
231
+ params['contents'] = contents;
232
+ }
216
233
 
217
- totalValue = event.ProductAction.ProductList.reduce(function(sum, product){
218
- if (isNumeric(product.Price) && isNumeric(product.Quantity)) {
219
- sum += product.Price * product.Quantity;
220
- }
221
- return sum;
222
- }, 0);
234
+ if (event.ProductAction.ProductActionType == mParticle.ProductActionType.AddToWishlist ||
235
+ event.ProductAction.ProductActionType == mParticle.ProductActionType.Checkout) {
236
+ var eventCategory = getEventCategoryString(event);
237
+ if (eventCategory) {
238
+ params['content_category'] = eventCategory;
239
+ }
240
+ if (event.ProductAction.ProductActionType == mParticle.ProductActionType.Checkout && event.ProductAction.CheckoutStep) {
241
+ params['checkout_step'] = event.ProductAction.CheckoutStep;
242
+ }
243
+ }
223
244
 
224
- params['value'] = totalValue;
245
+ if (event.ProductAction.ProductActionType == mParticle.ProductActionType.AddToCart ||
246
+ event.ProductAction.ProductActionType == mParticle.ProductActionType.AddToWishlist ||
247
+ event.ProductAction.ProductActionType == mParticle.ProductActionType.ViewDetail) {
225
248
 
226
- if (event.ProductAction.ProductActionType == mParticle.ProductActionType.AddToWishlist){
227
- eventName = ADD_TO_WISHLIST_EVENT_NAME;
228
- }
229
- else if (event.ProductAction.ProductActionType == mParticle.ProductActionType.AddToCart){
230
- eventName = ADD_TO_CART_EVENT_NAME;
231
- }
232
- else{
233
- eventName = VIEW_CONTENT_EVENT_NAME;
249
+ totalValue = event.ProductAction.ProductList.reduce(function(sum, product){
250
+ if (isNumeric(product.Price) && isNumeric(product.Quantity)) {
251
+ sum += product.Price * product.Quantity;
234
252
  }
253
+ return sum;
254
+ }, 0);
235
255
 
256
+ params['value'] = totalValue;
257
+
258
+ if (event.ProductAction.ProductActionType == mParticle.ProductActionType.AddToWishlist){
259
+ eventName = ADD_TO_WISHLIST_EVENT_NAME;
260
+ }
261
+ else if (event.ProductAction.ProductActionType == mParticle.ProductActionType.AddToCart){
262
+ eventName = ADD_TO_CART_EVENT_NAME;
263
+ }
264
+ else {
265
+ eventName = VIEW_CONTENT_EVENT_NAME;
236
266
  }
237
- else if (event.ProductAction.ProductActionType == mParticle.ProductActionType.Checkout ||
238
- event.ProductAction.ProductActionType == mParticle.ProductActionType.Purchase) {
239
267
 
240
- eventName = event.ProductAction.ProductActionType == mParticle.ProductActionType.Checkout ? CHECKOUT_EVENT_NAME : PURCHASE_EVENT_NAME;
268
+ }
269
+ else if (event.ProductAction.ProductActionType == mParticle.ProductActionType.Checkout ||
270
+ event.ProductAction.ProductActionType == mParticle.ProductActionType.Purchase) {
241
271
 
242
- if (event.ProductAction.TotalAmount) {
243
- params['value'] = event.ProductAction.TotalAmount;
244
- }
272
+ eventName = event.ProductAction.ProductActionType == mParticle.ProductActionType.Checkout ? CHECKOUT_EVENT_NAME : PURCHASE_EVENT_NAME;
245
273
 
246
- var num_items = event.ProductAction.ProductList.reduce(function(sum, product){
247
- if (isNumeric(product.Quantity)) {
248
- sum += product.Quantity;
274
+ if (event.ProductAction.TotalAmount) {
275
+ params['value'] = event.ProductAction.TotalAmount;
276
+ }
277
+
278
+ var num_items = event.ProductAction.ProductList.reduce(function(sum, product){
279
+ if (isNumeric(product.Quantity)) {
280
+ sum += product.Quantity;
281
+ }
282
+ return sum;
283
+ }, 0);
284
+ params['num_items'] = num_items;
285
+ }
286
+ else if (event.ProductAction.ProductActionType == mParticle.ProductActionType.RemoveFromCart) {
287
+ eventName = REMOVE_FROM_CART_EVENT_NAME;
288
+
289
+ // remove from cart can be performed in 1 of 2 ways:
290
+ // 1. mParticle.eCommerce.logProductEvent(), which contains event.ProductAction.TotalAmount
291
+ // 2. mParticle.eCommerce.Cart.remove(), which does not contain event.ProductAction.TotalAmount
292
+ // when there is no TotalAmount, a manual calculation must be done
293
+ if (event.ProductAction.TotalAmount) {
294
+ totalValue = event.ProductAction.TotalAmount;
295
+ } else {
296
+ totalValue = event.ProductAction.ProductList.reduce(function(sum, product) {
297
+ if (isNumeric(product.TotalAmount)) {
298
+ sum += product.TotalAmount;
249
299
  }
250
300
  return sum;
251
301
  }, 0);
252
- params['num_items'] = num_items;
253
- }
254
- else if (event.ProductAction.ProductActionType == mParticle.ProductActionType.RemoveFromCart) {
255
- eventName = REMOVE_FROM_CART_EVENT_NAME;
256
-
257
- // remove from cart can be performed in 1 of 2 ways:
258
- // 1. mParticle.eCommerce.logProductEvent(), which contains event.ProductAction.TotalAmount
259
- // 2. mParticle.eCommerce.Cart.remove(), which does not contain event.ProductAction.TotalAmount
260
- // when there is no TotalAmount, a manual calculation must be done
261
- if (event.ProductAction.TotalAmount) {
262
- totalValue = event.ProductAction.TotalAmount;
263
- } else {
264
- totalValue = event.ProductAction.ProductList.reduce(function(sum, product) {
265
- if (isNumeric(product.TotalAmount)) {
266
- sum += product.TotalAmount;
267
- }
268
- return sum;
269
- }, 0);
270
- }
271
-
272
- params['value'] = totalValue;
273
-
274
- fbq('trackCustom', eventName || 'customEvent', params, eventID);
275
- return true;
276
302
  }
277
303
 
278
- if (eventName) {
279
- fbq('track', eventName, params, eventID);
280
- }
281
- else {
282
- return false;
283
- }
304
+ params['value'] = totalValue;
284
305
 
306
+ fbq('trackCustom', eventName || 'customEvent', params, eventID);
285
307
  return true;
286
308
  }
287
309
 
288
- return false;
289
- }
310
+ if (eventName) {
311
+ fbq('track', eventName, params, eventID);
312
+ }
313
+ else {
314
+ return false;
315
+ }
290
316
 
291
- function logPageView(event) {
292
- logPageEvent(event, PAGE_VIEW_EVENT_NAME);
317
+ return true;
293
318
  }
294
319
 
295
- function logPageEvent(event, eventName) {
296
- var params = cloneEventAttributes(event);
297
- var eventID = createEventId(event);
298
-
299
- eventName = eventName || event.EventName;
300
- if (event.EventName) {
301
- params['content_name'] = event.EventName;
302
- }
320
+ return false;
321
+ }
303
322
 
304
- fbq('trackCustom', eventName || 'customEvent', params, eventID);
305
- }
323
+ function logPageView(event) {
324
+ logPageEvent(event, PAGE_VIEW_EVENT_NAME);
325
+ }
306
326
 
307
- function cloneEventAttributes(event) {
308
- var attr = {};
309
- if (event && event.EventAttributes) {
310
- try {
311
- attr = JSON.parse(JSON.stringify(event.EventAttributes));
312
- }
313
- catch (e) {
314
- //
315
- }
316
- }
317
- return attr;
318
- }
327
+ function logPageEvent(event, eventName) {
328
+ var params = cloneEventAttributes(event);
329
+ var eventID = createEventId(event);
319
330
 
320
- function isNumeric(n) {
321
- return !isNaN(parseFloat(n)) && isFinite(n);
331
+ eventName = eventName || event.EventName;
332
+ if (event.EventName) {
333
+ params['content_name'] = event.EventName;
322
334
  }
323
335
 
324
- function getEventCategoryString(event) {
336
+ fbq('trackCustom', eventName || 'customEvent', params, eventID);
337
+ }
325
338
 
326
- var enumTypeValues;
327
- var enumValue;
328
- if (event.EventDataType == MessageType.Commerce) {
329
- enumTypeValues = event.EventCategory ? mParticle.CommerceEventType : mParticle.ProductActionType;
330
- enumValue = event.EventCategory || event.ProductAction.ProductActionType;
339
+ function cloneEventAttributes(event) {
340
+ var attr = {};
341
+ if (event && event.EventAttributes) {
342
+ try {
343
+ attr = JSON.parse(JSON.stringify(event.EventAttributes));
331
344
  }
332
- else {
333
- enumTypeValues = mParticle.EventType;
334
- enumValue = event.EventCategory;
345
+ catch (e) {
346
+ //
335
347
  }
348
+ }
349
+ return attr;
350
+ }
336
351
 
337
- if (enumTypeValues && enumValue) {
352
+ function isNumeric(n) {
353
+ return !isNaN(parseFloat(n)) && isFinite(n);
354
+ }
338
355
 
339
- for (var category in enumTypeValues) {
340
- if (enumValue == enumTypeValues[category]) {
341
- return category;
342
- }
343
- }
344
- }
356
+ function getEventCategoryString(event) {
345
357
 
346
- return null;
358
+ var enumTypeValues;
359
+ var enumValue;
360
+ if (event.EventDataType == MessageType.Commerce) {
361
+ enumTypeValues = event.EventCategory ? mParticle.CommerceEventType : mParticle.ProductActionType;
362
+ enumValue = event.EventCategory || event.ProductAction.ProductActionType;
347
363
  }
364
+ else {
365
+ enumTypeValues = mParticle.EventType;
366
+ enumValue = event.EventCategory;
367
+ }
368
+
369
+ if (enumTypeValues && enumValue) {
348
370
 
349
- // https://developers.facebook.com/docs/marketing-api/conversions-api/deduplicate-pixel-and-server-events#event-deduplication-options
350
- function createEventId(event) {
351
- return {
352
- eventID: event.SourceMessageId || null
371
+ for (var category in enumTypeValues) {
372
+ if (enumValue == enumTypeValues[category]) {
373
+ return category;
374
+ }
353
375
  }
354
376
  }
355
377
 
356
- this.init = initForwarder;
357
- this.process = processEvent;
358
- };
359
-
360
- function getId() {
361
- return moduleId;
362
- }
378
+ return null;
379
+ }
363
380
 
364
- function register(config) {
365
- if (!config) {
366
- console.log('You must pass a config object to register the kit ' + name);
367
- return;
381
+ /**
382
+ * Builds contents array for Facebook Pixel commerce events.
383
+ * Creates a nested array of content items with product details.
384
+ *
385
+ * @param {Array} productList - Array of products from event.ProductAction.ProductList
386
+ * @returns {Array} Array of content objects for Facebook Pixel
387
+ */
388
+ function buildProductContents(productList) {
389
+ if (!productList || productList.length === 0) {
390
+ return [];
391
+ }
392
+
393
+ return productList
394
+ .filter(function(product) {
395
+ return product && product.Sku;
396
+ })
397
+ .map(function(product) {
398
+ var contentItem = {
399
+ id: product.Sku,
400
+ quantity: isNumeric(product.Quantity) ? product.Quantity : 1,
401
+ name: product.Name,
402
+ brand: product.Brand,
403
+ category: product.Category,
404
+ variant: product.Variant,
405
+ item_price: isNumeric(product.Price) ? product.Price : null
406
+ };
407
+
408
+ // Apply configured mappings to custom attributes
409
+ productAttributeMapping.forEach(function(productMapping) {
410
+ if (!isobject$1(productMapping) || !productMapping.map || !productMapping.value) {
411
+ return;
412
+ }
413
+
414
+ var sourceField = productMapping.map;
415
+ var facebookFieldName = productMapping.value;
416
+ var value = null;
417
+
418
+ // Check for Product level field first
419
+ if (product.hasOwnProperty(sourceField)) {
420
+ value = product[sourceField];
421
+ }
422
+ // then check for Product.Attributes level field
423
+ else if (product.Attributes && product.Attributes[sourceField]) {
424
+ value = product.Attributes[sourceField];
425
+ }
426
+
427
+ if (value !== null && value !== undefined) {
428
+ contentItem[facebookFieldName] = value;
429
+ }
430
+ });
431
+ return contentItem;
432
+ });
368
433
  }
369
434
 
370
- if (!isobject$1(config)) {
371
- console.log('\'config\' must be an object. You passed in a ' + typeof config);
372
- return;
435
+ // https://developers.facebook.com/docs/marketing-api/conversions-api/deduplicate-pixel-and-server-events#event-deduplication-options
436
+ function createEventId(event) {
437
+ return {
438
+ eventID: event.SourceMessageId || null
439
+ }
373
440
  }
374
441
 
375
- if (isobject$1(config.kits)) {
376
- config.kits[name] = {
377
- constructor: constructor
378
- };
379
- } else {
380
- config.kits = {};
381
- config.kits[name] = {
382
- constructor: constructor
383
- };
442
+ /**
443
+ * Builds array of product names from product list
444
+ * @param {Array} productList - Array of products
445
+ * @returns {Array} Array of product names
446
+ */
447
+ function buildProductNames(productList) {
448
+ if (!productList || productList.length === 0) {
449
+ return [];
450
+ }
451
+
452
+ return productList
453
+ .filter(function(product) {
454
+ return product && product.Name;
455
+ })
456
+ .map(function(product) {
457
+ return product.Name;
458
+ });
384
459
  }
385
- console.log('Successfully registered ' + name + ' to your mParticle configuration');
460
+
461
+ this.init = initForwarder;
462
+ this.process = processEvent;
463
+ };
464
+
465
+ function getId() {
466
+ return moduleId;
467
+ }
468
+
469
+ function register(config) {
470
+ if (!config) {
471
+ console.log('You must pass a config object to register the kit ' + name);
472
+ return;
386
473
  }
387
474
 
388
- if (typeof window !== 'undefined') {
389
- if (window && window.mParticle && window.mParticle.addForwarder) {
390
- window.mParticle.addForwarder({
391
- name: name,
392
- constructor: constructor,
393
- getId: getId
394
- });
395
- }
475
+ if (!isobject$1(config)) {
476
+ console.log('\'config\' must be an object. You passed in a ' + typeof config);
477
+ return;
478
+ }
479
+
480
+ if (isobject$1(config.kits)) {
481
+ config.kits[name] = {
482
+ constructor: constructor
483
+ };
484
+ } else {
485
+ config.kits = {};
486
+ config.kits[name] = {
487
+ constructor: constructor
488
+ };
489
+ }
490
+ console.log('Successfully registered ' + name + ' to your mParticle configuration');
491
+ }
492
+
493
+ if (typeof window !== 'undefined') {
494
+ if (window && window.mParticle && window.mParticle.addForwarder) {
495
+ window.mParticle.addForwarder({
496
+ name: name,
497
+ constructor: constructor,
498
+ getId: getId
499
+ });
396
500
  }
501
+ }
397
502
 
398
- var FacebookEventForwarder = {
399
- register: register
400
- };
503
+ var FacebookEventForwarder = {
504
+ register: register
505
+ };
401
506
  var FacebookEventForwarder_1 = FacebookEventForwarder.register;
402
507
 
403
508
  exports.default = FacebookEventForwarder;