Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/conversions/conversion-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fireConversion, type ConversionProvider } from "./providers";
const CONVERSION_MESSAGE_TYPE = "surface:conversion";
const CONVERSION_ACK_TYPE = "surface:conversion:ack";

const VALID_PROVIDERS: ConversionProvider[] = ["x", "meta", "ga4", "linkedin"];
const VALID_PROVIDERS: ConversionProvider[] = ["x", "meta", "openai", "ga4", "linkedin"];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Generated bundle rejects OpenAI

When the distributed embed receives an OpenAI conversion message, the unchanged surface_tag.js allowlist rejects it before dispatch, causing the new parent-context pixel path not to run. Regenerate and commit the browser bundle after this source change.

Context Used: CLAUDE.md (source)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, and already addressed. You reviewed 6bd10b2, which changed only the TypeScript source. The regenerated + committed bundle landed in the amended commit 04e8138 (surface_tag.js / surface_embed_v1.js now include ensureOaiq + the openai case + the openai entry in VALID_PROVIDERS). CI's "Bundle is up to date" check went from failing to passing on that commit, so deployed embeds will dispatch openai messages. Resolved.


// Idempotency: a form may retry a send; only fire once per message id.
const firedIds = new Set<string>();
Expand Down
24 changes: 22 additions & 2 deletions src/conversions/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

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

export type ConversionProvider = "x" | "meta" | "ga4" | "linkedin";
export type ConversionProvider = "x" | "meta" | "openai" | "ga4" | "linkedin";

export type ConversionEventPayload =
| { event_id: string; pixel_id: string } // x
| { pixel_id: string; event_name: string } // meta
| { pixel_id: string; event_name: string } // meta / openai
| { measurement_id: string; event_name: string } // ga4
| { partner_id: string; conversion_id: string }; // linkedin

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

const ensureOaiq = (pixelId: string) => {
const win = w();
if (!win.oaiq) {
const q: any = (win.oaiq = function (...args: any[]) {
q.q.push(args);
});
q.q = [];
const el = document.createElement("script");
el.async = true;
el.src = "https://bzrcdn.openai.com/sdk/oaiq.min.js";
document.head.appendChild(el);
}
win.oaiq("init", { pixelId });
};

const ensureGtag = (measurementId: string) => {
const win = w();
if (!win.gtag) {
Expand Down Expand Up @@ -122,6 +137,11 @@ export const fireConversion = (
ensureFbq(event.pixel_id);
win.fbq("track", event.event_name, {}, { eventID: ctx.response_id });
return true;
case "openai":
ensureOaiq(event.pixel_id);
// event_id is the platform dedupe key (matches browser + server sends).
win.oaiq("measure", event.event_name, { type: "customer_action" }, { event_id: ctx.response_id });
return true;
case "ga4":
ensureGtag(event.measurement_id);
// send_to pins the event to our property when the page's gtag also has
Expand Down
20 changes: 19 additions & 1 deletion surface_embed_v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,20 @@
}
win.fbq("init", pixelId);
};
var ensureOaiq = (pixelId) => {
const win = w();
if (!win.oaiq) {
const q = win.oaiq = function(...args) {
q.q.push(args);
};
q.q = [];
const el = document.createElement("script");
el.async = true;
el.src = "https://bzrcdn.openai.com/sdk/oaiq.min.js";
document.head.appendChild(el);
}
win.oaiq("init", { pixelId });
};
var ensureGtag = (measurementId) => {
const win = w();
if (!win.gtag) {
Expand Down Expand Up @@ -363,6 +377,10 @@
ensureFbq(event.pixel_id);
win.fbq("track", event.event_name, {}, { eventID: ctx.response_id });
return true;
case "openai":
ensureOaiq(event.pixel_id);
win.oaiq("measure", event.event_name, { type: "customer_action" }, { event_id: ctx.response_id });
return true;
case "ga4":
ensureGtag(event.measurement_id);
win.gtag("event", event.event_name, {
Expand All @@ -385,7 +403,7 @@
// src/conversions/conversion-listener.ts
var CONVERSION_MESSAGE_TYPE = "surface:conversion";
var CONVERSION_ACK_TYPE = "surface:conversion:ack";
var VALID_PROVIDERS = ["x", "meta", "ga4", "linkedin"];
var VALID_PROVIDERS = ["x", "meta", "openai", "ga4", "linkedin"];
var firedIds = /* @__PURE__ */ new Set();
var isConversionMessage = (data) => !!data && data.type === CONVERSION_MESSAGE_TYPE && typeof data.id === "string" && VALID_PROVIDERS.includes(data.provider) && !!data.event && typeof data.response_id === "string";
var handleConversionMessage = (event, log2) => {
Expand Down
20 changes: 19 additions & 1 deletion surface_tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,20 @@
}
win.fbq("init", pixelId);
};
var ensureOaiq = (pixelId) => {
const win = w();
if (!win.oaiq) {
const q = win.oaiq = function(...args) {
q.q.push(args);
};
q.q = [];
const el = document.createElement("script");
el.async = true;
el.src = "https://bzrcdn.openai.com/sdk/oaiq.min.js";
document.head.appendChild(el);
}
win.oaiq("init", { pixelId });
};
var ensureGtag = (measurementId) => {
const win = w();
if (!win.gtag) {
Expand Down Expand Up @@ -363,6 +377,10 @@
ensureFbq(event.pixel_id);
win.fbq("track", event.event_name, {}, { eventID: ctx.response_id });
return true;
case "openai":
ensureOaiq(event.pixel_id);
win.oaiq("measure", event.event_name, { type: "customer_action" }, { event_id: ctx.response_id });
return true;
case "ga4":
ensureGtag(event.measurement_id);
win.gtag("event", event.event_name, {
Expand All @@ -385,7 +403,7 @@
// src/conversions/conversion-listener.ts
var CONVERSION_MESSAGE_TYPE = "surface:conversion";
var CONVERSION_ACK_TYPE = "surface:conversion:ack";
var VALID_PROVIDERS = ["x", "meta", "ga4", "linkedin"];
var VALID_PROVIDERS = ["x", "meta", "openai", "ga4", "linkedin"];
var firedIds = /* @__PURE__ */ new Set();
var isConversionMessage = (data) => !!data && data.type === CONVERSION_MESSAGE_TYPE && typeof data.id === "string" && VALID_PROVIDERS.includes(data.provider) && !!data.event && typeof data.response_id === "string";
var handleConversionMessage = (event, log2) => {
Expand Down
Loading