← Back to Insights

Webflow: OpenAI Ads Pixel and CAPI for Webflow: Complete Setup

Step-by-step guide to installing OpenAI Ads Measurement Pixel and CAPI on Webflow with custom code head embeds, form events, and Webflow Logic relays.

2026-03-30 • CMS & Website Builders

Webflow offers extensive design control for marketing sites, but its managed hosting environment imposes specific constraints on custom tracking code.

Because Webflow does not provide direct access to an underlying backend server, you cannot execute custom PHP or Node scripts inside your hosting account. When visitors submit forms while running privacy tools or ad blockers, client-side code snippets fail silently.

Unrecorded form fills prevent ad network optimization from identifying winning audiences.

A resilient tracking structure combines Webflow's client-side Head Embed with an automated serverless webhook relay. The browser pixel tracks page views and client form submits, while a Webflow form webhook triggers a Cloudflare Worker or Make workflow to transmit verified submissions directly to OpenAI's Conversions API.

Here is how to set up both client tracking and webhook relays on Webflow.

Adding the base pixel in Webflow custom code

Insert the base measurement script into site-wide settings:

  1. Open your project inside the Webflow Designer and select Project Settings.
  2. Navigate to Custom Code.
  3. In the Head Code text area, 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>
<noscript>
  <img height="1" width="1" style="display:none" 
       src="https://bzr.openai.com/v1/events?pixel_id=YOUR_PIXEL_ID&event=PageView&noscript=1" />
</noscript>
  1. Save changes and publish your site.

Front-end form submission tracking

In Project Settings under Custom Code, add this listener into Footer Code:

<script>
  document.addEventListener('DOMContentLoaded', function () {
    var forms = document.querySelectorAll('form');

    forms.forEach(function (form) {
      form.addEventListener('submit', function () {
        var formName = form.getAttribute('data-name') || form.getAttribute('name') || 'Webflow Lead';
        var submissionId = 'wf_lead_' + formName.toLowerCase().replace(/[^a-z0-9]/g, '_') + '_' + Date.now();

        var hiddenInput = form.querySelector('input[name="openai_event_id"]');
        if (!hiddenInput) {
          hiddenInput = document.createElement('input');
          hiddenInput.type = 'hidden';
          hiddenInput.name = 'openai_event_id';
          form.appendChild(hiddenInput);
        }
        hiddenInput.value = submissionId;

        if (window.openaiAds) {
          window.openaiAds('track', 'Lead', {
            content_name: formName
          }, {
            event_id: submissionId
          });
        }
      });
    });
  });
</script>

Server-side CAPI via Webflow webhook relay

To ensure submissions are captured when client scripts fail, set up a serverless webhook relay:

In Webflow Project Settings, open Integrations, then Webhooks, click Add Webhook, set Trigger Type to Form Submission, and enter your relay URL.

Deploy your Cloudflare Worker relay:

export default {
  async fetch(request, env) {
    if (request.method !== 'POST') {
      return new Response('Method Not Allowed', { status: 405 });
    }

    try {
      const body = await request.json();
      const formData = body.data || {};
      const formName = body.name || 'Webflow Lead';

      const eventId = formData.openai_event_id || 
        `wf_lead_${formName.toLowerCase().replace(/[^a-z0-9]/g, '_')}_${Date.now()}`;

      const hashSha256 = async (str) => {
        if (!str) return null;
        const buf = new TextEncoder().encode(str.trim().toLowerCase());
        const digest = await crypto.subtle.digest('SHA-256', buf);
        return Array.from(new Uint8Array(digest))
          .map(b => b.toString(16).padStart(2, '0'))
          .join('');
      };

      let rawEmail = null;
      let rawPhone = null;

      for (const [key, val] of Object.entries(formData)) {
        const lowerKey = key.toLowerCase();
        if (lowerKey.includes('email') && typeof val === 'string') rawEmail = val;
        if (lowerKey.includes('phone') && typeof val === 'string') rawPhone = val;
      }

      const hashedEmail = await hashSha256(rawEmail);
      const hashedPhone = rawPhone ? await hashSha256(rawPhone.replace(/[^0-9]/g, '')) : null;

      const payload = {
        data: [
          {
            event_name: 'Lead',
            event_time: Math.floor(Date.now() / 1000),
            event_id: eventId,
            user_data: {
              ...(hashedEmail && { em: hashedEmail }),
              ...(hashedPhone && { ph: hashedPhone })
            },
            custom_data: {
              content_name: formName
            },
            action_source: 'system_generated'
          }
        ]
      };

      const capiResponse = 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(payload)
      });

      return new Response('Processed', { status: capiResponse.status });
    } catch (err) {
      return new Response('Internal Server Error: ' + err.message, { status: 500 });
    }
  }
};

Verification checklist

Submit a test lead on your live Webflow site and inspect the network tab to verify the base pixel and event calls execute.

Confirm that openai_event_id is populated in the form payload received by your webhook endpoint.

Review OpenAI Ads Event Manager to confirm that browser and webhook lead conversions merge into a single attributed event.

Frequently asked questions

Where do I insert the OpenAI Ads pixel in Webflow?

Go to Project Settings, select Custom Code, and insert the script in the Head Code section before publishing.

How do I track form leads on Webflow?

Add a JavaScript event listener inside Footer Code targeting form submit events, firing openaiAds('track', 'Lead', {...}).

Can Webflow trigger server-side CAPI events?

Yes. Configure a Form Submission Webhook in Project Settings pointing to a serverless function that hashes customer data and posts to https://bzr.openai.com/v1/events.

How do I avoid duplicate lead records?

Generate a shared submission identifier in the client form listener and pass that identical string to the webhook payload as event_id.

Need ChatGPT tracking installed?

Configured, tested, documented.