@@ -35,7 +35,7 @@ var mpFacebookKit = (function (exports) {
3535 PageEvent : 4 ,
3636 CrashReport : 5 ,
3737 OptOut : 6 ,
38- Commerce : 16
38+ Commerce : 16 ,
3939 } ,
4040 IdentityType = {
4141 Other : 0 ,
@@ -61,6 +61,14 @@ var mpFacebookKit = (function (exports) {
6161 PhoneNumber3 : 21 ,
6262 } ,
6363 SupportedCommerceTypes = [ ] ,
64+ // Standard FB Event Names from https://developers.facebook.com/docs/facebook-pixel/reference#standard-events
65+ ADD_TO_CART_EVENT_NAME = 'AddToCart' ;
66+ ADD_TO_WISHLIST_EVENT_NAME = 'AddToWishlist' ;
67+ CHECKOUT_EVENT_NAME = 'InitiateCheckout' ;
68+ PAGE_VIEW_EVENT_NAME = 'PageView' ;
69+ PURCHASE_EVENT_NAME = 'Purchase' ;
70+ REMOVE_FROM_CART_EVENT_NAME = 'RemoveFromCart' ;
71+ VIEW_CONTENT_EVENT_NAME = 'ViewContent' ;
6472 constructor = function ( ) {
6573 var self = this ,
6674 isInitialized = false ,
@@ -102,9 +110,15 @@ var mpFacebookKit = (function (exports) {
102110 visitorData [ 'external_id' ] = selectedIdentity [ 0 ] . Identity ;
103111 }
104112 }
113+ }
105114
106- fbq ( 'init' , settings . pixelId , visitorData ) ;
115+ if ( settings . disablePushState === 'True' ) {
116+ // Facebook will automatically track page views whenever a new state is pushed to the HTML 5 History State API
117+ // this option can be disabled to prevent duplicate page views
118+ // https://developers.facebook.com/docs/facebook-pixel/implementation/tag_spa/#tagging-single-page-applications
119+ fbq . disablePushState = true ;
107120 }
121+ fbq ( 'init' , settings . pixelId , visitorData ) ;
108122
109123 isInitialized = true ;
110124
@@ -199,20 +213,20 @@ var mpFacebookKit = (function (exports) {
199213 params [ 'value' ] = totalValue ;
200214
201215 if ( event . ProductAction . ProductActionType == mParticle . ProductActionType . AddToWishlist ) {
202- eventName = 'AddToWishlist' ;
216+ eventName = ADD_TO_WISHLIST_EVENT_NAME ;
203217 }
204218 else if ( event . ProductAction . ProductActionType == mParticle . ProductActionType . AddToCart ) {
205- eventName = 'AddToCart' ;
219+ eventName = ADD_TO_CART_EVENT_NAME ;
206220 }
207221 else {
208- eventName = 'ViewContent' ;
222+ eventName = VIEW_CONTENT_EVENT_NAME ;
209223 }
210224
211225 }
212226 else if ( event . ProductAction . ProductActionType == mParticle . ProductActionType . Checkout ||
213227 event . ProductAction . ProductActionType == mParticle . ProductActionType . Purchase ) {
214228
215- eventName = event . ProductAction . ProductActionType == mParticle . ProductActionType . Checkout ? 'InitiateCheckout' : 'Purchase' ;
229+ eventName = event . ProductAction . ProductActionType == mParticle . ProductActionType . Checkout ? CHECKOUT_EVENT_NAME : PURCHASE_EVENT_NAME ;
216230
217231 if ( event . ProductAction . TotalAmount ) {
218232 params [ 'value' ] = event . ProductAction . TotalAmount ;
@@ -227,7 +241,7 @@ var mpFacebookKit = (function (exports) {
227241 params [ 'num_items' ] = num_items ;
228242 }
229243 else if ( event . ProductAction . ProductActionType == mParticle . ProductActionType . RemoveFromCart ) {
230- eventName = 'RemoveFromCart' ;
244+ eventName = REMOVE_FROM_CART_EVENT_NAME ;
231245
232246 // remove from cart can be performed in 1 of 2 ways:
233247 // 1. mParticle.eCommerce.logProductEvent(), which contains event.ProductAction.TotalAmount
@@ -264,7 +278,7 @@ var mpFacebookKit = (function (exports) {
264278 }
265279
266280 function logPageView ( event ) {
267- logPageEvent ( event , 'Viewed ' + event . EventName ) ;
281+ logPageEvent ( event , PAGE_VIEW_EVENT_NAME ) ;
268282 }
269283
270284 function logPageEvent ( event , eventName ) {
@@ -275,6 +289,7 @@ var mpFacebookKit = (function (exports) {
275289 if ( event . EventName ) {
276290 params [ 'content_name' ] = event . EventName ;
277291 }
292+
278293 fbq ( 'trackCustom' , eventName || 'customEvent' , params , eventID ) ;
279294 }
280295
0 commit comments