Skip to content

Commit 6bd10b2

Browse files
paragmoreclaude
andcommitted
[SURF-1546] feat(conversions): fire the OpenAI Ads pixel
Adds OpenAI Ads (oaiq) as a conversion provider in the parent embed tag, mirroring the in-frame firing in surface_forms. Bootstraps the oaiq SDK if absent, then measures a `customer_action` conversion with the response ID as the event_id dedupe key. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018VUdEBjARoRAXvcVtaCS2N
1 parent 31f25eb commit 6bd10b2

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎src/conversions/conversion-listener.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { fireConversion, type ConversionProvider } from "./providers";
55
const CONVERSION_MESSAGE_TYPE = "surface:conversion";
66
const CONVERSION_ACK_TYPE = "surface:conversion:ack";
77

8-
const VALID_PROVIDERS: ConversionProvider[] = ["x", "meta", "ga4", "linkedin"];
8+
const VALID_PROVIDERS: ConversionProvider[] = ["x", "meta", "openai", "ga4", "linkedin"];
99

1010
// Idempotency: a form may retry a send; only fire once per message id.
1111
const firedIds = new Set<string>();

‎src/conversions/providers.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
/* eslint-disable @typescript-eslint/no-explicit-any */
88

9-
export type ConversionProvider = "x" | "meta" | "ga4" | "linkedin";
9+
export type ConversionProvider = "x" | "meta" | "openai" | "ga4" | "linkedin";
1010

1111
export type ConversionEventPayload =
1212
| { event_id: string; pixel_id: string } // x
13-
| { pixel_id: string; event_name: string } // meta
13+
| { pixel_id: string; event_name: string } // meta / openai
1414
| { measurement_id: string; event_name: string } // ga4
1515
| { partner_id: string; conversion_id: string }; // linkedin
1616

@@ -60,6 +60,21 @@ const ensureFbq = (pixelId: string) => {
6060
win.fbq("init", pixelId);
6161
};
6262

63+
const ensureOaiq = (pixelId: string) => {
64+
const win = w();
65+
if (!win.oaiq) {
66+
const q: any = (win.oaiq = function (...args: any[]) {
67+
q.q.push(args);
68+
});
69+
q.q = [];
70+
const el = document.createElement("script");
71+
el.async = true;
72+
el.src = "https://bzrcdn.openai.com/sdk/oaiq.min.js";
73+
document.head.appendChild(el);
74+
}
75+
win.oaiq("init", { pixelId });
76+
};
77+
6378
const ensureGtag = (measurementId: string) => {
6479
const win = w();
6580
if (!win.gtag) {
@@ -122,6 +137,11 @@ export const fireConversion = (
122137
ensureFbq(event.pixel_id);
123138
win.fbq("track", event.event_name, {}, { eventID: ctx.response_id });
124139
return true;
140+
case "openai":
141+
ensureOaiq(event.pixel_id);
142+
// event_id is the platform dedupe key (matches browser + server sends).
143+
win.oaiq("measure", event.event_name, { type: "customer_action" }, { event_id: ctx.response_id });
144+
return true;
125145
case "ga4":
126146
ensureGtag(event.measurement_id);
127147
// send_to pins the event to our property when the page's gtag also has

0 commit comments

Comments
 (0)