Skip to content

Commit d8cd5c8

Browse files
authored
Merge pull request #39 from classmethod/feature/facebook-pixel
Add Facebook Pixel tracking support
2 parents 3ca6bb8 + 27612ce commit d8cd5c8

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/App.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export default function App() {
161161
>({});
162162
const [analytics, setAnalytics] = useState<AnalyticsOptions>({
163163
googleTagId: "",
164+
facebookPixelId: "",
164165
});
165166
const [customHtml, setCustomHtml] = useState<CustomHtmlOptions>({
166167
headerHtml: "",
@@ -928,6 +929,19 @@ export default function App() {
928929
variant="outlined"
929930
size="small"
930931
/>
932+
<TextField
933+
fullWidth
934+
label="Facebook Pixel ID"
935+
margin="dense"
936+
placeholder="123456789012345"
937+
helperText="Your Facebook Pixel ID for conversion tracking"
938+
onChange={(e) =>
939+
handleAnalyticsChange("facebookPixelId", e.target.value)
940+
}
941+
value={analytics.facebookPixelId}
942+
variant="outlined"
943+
size="small"
944+
/>
931945
</Box>
932946

933947
<Box sx={{ mt: 3, pt: 2, borderTop: 1, borderColor: "grey.300" }}>

src/code.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface SeoOptions {
3636

3737
export interface AnalyticsOptions {
3838
googleTagId?: string;
39+
facebookPixelId?: string;
3940
}
4041

4142
export interface CustomHtmlOptions {
@@ -160,9 +161,10 @@ ${slugs
160161
161162
/*
162163
* Step 3.5: analytics configuration (optional)
163-
* Add your Google Analytics 4 Measurement ID for built-in tracking
164+
* Add your Google Analytics 4 Measurement ID and/or Facebook Pixel ID for built-in tracking
164165
*/
165166
const GOOGLE_TAG_ID = '${analytics?.googleTagId || ""}';
167+
const FACEBOOK_PIXEL_ID = '${analytics?.facebookPixelId || ""}';
166168
167169
/*
168170
* Step 3.6: custom HTML header injection (optional)
@@ -565,6 +567,25 @@ ${
565567
</script>\`, { html: true });
566568
}
567569
570+
// Add Facebook Pixel if configured (Issue #31)
571+
if (FACEBOOK_PIXEL_ID !== '') {
572+
element.append(\`<script>
573+
!function(f,b,e,v,n,t,s)
574+
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
575+
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
576+
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
577+
n.queue=[];t=b.createElement(e);t.async=!0;
578+
t.src=v;s=b.getElementsByTagName(e)[0];
579+
s.parentNode.insertBefore(t,s)}(window, document,'script',
580+
'https://connect.facebook.net/en_US/fbevents.js');
581+
fbq('init', '\${FACEBOOK_PIXEL_ID}');
582+
fbq('track', 'PageView');
583+
</script>
584+
<noscript><img height="1" width="1" style="display:none"
585+
src="https://www.facebook.com/tr?id=\${FACEBOOK_PIXEL_ID}&ev=PageView&noscript=1"
586+
/></noscript>\`, { html: true });
587+
}
588+
568589
// Add Twitter/X meta tags for social cards (Issue #19)
569590
if (TWITTER_HANDLE !== '') {
570591
element.append(\`<meta name="twitter:site" content="\${TWITTER_HANDLE}">\`, { html: true });

0 commit comments

Comments
 (0)