Add Meta Pixel analytics provider support#2727
Conversation
🦋 Changeset detectedLatest commit: f6092e4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@BC-AdamWard is attempting to deploy a commit to the BigCommerce Platform Team on Vercel. A member of the Team first needs to authorize it. |
chanceaclark
left a comment
There was a problem hiding this comment.
Love how simple this add was! Wonder who set this up to be easy... 😏
Have a few comments specific to the provider + some type stuff otherwise looking good.
| getConsent?: () => Analytics.Consent.ConsentValues | null; | ||
| debugMode?: boolean; |
There was a problem hiding this comment.
These two properties are based on how the analytics providers manages consent and if it has a debug option.
For the consent piece, do you know if MP handles managing consent on it's own, like GA does? Or does it always assume you have consent when placed on the page?
There was a problem hiding this comment.
Meta Pixel does support its own consent management via fbq('consent', 'grant'|'revoke') (Meta Consent Mode), so I've kept the consent path and reworked it to mirror the GA provider — see the updated initializeConsent. debugMode is removed (see the thread below).
| s.parentNode.insertBefore(t,s)}(window, document,'script', | ||
| 'https://connect.facebook.net/en_US/fbevents.js'); | ||
| fbq('init', '${this.config.pixelId}'); | ||
| ${this.config.debugMode ? "fbq('track', 'PageView');" : ''} |
There was a problem hiding this comment.
Is this manually added or do they have an example with debugMode?
There was a problem hiding this comment.
Removed debugMode entirely — unlike GA4's real debug_mode config param, Meta Pixel has no official equivalent (debugging is via the Pixel Helper extension / Events Manager Test Events), so this was hand-rolled. PageView now fires unconditionally after init as the standard base event.
| if (typeof window !== 'undefined' && (window as any).fbq) { | ||
| (window as any).fbq('consent', 'revoke'); |
There was a problem hiding this comment.
any should be avoided here and anywhere else in the file. Would also love to see if they have a type library we can use so we don't have to type check this, see @types/gtag.js.
| if (typeof window !== 'undefined' && (window as any).fbq) { | |
| (window as any).fbq('consent', 'revoke'); | |
| if (typeof window !== 'undefined' && 'fbq' in window) { | |
| window.fbq('consent', 'revoke'); |
There was a problem hiding this comment.
Done — added @types/facebook-pixel, which declares a typed global fbq (same mechanism as @types/gtag.js for the GA provider), so all the (window as any).fbq casts are gone and the calls are fully typed.
| // Check consent before initializing | ||
| if (this.config.consentModeEnabled && this.config.getConsent) { | ||
| const consent = this.config.getConsent(); | ||
| if (consent && !consent.marketing) { | ||
| // Consent denied, don't initialize pixel | ||
| if (this.config.debugMode) { | ||
| console.log('[Meta Pixel] Consent denied, pixel not initialized'); | ||
| } | ||
| return; | ||
| } | ||
| } |
There was a problem hiding this comment.
We can probably move this logic into the initializeConsent function.
There was a problem hiding this comment.
Refactored — the init-time consent handling now lives in initializeConsent, and the provider no longer skips initialization when consent is denied. It always initializes and applies revoke/grant, matching the GA provider and Meta's recommended Consent Mode flow.
Adds a Meta Pixel (Facebook Pixel) provider to the Catalyst analytics
framework, following the GoogleAnalyticsProvider architecture. Merchants who
configure a Meta Pixel (surfaced via webAnalytics.metaPixel.pixelId in the
GraphQL Storefront API) get standard e-commerce event tracking alongside GA4.
- MetaPixelProvider implementing AnalyticsProvider, typed with
@types/facebook-pixel (no 'any').
- Meta Consent Mode: fbq('consent', ...) applied before init so the pixel
stays dormant until marketing consent is granted.
- Standard events (ViewContent, AddToCart) use fbq('track', ...); events with
no Meta standard equivalent (ViewCart, RemoveFromCart, ViewCategory) use
fbq('trackCustom', ...). Each carries an eventID for browser <-> Conversions
API deduplication.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0d7b568 to
f6092e4
Compare
|
Thanks for the review, @chanceaclark — sorry for the long pause on this one! I've refreshed the PR against the latest
Also — the schema dependency this originally flagged is resolved: |
What/Why?
Add Meta Pixel (Facebook Pixel) analytics provider to Catalyst analytics framework. Implements standard e-commerce event tracking (ViewContent, AddToCart, RemoveFromCart, ViewCart, ViewCategory) with consent management support. Enables merchants to track events using Meta Pixel alongside or instead of Google Analytics.
Testing
Migration
Minor change