Meta Pixel (formerly Facebook Pixel) enables Facebook and Instagram ad tracking, audience building, and conversion optimization for Ghost websites. This guide covers installation methods and Ghost-specific configuration.
Prerequisites
Before installing Meta Pixel on Ghost:
- Meta Business Suite Account - Create at business.facebook.com
- Meta Pixel Created - Set up pixel in Events Manager
- Pixel ID - Obtain your pixel ID (format: 15-16 digit number)
- Ghost Admin Access - Owner or Administrator role required
- Domain Verified - Verify domain in Meta Business Suite (recommended)
Create Meta Pixel
If you haven't created a pixel yet:
- Navigate to Meta Events Manager
- Click Connect Data Sources → Web
- Select Meta Pixel
- Enter your Pixel Name (e.g., "Ghost Blog - Main Site")
- Optional: Enter your Ghost website URL
- Click Continue
- Copy your Pixel ID (you'll need this for installation)
Installation Methods
Method 1: Code Injection (Recommended for Most Users)
The easiest way to add Meta Pixel to Ghost without modifying theme files.
Step 1: Access Code Injection
- Log in to Ghost Admin (
yourdomain.com/ghost) - Navigate to Settings → Code Injection
- Locate the Site Header section
Step 2: Add Meta Pixel Base Code
Paste the following in Site Header:
<!-- Meta Pixel Code -->
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>
<noscript>
<img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=YOUR_PIXEL_ID&ev=PageView&noscript=1"/>
</noscript>
<!-- End Meta Pixel Code -->
Replace YOUR_PIXEL_ID with your actual Meta Pixel ID.
Step 3: Save and Verify
- Click Save in the top-right corner
- Open your Ghost site in a new browser
- Install Meta Pixel Helper Chrome extension
- Verify pixel fires on page load
Method 2: Custom Theme Integration
For maximum control and access to Ghost Handlebars data.
Step 1: Download Your Theme
For Ghost(Pro):
- Navigate to Settings → Design
- Scroll to Installed Themes
- Click Download next to your active theme
For Self-Hosted:
cd /var/www/ghost/content/themes/
cp -r your-theme-name your-theme-name-meta
Step 2: Create Meta Pixel Partial
Create partials/meta-pixel.hbs:
{{!-- partials/meta-pixel.hbs --}}
<!-- Meta Pixel Code -->
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
// Track PageView with Ghost context
fbq('track', 'PageView', {
{{#post}}
content_type: 'post',
content_name: '{{title}}',
content_category: '{{primary_tag.name}}',
content_ids: ['{{id}}'],
{{/post}}
{{#page}}
content_type: 'page',
content_name: '{{title}}',
{{/page}}
{{#is "home"}}
content_type: 'homepage',
{{/is}}
});
</script>
<noscript>
<img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=YOUR_PIXEL_ID&ev=PageView&noscript=1"/>
</noscript>
<!-- End Meta Pixel Code -->
Step 3: Include Partial in default.hbs
Edit default.hbs and add before \{\{ghost_head\}\}:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{meta_title}}</title>
{{!-- Meta Pixel --}}
{{> meta-pixel}}
{{ghost_head}}
</head>
Step 4: Upload and Activate Theme
For Ghost(Pro):
- Zip your modified theme directory
- Navigate to Settings → Design → Change theme
- Upload ZIP file
- Click Activate
For Self-Hosted:
ghost restart
Then activate via Settings → Design.
Method 3: Google Tag Manager
If you're using GTM, deploy Meta Pixel through Tag Manager.
Step 1: Create Meta Pixel Tag
In GTM:
<!-- Meta Pixel via GTM -->
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>
- Click Triggering → All Pages
- Name tag: "Meta Pixel - Base Code"
- Click Save
Step 2: Publish Container
- Click Submit
- Enter version name: "Add Meta Pixel"
- Click Publish
Enhanced Meta Pixel Configuration
Track Content Type
Differentiate between posts, pages, and homepage:
<script>
fbq('track', 'PageView', {
content_type: '{{#is "post"}}post{{/is}}{{#is "page"}}page{{/is}}{{#is "home"}}homepage{{/is}}{{#is "tag"}}tag_archive{{/is}}{{#is "author"}}author_archive{{/is}}'
});
</script>
Track Member Status
Segment visitors by member status:
<script>
fbq('track', 'PageView', {
{{#member}}
user_type: 'member',
member_status: '{{#if paid}}paid{{else}}free{{/if}}',
{{/member}}
{{^member}}
user_type: 'visitor',
{{/member}}
});
</script>
Track Post Metadata
Send article details to Meta:
{{#post}}
<script>
fbq('track', 'ViewContent', {
content_name: '{{title}}',
content_category: '{{primary_tag.name}}',
content_type: 'article',
content_ids: ['{{id}}'],
{{#if primary_author}}
author: '{{primary_author.name}}',
{{/if}}
published_date: '{{published_at}}',
{{#if featured}}
featured: true,
{{/if}}
visibility: '{{visibility}}'
});
</script>
{{/post}}
Advanced Event Tracking
Meta Pixel supports standard events for conversion tracking:
Member Signup Event
<script>
window.addEventListener('portal-signup', function() {
if (typeof fbq !== 'undefined') {
fbq('track', 'Lead', {
content_name: 'Member Signup',
content_category: 'Membership',
{{#member}}
status: '{{#if paid}}paid{{else}}free{{/if}}'
{{/member}}
});
}
});
</script>
Newsletter Subscription
<script>
window.addEventListener('portal-subscribe', function() {
if (typeof fbq !== 'undefined') {
fbq('track', 'Subscribe', {
content_name: 'Newsletter Subscription',
predicted_ltv: 0,
value: 0,
currency: 'USD'
});
}
});
</script>
Paid Subscription (Purchase)
<script>
{{#if @member.subscriptions}}
// Track subscription as purchase
if (typeof fbq !== 'undefined') {
fbq('track', 'Purchase', {
content_name: '{{@member.subscriptions.[0].tier.name}}',
content_type: 'subscription',
content_ids: ['{{@member.subscriptions.[0].tier.id}}'],
currency: '{{@member.subscriptions.[0].tier.currency}}',
value: {{@member.subscriptions.[0].tier.monthly_price}},
predicted_ltv: {{multiply @member.subscriptions.[0].tier.monthly_price 12}}
});
}
{{/if}}
</script>
Conversion API (Server-Side Tracking)
For enhanced privacy and iOS 14+ tracking, implement Meta Conversion API.
Step 1: Generate Access Token
- Navigate to Meta Events Manager
- Select your pixel
- Click Settings
- Scroll to Conversions API
- Click Generate Access Token
- Copy the token (keep it secure)
Step 2: Server-Side Implementation
Create a Node.js webhook handler:
// conversion-api-handler.js
const crypto = require('crypto');
const axios = require('axios');
async function sendToConversionAPI(event, userData) {
const accessToken = process.env.META_CAPI_ACCESS_TOKEN;
const pixelId = process.env.META_PIXEL_ID;
// Hash user data for privacy
const hashedEmail = userData.email
? crypto.createHash('sha256').update(userData.email).digest('hex')
: null;
const payload = {
data: [{
event_name: event.name,
event_time: Math.floor(Date.now() / 1000),
action_source: 'website',
event_source_url: event.url,
user_data: {
em: hashedEmail,
client_ip_address: event.ip,
client_user_agent: event.userAgent,
fbc: event.fbc, // Facebook click ID
fbp: event.fbp // Facebook browser ID
},
custom_data: event.customData
}]
};
try {
const response = await axios.post(
`https://graph.facebook.com/v18.0/${pixelId}/events`,
payload,
{
params: { access_token: accessToken }
}
);
console.log('CAPI Response:', response.data);
} catch (error) {
console.error('CAPI Error:', error.response?.data);
}
}
// Example: Track member signup
sendToConversionAPI(
{
name: 'Lead',
url: 'https://yoursite.com',
ip: '1.2.3.4',
userAgent: 'Mozilla/5.0...',
fbc: '_fbc_value',
fbp: '_fbp_value',
customData: {
content_name: 'Member Signup',
content_category: 'Membership'
}
},
{ email: 'user@example.com' }
);
Step 3: Integrate with Ghost Webhooks
Use Ghost webhooks to trigger server-side events:
- Navigate to Ghost Admin → Settings → Integrations
- Click Add custom integration
- Enter name: "Meta Conversion API"
- Click Create
- Copy Webhook URL
- Configure webhook to send
member.addedevents to your server
Performance Optimization
Preconnect to Meta Domains
Add to theme <head>:
<link rel="preconnect" href="https://connect.facebook.net">
<link rel="dns-prefetch" href="//connect.facebook.net">
Async Loading
Meta Pixel loads asynchronously by default. For additional control:
// Delay Meta Pixel until after page load
window.addEventListener('load', function() {
// Load Meta Pixel script here
});
Conditional Loading
Only load on specific content types:
{{!-- Only load Meta Pixel on posts and pages --}}
{{#is "post, page"}}
{{> meta-pixel}}
{{/is}}
Domain Verification
Verify your Ghost domain in Meta Business Suite for iOS 14+ tracking:
- Navigate to Meta Business Suite → Settings → Brand Safety → Domains
- Click Add
- Enter your Ghost domain
- Select verification method:
- HTML Tag - Add meta tag to Ghost code injection
- DNS TXT Record - Add DNS record to domain
HTML Tag Method:
- Copy the meta tag from Meta Business Suite
- Paste in Ghost Settings → Code Injection → Site Header:
<meta name="facebook-domain-verification" content="your-verification-code" />
- Click Save
- Return to Meta Business Suite and click Verify
Testing and Validation
Meta Pixel Helper
- Install Meta Pixel Helper Chrome extension
- Navigate to your Ghost site
- Click extension icon
- Verify:
Test Events Tool
Use Meta's Test Events feature:
- Navigate to Events Manager → Test Events
- Copy your Test Event Code
- Add to Ghost code injection:
<script>
fbq('init', 'YOUR_PIXEL_ID', {}, {
agent: 'test_event_code',
test_event_code: 'TEST12345'
});
</script>
- Trigger events on your Ghost site
- Verify events appear in Test Events dashboard
Browser Console
Check for Meta Pixel in console:
// Verify fbq function exists
console.log(typeof fbq);
// Expected: "function"
// Check pixel version
console.log(fbq.version);
// Expected: "2.0"
// Manual event test
fbq('track', 'PageView');
Common Issues
Pixel Not Firing
- Verify Pixel ID - Check for typos in pixel ID
- Ad Blockers - Test in incognito without extensions
- Code Placement - Ensure pixel in
<head>before\{\{ghost_head\}\} - JavaScript Errors - Check browser console for errors
Multiple Pixel Fires
- Code Injection + Theme - Remove duplicate implementations
- GTM + Direct - Use only one method (GTM or direct)
- Meta Pixel Helper - Shows "Multiple Pixels" warning
Events Not Recording
- Pixel Not Active - Verify pixel is active in Events Manager
- Domain Mismatch - Ensure domain matches pixel configuration
- Ad Blockers - Users with ad blockers won't track
- iOS 14+ Issues - Implement domain verification and CAPI
Performance Impact
- Too Many Events - Limit custom events
- Large Payloads - Keep custom data minimal
- Synchronous Loading - Ensure async attribute present
Ghost(Pro) vs. Self-Hosted
Ghost(Pro)
- Code Injection: Recommended (no theme upload needed)
- Theme Method: Requires theme upload
- CAPI: Requires external server for webhooks
- Domain Verification: Fully supported
Self-Hosted
- File Access: Direct theme editing
- Server-Side CAPI: Can run on same server
- Custom Events: Full control over event tracking
- Webhooks: Can handle internally
Next Steps
- Meta Pixel Event Tracking - Track Ghost-specific events
- GTM Setup - Deploy Meta Pixel via GTM
- Troubleshooting Events - Debug Meta Pixel issues