Commerce events (items_added, checkout_started, order_created) are silently dropped by the pixel SDK's validator
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3623577. -->
Reported by: [introfini](https://www.drupal.org/user/42293)
>>>
<h3>Problem/Motivation</h3>
<p>The Commerce sub-module's <code>items_added</code>, <code>checkout_started</code> and <code>order_created</code> events never reach the OpenAI Advertiser API in production, even though the consent gate, the AJAX drain path and the <code>page_top</code> lazy builder all work correctly and the events are dispatched to <code>oaiq('measure', ...)</code> exactly as designed.</p>
<p>Reproduced live on a production site: an add to cart with consent granted produces zero <code>items_added</code> events in the Advertiser API's diagnostic stream, while <code>page_viewed</code> (built by hand in JavaScript, not by this sub-module) keeps arriving normally.</p>
<h3>Root cause</h3>
<p>The pixel SDK (<a href="https://bzrcdn.openai.com/sdk/oaiq.min.js">bzrcdn.openai.com/sdk/oaiq.min.js</a>) validates every <code>contents[]</code> item client side against a closed list of documented fields (<code>id</code>, <code>name</code>, <code>content_type</code>, <code>quantity</code>, <code>amount</code>, <code>currency</code>, matching <a href="https://developers.openai.com/ads/measurement-pixel">developers.openai.com/ads/measurement-pixel</a>, which says outright: "Use only the documented fields inside contents[]"). Any other key makes the validator drop the whole event, silently, before any network request: the SDK only logs <code>[oaiq] validation failed; event dropped</code> to the console, with no detail unless the pixel is initialised in debug mode.</p>
<p><code>OrderEventBuilder::content()</code> in <code>modules/chatgpt_ads_commerce/src/OrderEventBuilder.php</code> adds an undocumented <code>group_id</code> key (the parent product id) to every content item whenever the purchased entity is a product variation that belongs to a product, which is true for essentially every real Commerce order. Since this helper backs <code>content()</code> for <code>itemsAdded()</code> directly and, through <code>orderData()</code>, for <code>checkoutStarted()</code> and <code>orderCreated()</code> as well, all three events are affected, not only <code>items_added</code>.</p>
<p>Confirmed directly in a browser, on the real (unstubbed) SDK: calling <code>oaiq('measure', 'items_added', {type: 'contents', amount: 29000, currency: 'EUR', contents: [{id: 'X', group_id: '413', name: 'Test', quantity: 1, amount: 29000, currency: 'EUR'}]})</code> logs the validation warning and sends nothing; removing only <code>group_id</code> from the same payload sends cleanly.</p>
<h4>Steps to reproduce</h4>
<ol>
<li>Enable <code>chatgpt_ads_commerce</code> with <code>items_added</code> on, and a pixel id.</li>
<li>Open the browser console on a page with the pixel loaded and consent granted.</li>
<li>Add any product that belongs to a product entity (i.e. any normal Commerce product) to the cart.</li>
<li>Observe <code>[oaiq] validation failed; event dropped</code> in the console, and no matching event in the Advertiser API's conversions/events diagnostic endpoint.</li>
</ol>
<h3>Proposed resolution</h3>
<p>Stop sending <code>group_id</code>. There is no documented field in the Measurement Pixel schema for a product's parent/group id, so it cannot be remapped, only removed.</p>
<h3>Remaining tasks</h3>
<p>Merge request attached. The existing Playwright suite for this sub-module always stubs <code>window.oaiq</code> before the real SDK script runs (see <code>e2e/chatgpt_ads/helpers.ts</code>, <code>stubPixel()</code>), which is exactly why this shipped undetected in 1.0.0-beta1: no test in the suite ever lets the real SDK's validator see a real payload. Worth a follow-up issue to add one spec that loads the genuine SDK and asserts no validation warning fires, rather than widening this fix's scope.</p>
issue
GitLab AI Context
Project: project/chatgpt_ads
Instance: https://git.drupalcode.org
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://git.drupalcode.org/project/chatgpt_ads/-/raw/1.0.x/README.md — project overview and setup
Repository: https://git.drupalcode.org/project/chatgpt_ads
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD