Ghost CMS: OpenAI Ads Pixel and CAPI for Ghost CMS: Newsletter & Membership Tracking
Step-by-step technical guide to setting up OpenAI Ads Measurement Pixel and Conversions API on Ghost CMS for newsletter subscriptions and paid memberships.
Ghost is a popular platform for independent publishers and paid membership sites.
Ghost's built-in Portal membership system runs inside an isolated iframe, meaning standard page DOM listeners cannot easily detect when a reader submits their email or completes a subscription upgrade.
Tracking URL changes alone fails to capture most membership signups.
Reliable measurement on Ghost involves combining Ghost's Code Injection settings with native Admin Webhooks. The browser pixel tracks reader engagement and page views across public articles, while Ghost webhooks like member.added trigger server-to-server CAPI requests as soon as memberships are created.
Here is how to track newsletter signups and paid subscriptions on Ghost using both client pixels and server webhooks.
Adding the base pixel in Ghost Code Injection
Add the measurement snippet to your publication header:
- In Ghost Admin, open Settings using the gear icon.
- Select Code Injection.
- In the Site Header field, insert the base pixel snippet:
<script>
!function(w,d,e,u,t,s){if(w.openaiAds)return;t=w.openaiAds=function(){
t.callMethod?t.callMethod.apply(t,arguments):t.queue.push(arguments)};
if(!w._openaiAds)w._openaiAds=t;t.push=t;t.loaded=!0;t.version='1.0';
t.queue=[];s=d.createElement(e);s.async=!0;s.src=u;
var f=d.getElementsByTagName(e)[0];f.parentNode.insertBefore(s,f);
}(window,document,'script','https://bzrcdn.openai.com/pixel.js');
openaiAds('init', 'YOUR_PIXEL_ID');
openaiAds('track', 'PageView');
</script>
Front-end newsletter and checkout tracking
In the Site Footer section of Code Injection, add listeners to track inline signup forms and paid checkout returns:
<script>
document.addEventListener('DOMContentLoaded', function () {
var memberForms = document.querySelectorAll('form[data-members-form]');
memberForms.forEach(function (form) {
form.addEventListener('submit', function () {
var emailInput = form.querySelector('input[type="email"]');
var email = emailInput ? emailInput.value.trim().toLowerCase() : '';
var dedupeId = 'ghost_lead_' + Date.now();
if (window.openaiAds) {
window.openaiAds('track', 'Lead', {
content_name: 'Ghost Newsletter Signup'
}, {
event_id: dedupeId
});
}
});
});
var urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('stripe') === 'success') {
var purchaseId = 'ghost_stripe_' + Date.now();
if (window.openaiAds) {
window.openaiAds('track', 'Purchase', {
content_type: 'membership',
currency: 'USD'
}, {
event_id: purchaseId
});
}
}
});
</script>
Server-side CAPI via Ghost admin webhooks
To ensure all new subscribers are recorded, subscribe to Ghost's member.added webhook using an edge relay on Cloudflare Workers or Node.
Create a custom integration in Ghost Admin:
- Navigate to Settings, then Integrations.
- Click Add custom integration and name it OpenAI Ads CAPI.
- Click Add webhook, set the name to Member Created Webhook, select
Member addedas the event, and set the target URL to your relay worker endpoint.
Deploy your webhook relay worker:
export default {
async fetch(request, env) {
if (request.method !== 'POST') {
return new Response('Method Not Allowed', { status: 405 });
}
try {
const payload = await request.json();
const member = payload.member && payload.member.current ? payload.member.current : payload;
if (!member || !member.email) {
return new Response('Invalid payload', { status: 400 });
}
const memberId = member.id || member.uuid || Date.now().toString();
const dedupeId = `ghost_member_${memberId}`;
const hashSha256 = async (str) => {
if (!str) return null;
const buf = new TextEncoder().encode(str.trim().toLowerCase());
const hash = await crypto.subtle.digest('SHA-256', buf);
return Array.from(new Uint8Array(hash)).map(b => b.toString(16).padStart(2, '0')).join('');
};
const hashedEmail = await hashSha256(member.email);
const isPaid = member.status === 'paid' || (member.subscriptions && member.subscriptions.length > 0);
const eventName = isPaid ? 'Purchase' : 'Lead';
let customData = {
content_name: isPaid ? 'Ghost Paid Membership' : 'Ghost Free Newsletter'
};
if (isPaid && member.subscriptions && member.subscriptions[0]) {
const sub = member.subscriptions[0];
customData.value = Math.round(Number(sub.plan.amount || 0));
customData.currency = (sub.plan.currency || 'USD').toUpperCase();
customData.order_id = sub.id;
}
const capiPayload = {
data: [
{
event_name: eventName,
event_time: Math.floor(Date.now() / 1000),
event_id: dedupeId,
user_data: {
em: hashedEmail
},
custom_data: customData,
action_source: 'system_generated'
}
]
};
const res = await fetch('https://bzr.openai.com/v1/events', {
method: 'POST',
headers: {
'Authorization': `Bearer ${env.OPENAI_ADS_ACCESS_TOKEN}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(capiPayload)
});
return new Response('Processed', { status: res.status });
} catch (err) {
return new Response('Internal Server Error: ' + err.message, { status: 500 });
}
}
};
Quality assurance and verification
Check the Integrations dashboard in Ghost Admin to review webhook delivery status and response codes.
Confirm that email addresses passed in the em property are valid 64-character SHA-256 hashes.
Review OpenAI Ads Event Manager to verify that incoming free newsletter leads and paid subscriber purchases appear with correct parameter mappings.
Frequently asked questions
Where do I paste the OpenAI Ads tracking code in Ghost?
Go to Settings, select Code Injection, and place the script in the Site Header box. Save your changes to apply across your publication.
How do I track free newsletter signups in Ghost?
Add an event listener to forms marked with data-members-form in the Site Footer code injection, firing a Lead event when the form is submitted.
How do I report paid Ghost memberships to OpenAI Ads CAPI?
Configure a webhook integration in Ghost for member.added pointing to an edge function. The function checks for active Stripe subscription details and posts a Purchase event to https://bzr.openai.com/v1/events.
How are duplicate member signups prevented?
Construct the event_id using the subscriber's unique ID or email hash. OpenAI's ingestion pipeline reconciles duplicate events sharing this token.
Need ChatGPT tracking installed?
Configured, tested, documented.