← Back to Insights

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

Complete step-by-step technical guide to setting up OpenAI Ads Measurement Pixel and Conversions API (CAPI) on Joomla 4 and 5 with system plugins and form hooks.

2026-04-05 • CMS & Website Builders

Joomla powers corporate portals, multilingual web services, and online storefronts worldwide.

Setting up advertising telemetry on Joomla requires careful planning. Hardcoded template scripts can be overwritten during core or theme updates, while front-end scripts remain susceptible to content blockers and cookie lifespan limits.

A decoupled hybrid tracking framework provides greater stability.

You inject the client measurement pixel through a custom system plugin, keeping tracking code separate from template files. On the server side, you hook into form components like RSForm! Pro or Convert Forms to dispatch authenticated CAPI requests directly from PHP.

Here is how to set up both client-side pixel scripts and server-side CAPI processing in Joomla.

Adding the base pixel via a custom system plugin

Create a system plugin at plugins/system/openaiads/openaiads.php:

<?php
defined('_JEXEC') or die;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Factory;

class PlgSystemOpenaiads extends CMSPlugin
{
    protected $app;

    public function onBeforeCompileHead()
    {
        if ($this->app->isClient('administrator')) {
            return;
        }

        $pixelId = $this->params->get('pixel_id');
        if (empty($pixelId)) {
            return;
        }

        $document = Factory::getApplication()->getDocument();

        $script = <<<JS
!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', '{$pixelId}');
openaiAds('track', 'PageView');
JS;

        $document->addScriptDeclaration($script);
    }
}

This attaches the loader to the document head across all public pages while excluding admin views.

Server-side CAPI via form component scripts

In RSForm! Pro, navigate to Manage Forms, choose your form, open Properties, and select PHP Scripts.

In the Script called after form has been processed section, insert:

// Retrieve form submission values
$submissionId = $SubmissionId;
$formId = $formId;

$email = isset($_POST['form']['email']) ? trim($_POST['form']['email']) : '';
$phone = isset($_POST['form']['phone']) ? trim($_POST['form']['phone']) : '';

if (!empty($email)) {
    $eventId = 'joomla_lead_' . $formId . '_' . $submissionId;

    $hashedEmail = hash('sha256', strtolower($email));
    $hashedPhone = !empty($phone) ? hash('sha256', preg_replace('/[^0-9]/', '', $phone)) : null;

    $apiToken = 'YOUR_OPENAI_ADS_ACCESS_TOKEN';

    $payload = [
        'data' => [
            [
                'event_name' => 'Lead',
                'event_time' => time(),
                'event_id' => $eventId,
                'user_data' => array_filter([
                    'em' => $hashedEmail,
                    'ph' => $hashedPhone,
                    'client_user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? null,
                    'client_ip_address' => $_SERVER['REMOTE_ADDR'] ?? null,
                ]),
                'custom_data' => [
                    'content_name' => 'Joomla RSForm Lead',
                    'form_id' => (string) $formId,
                ],
                'action_source' => 'system_generated'
            ]
        ]
    ];

    try {
        $http = \Joomla\CMS\Http\HttpFactory::getHttp();
        $headers = [
            'Authorization' => 'Bearer ' . $apiToken,
            'Content-Type'  => 'application/json'
        ];
        $http->post('https://bzr.openai.com/v1/events', json_encode($payload), $headers, 4);
    } catch (\Exception $e) {
        \Joomla\CMS\Log\Log::add('OpenAI Ads CAPI Error: ' . $e->getMessage(), \Joomla\CMS\Log\Log::ERROR, 'openaiads');
    }
}

Front-end form event matching

In RSForm! Pro under CSS and Javascript, add this handler to the Javascript Action section:

function rsfp_onSuccess() {
  var submissionTimestamp = Date.now();
  var dedupeId = 'joomla_lead_general_' + submissionTimestamp;

  if (window.openaiAds) {
    window.openaiAds('track', 'Lead', {
      content_name: 'RSForm Submission'
    }, {
      event_id: dedupeId
    });
  }
}

Verification checklist

Inspect the HTML page source of your live site to confirm the pixel initialization script appears in the head.

Submit a test inquiry through your form and check Joomla log files under administrator/logs to verify the outgoing HTTP POST executed successfully.

Check OpenAI Ads Event Manager to confirm that incoming lead events register without parameter validation warnings.

Frequently asked questions

Where should the OpenAI Ads pixel code be installed in Joomla?

Create a custom system plugin that registers an onBeforeCompileHead hook, or insert the code in your active template index file inside the head tags.

How do I capture form submissions with CAPI in Joomla?

In RSForm! Pro or your chosen form manager, use post-submission PHP hooks to extract customer data, hash email and phone values with SHA-256, and post to https://bzr.openai.com/v1/events using Joomla HttpFactory.

How does Joomla prevent duplicate conversion counts?

Both the client form script and server PHP hook construct matching event_id strings using the form ID and submission reference.

Does Joomla page caching interfere with CAPI dispatches?

No. Server-side post-save PHP hooks run during form submission processing, which operates independently of Joomla's page cache layer.

Need ChatGPT tracking installed?

Configured, tested, documented.