OpenAI Ads
Configure the OpenAI Pixel and Conversions API with event ID deduplication.
Set up the OpenAI Pixel in the web container first. Then send matching events through the OpenAI Conversions API.
Both tags send the same conversion. Give both tags the same event name and event ID. OpenAI can then deduplicate the events and count one conversion.
This hybrid setup captures browser and server events. It also reduces losses from ad blockers and browser cookie restrictions.
What you'll configure
You will create:
An OpenAI Pixel tag in the GTM web container.
An OpenAI Conversions API tag in the GTM server container.
One shared
event_idfor each matching browser and server event.
Use this page for the complete implementation. See OpenAI credentials, event ID deduplication, and campaign URL tracking.
Before you start
Make sure you have:
Part 1: Set up client-side tracking
Step 1: Add the OpenAI Pixel template
Open your GTM web container and go to Templates.
Under Tag Templates, click Search Gallery.
Search for the OpenAI Pixel tag template and add it.
Step 2: Create a Pixel ID variable
Go to Variables and create a Constant variable.
Set its value to the OpenAI Pixel ID.
Save it as your Pixel ID variable.
Step 3: Create client-side event tags
Create a new OpenAI Pixel tag.
Select your Pixel ID variable.
Choose Inherit from DataLayer to reuse the GA4 event name.
Choose Override only when OpenAI requires a different event name.
Keep Automatic Event Parameters mapping enabled.
Under Server-Side Tracking Settings, set Event ID to your Unique Event ID variable.
Use the same trigger as the matching GA4 event tag.
Repeat this for every event you want to track. Include page_view with the same trigger as the GA4 page view tag.
Step 4: Pass the event ID to GA4
Add the same Unique Event ID variable to every matching GA4 event tag:
Open the GA4 event tag.
Add an event parameter named
event_id.Set its value to the Unique Event ID variable.
Save the tag.
The server container can now read the event ID from the GA4 event.
Part 2: Set up server-side tracking
Step 5: Add the Conversions API template
Open your GTM server container and go to Templates.
Under Tag Templates, click Search Gallery.
Add the OpenAI Conversions API tag template.
Step 6: Create the server-side tag
Create a new OpenAI Conversions API tag.
Under Event Name Setup Method, choose Inherit from client.
Choose Override only when the Pixel tag uses the same override.
Choose the correct Action Source, such as Website.
Enter the OpenAI Pixel ID and API key.
Keep Automatic Event Parameters mapping enabled.
Step 7: Pass the event ID to OpenAI
Create a server-container variable that reads the incoming
event_idevent parameter.Open the OpenAI Conversions API tag.
Under Server Event Data Parameters, add Event ID.
Set its value to the server-side event ID variable.
Step 8: Configure consent and the trigger
Enable Consent Granted / GTM Consent Mode support. Map it to marketing consent.
Create a trigger for the events you want to send. Use both conditions:
{{Event Name}}matches RegExpurchase|order_completed.{{Client Name}}equalsGA4.
Leave Set Click ID cookie enabled unless the client requires otherwise. It stores OpenAI's click ID in the first-party __oppref cookie.
Test and validate the complete setup in preview mode
Before you publish, confirm that the OpenAI cookies reach the server container and that the Conversions API tag forwards the click ID (oppref) and the browser reference (obref) to OpenAI.
The Pixel stores both values in first-party cookies (__oppref and __obref). The Conversions API does not capture them for you. The tag must find the click ID in the URL, the cookie, or the event data, and send it as oppref. The browser reference goes in user.obref, unchanged.
Prepare the test
Open a clean incognito window. Connect GTM preview mode for both the web container and the server container.
Work in a separate workspace. If the tag offers Validate Only, enable it for the test, so test events are excluded from measurement. Switch it off again before you publish.
Open a landing page with a test click ID, for example
https://yourdomain.com/?oppref=test123. You can also click a test campaign

Where to look in server preview
Incoming request (client)
The cookie header contains __oppref and __obref. If they are missing, the tag cannot read them. The server container is probably not running on a first-party domain of the website.
Event Data
page_location contains the oppref parameter. The consent state shows ad_storage granted.
OpenAI tag → Request
The URL is https://bzr.openai.com/v1/events?pid=<PIXEL-ID>. The body contains oppref, user.obref, id and source_url.
Browser → Application → Cookies
__oppref exists with the expected domain and expiry. The server container sets it in the Set-Cookie header of its response.
Run the test scenarios
1
Landing page with oppref in the URL, marketing consent granted
The first event contains oppref, equal to the URL value. The __oppref cookie is set.
2
Second page view without oppref in the URL
oppref comes from the cookie and has the same value.
3
Second ad click with a different oppref
The new value is sent and the cookie is overwritten.
4
Direct visit without oppref
oppref is omitted from the body. It is not an empty string.
5
Marketing consent denied
No request goes to OpenAI and no cookies are set. Revoking consent removes the cookies.
6
Consent given after the landing page loaded
The OpenAI tag fires after the consent update and still contains oppref from the URL.
7
user.obref
Equals the value of the __obref cookie and is not hashed.
8
Pixel and Conversions API together
Both send the same event ID, so only one conversion counts.
9
Purchase sent from a shop webhook
No browser cookies are available. Store the click ID with the order and set it manually in the tag.
Apply the findings to the template
Update the OpenAI Conversions API template to the latest version from the gallery. Check that the user fields in the request body match the OpenAI specification, for example
emails_sha256,cities,postal_codesandcountriesas lists.If
opprefis missing on the first event althoughpage_locationcontains it, set the Click ID manually under Server Event Data Parameters. Use a variable that readsoppreffrompage_locationfirst, then from the__opprefcookie, then from the event data. Manual values take precedence over automapped ones, so make sure the variable falls back correctly. Test in preview what happens when the variable is empty.Keep Set Click ID cookie enabled. Leave HTTP Only on its default (off), so browser scripts can still read the cookie. Choose an expiry that matches OpenAI's cookie lifetime of 30 to 90 days.
Fire the OpenAI Pixel
page_viewtag after the consent update. The landing URL containsopprefon the first page only. If the tag fires before consent is known, the click ID is lost.Use the same Unique Event ID in both tags. Disable Autogenerate an Event ID in the server tag when the Pixel also sends events.
Check the result after publishing
In the outgoing request logs, confirm that:
Landing pages with
opprefin the URL carryopprefin the request body.Follow-up page views carry the same value.
No requests contain
"validate_only": true.The number of non-2xx responses does not increase.
Last updated
Was this helpful?

