|
| 1 | +--- |
| 2 | +title: "Facebook Pixel Setup" |
| 3 | +description: "Integrate Facebook Pixel with automatic event mapping and purchase deduplication." |
| 4 | +--- |
| 5 | + |
| 6 | + |
| 7 | +## Setup |
| 8 | + |
| 9 | +1. **Add Facebook Pixel Base Code** |
| 10 | + |
| 11 | + ```html |
| 12 | + <!-- Facebook Pixel Code --> |
| 13 | + <script> |
| 14 | + !function(f,b,e,v,n,t,s) |
| 15 | + {if(f.fbq)return;n=f.fbq=function(){n.callMethod? |
| 16 | + n.callMethod.apply(n,arguments):n.queue.push(arguments)}; |
| 17 | + if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; |
| 18 | + n.queue=[];t=b.createElement(e);t.async=!0; |
| 19 | + t.src=v;s=b.getElementsByTagName(e)[0]; |
| 20 | + s.parentNode.insertBefore(t,s)}(window, document,'script', |
| 21 | + 'https://connect.facebook.net/en_US/fbevents.js'); |
| 22 | + fbq('init', 'YOUR_PIXEL_ID'); |
| 23 | + </script> |
| 24 | + ``` |
| 25 | + |
| 26 | +2. **Configure SDK** |
| 27 | + |
| 28 | + ```javascript |
| 29 | + window.nextConfig = { |
| 30 | + storeName: 'my-store', // IMPORTANT for deduplication! |
| 31 | + analytics: { |
| 32 | + providers: { |
| 33 | + facebook: { |
| 34 | + enabled: true, |
| 35 | + settings: { |
| 36 | + pixelId: 'YOUR_PIXEL_ID' |
| 37 | + }, |
| 38 | + blockedEvents: [] // Optional |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + }; |
| 43 | + ``` |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +:::tip |
| 48 | +Make sure to replace `YOUR_PIXEL_ID` with your actual Facebook Pixel ID from your Meta Business Manager account. |
| 49 | +::: |
| 50 | + |
| 51 | +## Event Mapping |
| 52 | + |
| 53 | +SDK events are automatically mapped to Facebook standard events: |
| 54 | + |
| 55 | +| SDK Event | Facebook Event | Type | |
| 56 | +|-----------|----------------|------| |
| 57 | +| `dl_view_item` | `ViewContent` | Standard | |
| 58 | +| `dl_add_to_cart` | `AddToCart` | Standard | |
| 59 | +| `dl_begin_checkout` | `InitiateCheckout` | Standard | |
| 60 | +| `dl_add_shipping_info` | `AddShippingInfo` | Custom | |
| 61 | +| `dl_add_payment_info` | `AddPaymentInfo` | Standard | |
| 62 | +| `dl_purchase` | `Purchase` | Standard | |
| 63 | +| `dl_sign_up` | `CompleteRegistration` | Standard | |
| 64 | + |
| 65 | +This mapping tracks store events in Facebook Analytics without additional configuration. |
| 66 | + |
| 67 | +## Purchase Deduplication |
| 68 | + |
| 69 | +The SDK uses `eventID` to prevent duplicate purchase tracking: |
| 70 | + |
| 71 | +```javascript |
| 72 | +// SDK automatically generates eventID |
| 73 | +fbq('track', 'Purchase', { |
| 74 | + value: 159.99, |
| 75 | + currency: 'USD' |
| 76 | +}, { |
| 77 | + eventID: 'my-store-12345' // Format: {storeName}-{orderNumber} |
| 78 | +}); |
| 79 | +``` |
| 80 | + |
| 81 | +**Why storeName is required:** |
| 82 | +- Creates unique eventIDs across different stores |
| 83 | +- Prevents Facebook from counting the same purchase twice |
| 84 | +- Required for server-side API deduplication |
| 85 | +- Without it, deduplication may fail |
| 86 | + |
| 87 | +:::caution |
| 88 | +The `storeName` configuration is required for Facebook Pixel purchase deduplication. Without it, Facebook may count the same purchase multiple times across your sales channels (web, mobile, server-side events). Set `storeName` to a unique identifier for your store before deploying to production. |
| 89 | +::: |
| 90 | + |
| 91 | +## Event Format Example |
| 92 | + |
| 93 | +Facebook Pixel events are formatted with these properties: |
| 94 | + |
| 95 | +```javascript |
| 96 | +fbq('track', 'AddToCart', { |
| 97 | + content_type: 'product', |
| 98 | + content_ids: ['SKU-123'], |
| 99 | + content_name: 'Product Name', |
| 100 | + value: 99.99, |
| 101 | + currency: 'USD', |
| 102 | + contents: [{ |
| 103 | + id: 'SKU-123', |
| 104 | + quantity: 1, |
| 105 | + item_price: 99.99 |
| 106 | + }] |
| 107 | +}); |
| 108 | +``` |
| 109 | + |
| 110 | +### Event Property Details |
| 111 | + |
| 112 | +- **content_type**: Type of content (e.g., 'product', 'product_group') |
| 113 | +- **content_ids**: Array of product SKUs or IDs |
| 114 | +- **content_name**: Name of the product or content |
| 115 | +- **value**: Total value of the event |
| 116 | +- **currency**: Currency code (e.g., 'USD', 'EUR') |
| 117 | +- **contents**: Array of items with quantity and pricing details |
| 118 | + |
| 119 | +## Blocked Events |
| 120 | + |
| 121 | +Prevent specific events from being sent to Facebook Pixel using the `blockedEvents` configuration: |
| 122 | + |
| 123 | +```javascript |
| 124 | +facebook: { |
| 125 | + enabled: true, |
| 126 | + settings: { pixelId: 'xxx' }, |
| 127 | + blockedEvents: ['dl_test_event', 'internal_event'] |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +This is useful for: |
| 132 | +- Preventing test events from affecting analytics |
| 133 | +- Blocking internal tracking events not relevant to Facebook |
| 134 | +- Reducing event volume and optimizing tracking |
| 135 | + |
| 136 | +## Troubleshooting |
| 137 | + |
| 138 | +### Events Not Appearing in Facebook Analytics |
| 139 | + |
| 140 | +1. **Verify Pixel ID**: Ensure your `pixelId` is correct in the configuration |
| 141 | +2. **Check storeName**: Confirm that `storeName` is set in your config - missing this can cause events to be blocked or deduplicated unexpectedly |
| 142 | +3. **Test with Facebook Pixel Helper**: Use the [Facebook Pixel Helper Chrome extension](https://chrome.google.com/webstore/detail/facebook-pixel-helper/fdgodlnavgvnoonakpplpknkeae6764d) to verify events are firing |
| 143 | +4. **Review Browser Console**: Check for JavaScript errors that might prevent events from sending |
| 144 | + |
| 145 | +### Purchase Deduplication Not Working |
| 146 | + |
| 147 | +- **Ensure storeName is configured**: This is the primary reason deduplication fails |
| 148 | +- **Verify eventID format**: Should be `{storeName}-{orderNumber}` (e.g., `my-store-12345`) |
| 149 | +- **Check server-side events**: If you're also sending events server-side, ensure consistent storeName and eventID |
| 150 | +- **Allow time for deduplication**: Facebook's deduplication can take up to 24 hours to process |
| 151 | + |
| 152 | +### Low Purchase Conversion Events |
| 153 | + |
| 154 | +- **Verify currency code**: Ensure the currency matches your Facebook Pixel settings |
| 155 | +- **Check content details**: Make sure `contents` array includes all required item information |
| 156 | +- **Review blocked events**: Ensure `dl_purchase` is not in your `blockedEvents` list |
| 157 | +- **Validate event values**: Confirm that transaction values are being passed correctly |
| 158 | + |
| 159 | +### Multiple Events Firing for Same Action |
| 160 | + |
| 161 | +1. Check that you're not initializing the Facebook Pixel multiple times |
| 162 | +2. Verify that duplicate SDK instances aren't running |
| 163 | +3. Review your `blockedEvents` configuration to filter unwanted duplicates |
| 164 | + |
| 165 | +### Contact Support |
| 166 | + |
| 167 | +If you continue experiencing issues: |
| 168 | +- Check your Meta Business Manager logs for event validation errors |
| 169 | +- Consult the [Facebook Pixel documentation](https://developers.facebook.com/docs/facebook-pixel) |
| 170 | +- Reach out to your analytics support team with event payloads for investigation |
0 commit comments