|
23 | 23 | PageEvent: 4, |
24 | 24 | CrashReport: 5, |
25 | 25 | OptOut: 6, |
26 | | - Commerce: 16 |
| 26 | + Commerce: 16, |
27 | 27 | }, |
28 | 28 | IdentityType = { |
29 | 29 | Other: 0, |
|
49 | 49 | PhoneNumber3: 21, |
50 | 50 | }, |
51 | 51 | SupportedCommerceTypes = [], |
| 52 | + // Standard FB Event Names from https://developers.facebook.com/docs/facebook-pixel/reference#standard-events |
| 53 | + ADD_TO_CART_EVENT_NAME = 'AddToCart'; |
| 54 | + ADD_TO_WISHLIST_EVENT_NAME = 'AddToWishlist'; |
| 55 | + CHECKOUT_EVENT_NAME = 'InitiateCheckout'; |
| 56 | + PAGE_VIEW_EVENT_NAME = 'PageView'; |
| 57 | + PURCHASE_EVENT_NAME = 'Purchase'; |
| 58 | + REMOVE_FROM_CART_EVENT_NAME = 'RemoveFromCart'; |
| 59 | + VIEW_CONTENT_EVENT_NAME = 'ViewContent'; |
52 | 60 | constructor = function () { |
53 | 61 | var self = this, |
54 | 62 | isInitialized = false, |
|
90 | 98 | visitorData['external_id'] = selectedIdentity[0].Identity; |
91 | 99 | } |
92 | 100 | } |
| 101 | + } |
93 | 102 |
|
94 | | - fbq('init', settings.pixelId, visitorData); |
| 103 | + if (settings.disablePushState === 'True') { |
| 104 | + // Facebook will automatically track page views whenever a new state is pushed to the HTML 5 History State API |
| 105 | + // this option can be disabled to prevent duplicate page views |
| 106 | + // https://developers.facebook.com/docs/facebook-pixel/implementation/tag_spa/#tagging-single-page-applications |
| 107 | + fbq.disablePushState = true; |
95 | 108 | } |
| 109 | + fbq('init', settings.pixelId, visitorData); |
96 | 110 |
|
97 | 111 | isInitialized = true; |
98 | 112 |
|
|
187 | 201 | params['value'] = totalValue; |
188 | 202 |
|
189 | 203 | if (event.ProductAction.ProductActionType == mParticle.ProductActionType.AddToWishlist){ |
190 | | - eventName = 'AddToWishlist'; |
| 204 | + eventName = ADD_TO_WISHLIST_EVENT_NAME; |
191 | 205 | } |
192 | 206 | else if (event.ProductAction.ProductActionType == mParticle.ProductActionType.AddToCart){ |
193 | | - eventName = 'AddToCart'; |
| 207 | + eventName = ADD_TO_CART_EVENT_NAME; |
194 | 208 | } |
195 | 209 | else{ |
196 | | - eventName = 'ViewContent'; |
| 210 | + eventName = VIEW_CONTENT_EVENT_NAME; |
197 | 211 | } |
198 | 212 |
|
199 | 213 | } |
200 | 214 | else if (event.ProductAction.ProductActionType == mParticle.ProductActionType.Checkout || |
201 | 215 | event.ProductAction.ProductActionType == mParticle.ProductActionType.Purchase) { |
202 | 216 |
|
203 | | - eventName = event.ProductAction.ProductActionType == mParticle.ProductActionType.Checkout ? 'InitiateCheckout' : 'Purchase'; |
| 217 | + eventName = event.ProductAction.ProductActionType == mParticle.ProductActionType.Checkout ? CHECKOUT_EVENT_NAME : PURCHASE_EVENT_NAME; |
204 | 218 |
|
205 | 219 | if (event.ProductAction.TotalAmount) { |
206 | 220 | params['value'] = event.ProductAction.TotalAmount; |
|
215 | 229 | params['num_items'] = num_items; |
216 | 230 | } |
217 | 231 | else if (event.ProductAction.ProductActionType == mParticle.ProductActionType.RemoveFromCart) { |
218 | | - eventName = 'RemoveFromCart'; |
| 232 | + eventName = REMOVE_FROM_CART_EVENT_NAME; |
219 | 233 |
|
220 | 234 | // remove from cart can be performed in 1 of 2 ways: |
221 | 235 | // 1. mParticle.eCommerce.logProductEvent(), which contains event.ProductAction.TotalAmount |
|
252 | 266 | } |
253 | 267 |
|
254 | 268 | function logPageView(event) { |
255 | | - logPageEvent(event, 'Viewed ' + event.EventName); |
| 269 | + logPageEvent(event, PAGE_VIEW_EVENT_NAME); |
256 | 270 | } |
257 | 271 |
|
258 | 272 | function logPageEvent(event, eventName) { |
|
263 | 277 | if (event.EventName) { |
264 | 278 | params['content_name'] = event.EventName; |
265 | 279 | } |
| 280 | + |
266 | 281 | fbq('trackCustom', eventName || 'customEvent', params, eventID); |
267 | 282 | } |
268 | 283 |
|
|
0 commit comments