@@ -165,11 +165,12 @@ var name = 'Facebook',
165165 event . ProductAction . ProductList &&
166166 event . ProductAction . ProductActionType &&
167167 SupportedCommerceTypes . indexOf ( event . ProductAction . ProductActionType ) > - 1 ) {
168-
169168 var eventName ,
170169 totalValue ,
171170 params = cloneEventAttributes ( event ) ,
172- eventID = createEventId ( event ) ;
171+ eventID = createEventId ( event ) ,
172+ sendProductNamesAsContents = settings . sendProductNamesasContents || false ;
173+
173174 params [ 'currency' ] = event . CurrencyCode || 'USD' ;
174175
175176 if ( event . EventName ) {
@@ -187,6 +188,25 @@ var name = 'Facebook',
187188 params [ 'content_ids' ] = productSkus ;
188189 }
189190
191+ // Override content_name with product names array if setting enabled
192+ if ( sendProductNamesAsContents ) {
193+ var productNames = buildProductNames ( event . ProductAction . ProductList ) ;
194+ if ( productNames && productNames . length > 0 ) {
195+ params [ 'content_name' ] = productNames ;
196+ }
197+ }
198+
199+ // Set order_id if TransactionId exists
200+ if ( event . ProductAction . TransactionId ) {
201+ params [ 'order_id' ] = event . ProductAction . TransactionId ;
202+ }
203+
204+ // Build contents array
205+ var contents = buildProductContents ( event . ProductAction . ProductList ) ;
206+ if ( contents && contents . length > 0 ) {
207+ params [ 'contents' ] = contents ;
208+ }
209+
190210 if ( event . ProductAction . ProductActionType == mParticle . ProductActionType . AddToWishlist ||
191211 event . ProductAction . ProductActionType == mParticle . ProductActionType . Checkout ) {
192212 var eventCategory = getEventCategoryString ( event ) ;
@@ -238,18 +258,6 @@ var name = 'Facebook',
238258 return sum ;
239259 } , 0 ) ;
240260 params [ 'num_items' ] = num_items ;
241-
242- if ( event . ProductAction . TransactionId ) {
243- params [ 'order_id' ] = event . ProductAction . TransactionId ;
244- }
245-
246- // Build contents array for Purchase events
247- if ( event . ProductAction . ProductActionType == mParticle . ProductActionType . Purchase ) {
248- var contents = buildProductContents ( event . ProductAction . ProductList ) ;
249- if ( contents && contents . length > 0 ) {
250- params [ 'contents' ] = contents ;
251- }
252- }
253261 }
254262 else if ( event . ProductAction . ProductActionType == mParticle . ProductActionType . RemoveFromCart ) {
255263 eventName = REMOVE_FROM_CART_EVENT_NAME ;
@@ -407,6 +415,25 @@ var name = 'Facebook',
407415 }
408416 }
409417
418+ /**
419+ * Builds array of product names from product list
420+ * @param {Array } productList - Array of products
421+ * @returns {Array } Array of product names
422+ */
423+ function buildProductNames ( productList ) {
424+ if ( ! productList || productList . length === 0 ) {
425+ return [ ] ;
426+ }
427+
428+ return productList
429+ . filter ( function ( product ) {
430+ return product && product . Name ;
431+ } )
432+ . map ( function ( product ) {
433+ return product . Name ;
434+ } ) ;
435+ }
436+
410437 this . init = initForwarder ;
411438 this . process = processEvent ;
412439 } ;
0 commit comments