Wix Studio: OpenAI Ads Pixel and CAPI for Wix & Wix Studio: Complete Setup
Complete technical guide to setting up OpenAI Ads Measurement Pixel and CAPI on Wix and Wix Studio using Custom Code, Velo backend events, and fetch APIs.
Wix Studio provides a design-focused workspace for web development agencies, backed by the Velo full-stack JavaScript environment.
The Velo backend offers a distinct advantage: you can execute server-side Conversions API calls natively without requiring third-party middleware or separate cloud hosts.
Standard tutorials often advise pasting a tracking snippet into Custom Code settings and stopping there. But client-only tracking remains vulnerable to browser privacy extensions, ad blockers, and unreturned checkout redirects.
By utilizing Velo backend event hooks (backend/events.js), you can capture form submissions and online sales on the server and transmit them directly to OpenAI's Conversions API using wix-fetch.
Here is how to set up both Custom Code client pixels and Velo backend modules in Wix Studio.
Client-side pixel via Custom Code
Deploy the measurement script in your Wix Studio dashboard:
- Open your Wix Studio dashboard and navigate to Settings, then Custom Code.
- Click Add Custom Code.
- Paste 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>
- Set placement to Head, apply to All Pages, and click Apply.
Server-side CAPI via Velo backend events
Enable Dev Mode in your Wix Studio editor. In the Code panel, open backend/events.js and add this event hook:
import { fetch } from 'wix-fetch';
import wixSecretsBackend from 'wix-secrets-backend';
import crypto from 'crypto';
function hashSha256(value) {
if (!value) return null;
return crypto.createHash('sha256').update(value.trim().toLowerCase()).digest('hex');
}
export async function wixForms_onFormSubmitted(event) {
const submissionId = event.submissionId;
const formId = event.formId;
const formName = event.formName || 'Wix Form';
const fields = event.fields || {};
let rawEmail = null;
let rawPhone = null;
for (const key of Object.keys(fields)) {
const val = fields[key];
const lowerKey = key.toLowerCase();
if ((lowerKey.includes('email') || lowerKey.includes('mail')) && typeof val === 'string') {
rawEmail = val;
}
if ((lowerKey.includes('phone') || lowerKey.includes('tel')) && typeof val === 'string') {
rawPhone = val.replace(/[^0-9]/g, '');
}
}
if (!rawEmail) {
return;
}
const hashedEmail = hashSha256(rawEmail);
const hashedPhone = rawPhone ? hashSha256(rawPhone) : null;
const dedupeId = `wix_lead_${submissionId}`;
const apiToken = await wixSecretsBackend.getSecret('OPENAI_ADS_ACCESS_TOKEN');
const payload = {
data: [
{
event_name: 'Lead',
event_time: Math.floor(Date.now() / 1000),
event_id: dedupeId,
user_data: {
em: hashedEmail,
ph: hashedPhone
},
custom_data: {
content_name: formName,
form_id: formId
},
action_source: 'system_generated'
}
]
};
try {
const response = await fetch('https://bzr.openai.com/v1/events', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!response.ok) {
console.error('OpenAI CAPI Error:', await response.text());
}
} catch (err) {
console.error('Failed to dispatch OpenAI CAPI event:', err);
}
}
Store your API token securely under Developer Tools, then Secrets Manager, with the key OPENAI_ADS_ACCESS_TOKEN.
Front-end form event matching in Velo
To ensure the client Lead event sends the identical event_id before the form clears:
In your page code file:
$w.onReady(function () {
const formElement = $w('#wixForm1');
if (formElement) {
formElement.onWixFormSubmitted((event) => {
const submissionId = event.fields.submissionId || event.submissionId;
const dedupeId = `wix_lead_${submissionId}`;
if (typeof window !== 'undefined' && window.openaiAds) {
window.openaiAds('track', 'Lead', {
content_name: 'Contact Inquiry'
}, {
event_id: dedupeId
});
}
});
}
});
Verification checklist
Inspect the HTML head of your live site to confirm the tracking script is present.
Open Developer Tools, submit a form in preview mode, and verify in Site Events logs that wixForms_onFormSubmitted executed successfully.
Check OpenAI Ads Event Manager to confirm that browser and Velo server events merge into a single conversion.
Frequently asked questions
Where is the pixel script added in Wix Studio?
In your site dashboard, go to Settings, open Custom Code, click Add Custom Code, and paste the code into the Head section for All Pages.
How do I track form submissions on Wix Studio?
Use Velo frontend code to hook into onWixFormSubmitted for client tracking, and use backend/events.js to dispatch authenticated server CAPI requests.
Does Wix Studio require external middleware for CAPI?
No. Velo includes native server execution via wix-fetch and wix-secrets-backend, allowing you to deliver CAPI requests without third-party services.
How does deduplication work in Wix Studio?
Both the client form handler and the backend wixForms_onFormSubmitted hook use wix_lead_ plus the form submissionId as the shared event_id.
Need ChatGPT tracking installed?
Configured, tested, documented.