Skip to content

Commit 0d7b568

Browse files
committed
Add Meta Pixel analytics provider support
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. - Add MetaPixelProvider class implementing AnalyticsProvider interface - Update WebAnalyticsFragment to include metaPixel configuration - Update AnalyticsProvider component to support multiple providers - Add consent management integration for GDPR/CCPA compliance
1 parent c3fa141 commit 0d7b568

4 files changed

Lines changed: 389 additions & 4 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"@bigcommerce/catalyst-core": minor
3+
---
4+
5+
Add Meta Pixel analytics provider support
6+
7+
This change adds a new Meta Pixel (Facebook Pixel) analytics provider to the Catalyst analytics framework. The implementation follows the same architecture pattern as the existing Google Analytics provider, allowing merchants to track e-commerce events using Meta Pixel for advertising and analytics purposes.
8+
9+
**Features:**
10+
- Meta Pixel provider implementation with full event tracking support
11+
- Consent management integration for GDPR/CCPA compliance
12+
- Support for multiple analytics providers simultaneously (GA4 + Meta Pixel)
13+
- Standard e-commerce events: ViewContent, AddToCart, RemoveFromCart, ViewCart, ViewCategory
14+
15+
**Configuration:**
16+
Merchants can configure Meta Pixel by adding `metaPixel { pixelId }` to their BigCommerce store settings. The GraphQL fragment has been updated to support fetching Meta Pixel configuration.
17+
18+
**Note:** This implementation requires the BigCommerce GraphQL schema to include `metaPixel` in `webAnalytics`. Platform support may be required for full functionality.

core/components/analytics/fragment.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export const WebAnalyticsFragment = graphql(`
66
ga4 {
77
tagId
88
}
9+
metaPixel {
10+
pixelId
11+
}
912
}
1013
}
1114
`);

core/components/analytics/provider.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { PropsWithChildren, useEffect, useRef } from 'react';
55

66
import { FragmentOf } from '~/client/graphql';
77
import { Analytics } from '~/lib/analytics';
8+
import { AnalyticsProvider as AnalyticsProviderType } from '~/lib/analytics/types';
89
import { GoogleAnalyticsProvider } from '~/lib/analytics/providers/google-analytics';
10+
import { MetaPixelProvider } from '~/lib/analytics/providers/meta-pixel';
911
import { AnalyticsProvider as AnalyticsProviderLib } from '~/lib/analytics/react';
1012
import { getConsentCookie } from '~/lib/consent-manager/cookies/client';
1113

@@ -33,21 +35,37 @@ const getConsent = () => {
3335
};
3436

3537
const getAnalytics = ({ channelId, isCookieConsentEnabled, settings }: Props): Analytics | null => {
38+
const providers: AnalyticsProviderType[] = [];
39+
40+
// Add Google Analytics if configured
3641
if (settings?.webAnalytics?.ga4?.tagId && channelId) {
3742
const googleAnalytics = new GoogleAnalyticsProvider({
3843
gaId: settings.webAnalytics.ga4.tagId,
3944
consentModeEnabled: isCookieConsentEnabled,
4045
developerId: 'dMjk3Nj',
4146
getConsent,
4247
});
48+
providers.push(googleAnalytics);
49+
}
4350

44-
return new Analytics({
45-
channelId,
46-
providers: [googleAnalytics],
51+
// Add Meta Pixel if configured
52+
if (settings?.webAnalytics?.metaPixel?.pixelId && channelId) {
53+
const metaPixel = new MetaPixelProvider({
54+
pixelId: settings.webAnalytics.metaPixel.pixelId,
55+
consentModeEnabled: isCookieConsentEnabled,
56+
getConsent,
4757
});
58+
providers.push(metaPixel);
4859
}
4960

50-
return null;
61+
if (providers.length === 0) {
62+
return null;
63+
}
64+
65+
return new Analytics({
66+
channelId,
67+
providers,
68+
});
5169
};
5270

5371
export function AnalyticsProvider({

0 commit comments

Comments
 (0)