Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/add-meta-pixel-analytics-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@bigcommerce/catalyst-core": minor
---

Add Meta Pixel analytics provider support

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.

**Features:**
- Meta Pixel provider implementation with full event tracking support
- Consent management integration for GDPR/CCPA compliance
- Support for multiple analytics providers simultaneously (GA4 + Meta Pixel)
- Standard e-commerce events: ViewContent, AddToCart, RemoveFromCart, ViewCart, ViewCategory

**Configuration:**
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.

**Note:** This implementation requires the BigCommerce GraphQL schema to include `metaPixel` in `webAnalytics`. Platform support may be required for full functionality.
3 changes: 3 additions & 0 deletions core/components/analytics/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export const WebAnalyticsFragment = graphql(`
ga4 {
tagId
}
metaPixel {
pixelId
}
}
}
`);
26 changes: 22 additions & 4 deletions core/components/analytics/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { PropsWithChildren, useEffect, useRef } from 'react';

import { FragmentOf } from '~/client/graphql';
import { Analytics } from '~/lib/analytics';
import { AnalyticsProvider as AnalyticsProviderType } from '~/lib/analytics/types';
import { GoogleAnalyticsProvider } from '~/lib/analytics/providers/google-analytics';
import { MetaPixelProvider } from '~/lib/analytics/providers/meta-pixel';
import { AnalyticsProvider as AnalyticsProviderLib } from '~/lib/analytics/react';
import { getConsentCookie } from '~/lib/consent-manager/cookies/client';

Expand Down Expand Up @@ -33,21 +35,37 @@ const getConsent = () => {
};

const getAnalytics = ({ channelId, isCookieConsentEnabled, settings }: Props): Analytics | null => {
const providers: AnalyticsProviderType[] = [];

// Add Google Analytics if configured
if (settings?.webAnalytics?.ga4?.tagId && channelId) {
const googleAnalytics = new GoogleAnalyticsProvider({
gaId: settings.webAnalytics.ga4.tagId,
consentModeEnabled: isCookieConsentEnabled,
developerId: 'dMjk3Nj',
getConsent,
});
providers.push(googleAnalytics);
}

return new Analytics({
channelId,
providers: [googleAnalytics],
// Add Meta Pixel if configured
if (settings?.webAnalytics?.metaPixel?.pixelId && channelId) {
const metaPixel = new MetaPixelProvider({
pixelId: settings.webAnalytics.metaPixel.pixelId,
consentModeEnabled: isCookieConsentEnabled,
getConsent,
});
providers.push(metaPixel);
}

return null;
if (providers.length === 0) {
return null;
}

return new Analytics({
channelId,
providers,
});
};

export function AnalyticsProvider({
Expand Down
Loading
Loading