1// openai-pixel-interop.js 2// --------------------------------------------------------------------------- 3// Helpers for OpenAI Ads conversion tracking (the "oaiq" pixel, installed 4// site-wide via the admin Script Manager). 5// 6// Two jobs: 7// 1) captureOppref() â grab the OpenAI click reference (oppref) from the 8// landing-page URL and PERSIST it, so it survives SPA navigation AND the 9// cross-domain payment-gateway round-trip (CCAvenue/Razorpay). The pixel 10// SDK may set its own cookie, but cookies can be lost on the gateway hop, 11// so we keep our own copy in localStorage and pass it explicitly on the 12// conversion. Call this early on every page load. 13// 14// 2) fireOrderCreated(orderId) â fire the `order_created` conversion. Called 15// ONLY from the payment SUCCESS branch (PaymentResult.razor), so it can 16// only ever fire after a confirmed CCAvenue/Razorpay/PayU payment. Guarded 17// so it fires at most once per order (survives page refresh via 18// localStorage), so a user refreshing the success page won't double-count. 19// --------------------------------------------------------------------------- 20window.OpenAiPixelInterop = { 21 _OPPREF_KEY: 'oai_oppref', 22 _FIRED_KEY: 'oai_order_fired', // prefix; per-order flag = _FIRED_KEY + orderId 23 24 // Capture oppref from the current URL (if present) and remember it. 25 // Accepts common param spellings; stores the first one found. Idempotent: 26 // once stored, a later page without the param does NOT wipe it. 27 captureOppref: function () { 28 try { 29 var params = new URLSearchParams(window.location.search); 30 var val = params.get('oppref') || params.get('oai_oppref') || params.get('openai_oppref'); 31 if (val) { 32 localStorage.setItem(this._OPPREF_KEY, val); 33 } 34 } catch (e) { /* localStorage unavailable â pixel cookie still applies */ } 35 }, 36 37 getOppref: function () { 38 try { return localStorage.getItem(this._OPPREF_KEY) || null; } catch (e) { return null; } 39 }, 40 41 // Fire the order_created conversion for a successful payment. orderId is used 42 // only for the once-per-order guard (not sent unless you want it in props). 43 fireOrderCreated: function (orderId) { 44 try { 45 // Once-per-order guard (persists across refresh of the success page). 46 var firedKey = this._FIRED_KEY + (orderId || ''); 47 if (orderId && localStorage.getItem(firedKey) === '1') return false; 48 49 // The pixel SDK (oaiq) is loaded site-wide via Script Manager. If it 50 // hasn't finished loading, oaiq still queues calls (the snippet sets 51 // up a command queue), so this is safe to call immediately. 52 if (typeof window.oaiq !== 'function') return false; 53 54 var props = { type: 'contents' }; 55 var oppref = this.getOppref(); 56 if (oppref) props.oppref = oppref; // pass the preserved click ref explicitly 57 58 window.oaiq('measure', 'order_created', props); 59 60 if (orderId) localStorage.setItem(firedKey, '1'); 61 return true; 62 } catch (e) { return false; } 63 } 64}; 65 66// Capture oppref as soon as this script runs (it loads on every page, before 67// Blazor starts), so the very first landing URL is recorded even if the user 68// navigates away immediately. 69try { window.OpenAiPixelInterop.captureOppref(); } catch (e) { }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.