@shware/analytics 16.0.0 → 16.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +76 -1
  2. package/dist/native/fbsdk.cjs +1 -2
  3. package/dist/native/fbsdk.cjs.map +1 -1
  4. package/dist/native/fbsdk.d.cts.map +1 -1
  5. package/dist/native/fbsdk.d.mts.map +1 -1
  6. package/dist/native/fbsdk.mjs +3 -4
  7. package/dist/native/fbsdk.mjs.map +1 -1
  8. package/dist/server/conversions-api-error.cjs +20 -0
  9. package/dist/server/conversions-api-error.cjs.map +1 -0
  10. package/dist/server/conversions-api-error.d.cts +17 -0
  11. package/dist/server/conversions-api-error.d.cts.map +1 -0
  12. package/dist/server/conversions-api-error.d.mts +17 -0
  13. package/dist/server/conversions-api-error.d.mts.map +1 -0
  14. package/dist/server/conversions-api-error.mjs +19 -0
  15. package/dist/server/conversions-api-error.mjs.map +1 -0
  16. package/dist/server/google-data-manager.cjs +24 -26
  17. package/dist/server/google-data-manager.cjs.map +1 -1
  18. package/dist/server/google-data-manager.d.cts +13 -5
  19. package/dist/server/google-data-manager.d.cts.map +1 -1
  20. package/dist/server/google-data-manager.d.mts +13 -5
  21. package/dist/server/google-data-manager.d.mts.map +1 -1
  22. package/dist/server/google-data-manager.mjs +24 -27
  23. package/dist/server/google-data-manager.mjs.map +1 -1
  24. package/dist/server/index.cjs +11 -0
  25. package/dist/server/index.d.cts +10 -7
  26. package/dist/server/index.d.mts +10 -7
  27. package/dist/server/index.mjs +9 -7
  28. package/dist/server/linkedin-conversions-api.cjs +29 -23
  29. package/dist/server/linkedin-conversions-api.cjs.map +1 -1
  30. package/dist/server/linkedin-conversions-api.d.cts +7 -2
  31. package/dist/server/linkedin-conversions-api.d.cts.map +1 -1
  32. package/dist/server/linkedin-conversions-api.d.mts +7 -2
  33. package/dist/server/linkedin-conversions-api.d.mts.map +1 -1
  34. package/dist/server/linkedin-conversions-api.mjs +29 -24
  35. package/dist/server/linkedin-conversions-api.mjs.map +1 -1
  36. package/dist/server/meta-capi.cjs +32 -31
  37. package/dist/server/meta-capi.cjs.map +1 -1
  38. package/dist/server/meta-capi.d.cts +12 -3
  39. package/dist/server/meta-capi.d.cts.map +1 -1
  40. package/dist/server/meta-capi.d.mts +12 -3
  41. package/dist/server/meta-capi.d.mts.map +1 -1
  42. package/dist/server/meta-capi.mjs +33 -33
  43. package/dist/server/meta-capi.mjs.map +1 -1
  44. package/dist/server/microsoft-conversions-api.cjs +33 -28
  45. package/dist/server/microsoft-conversions-api.cjs.map +1 -1
  46. package/dist/server/microsoft-conversions-api.d.cts +14 -2
  47. package/dist/server/microsoft-conversions-api.d.cts.map +1 -1
  48. package/dist/server/microsoft-conversions-api.d.mts +14 -2
  49. package/dist/server/microsoft-conversions-api.d.mts.map +1 -1
  50. package/dist/server/microsoft-conversions-api.mjs +33 -29
  51. package/dist/server/microsoft-conversions-api.mjs.map +1 -1
  52. package/dist/server/openai-conversions-api.cjs +20 -18
  53. package/dist/server/openai-conversions-api.cjs.map +1 -1
  54. package/dist/server/openai-conversions-api.d.cts +7 -0
  55. package/dist/server/openai-conversions-api.d.cts.map +1 -1
  56. package/dist/server/openai-conversions-api.d.mts +7 -0
  57. package/dist/server/openai-conversions-api.d.mts.map +1 -1
  58. package/dist/server/openai-conversions-api.mjs +21 -20
  59. package/dist/server/openai-conversions-api.mjs.map +1 -1
  60. package/dist/server/reddit-conversions-api.cjs +20 -18
  61. package/dist/server/reddit-conversions-api.cjs.map +1 -1
  62. package/dist/server/reddit-conversions-api.d.cts +7 -0
  63. package/dist/server/reddit-conversions-api.d.cts.map +1 -1
  64. package/dist/server/reddit-conversions-api.d.mts +7 -0
  65. package/dist/server/reddit-conversions-api.d.mts.map +1 -1
  66. package/dist/server/reddit-conversions-api.mjs +21 -20
  67. package/dist/server/reddit-conversions-api.mjs.map +1 -1
  68. package/dist/server/setup-conversions.cjs +62 -0
  69. package/dist/server/setup-conversions.cjs.map +1 -0
  70. package/dist/server/setup-conversions.d.cts +97 -0
  71. package/dist/server/setup-conversions.d.cts.map +1 -0
  72. package/dist/server/setup-conversions.d.mts +97 -0
  73. package/dist/server/setup-conversions.d.mts.map +1 -0
  74. package/dist/server/setup-conversions.mjs +60 -0
  75. package/dist/server/setup-conversions.mjs.map +1 -0
  76. package/dist/third-parties/index.d.cts +3 -3
  77. package/dist/third-parties/index.d.mts +3 -3
  78. package/dist/third-parties/integration.cjs +13 -6
  79. package/dist/third-parties/integration.cjs.map +1 -1
  80. package/dist/third-parties/integration.d.cts +12 -8
  81. package/dist/third-parties/integration.d.cts.map +1 -1
  82. package/dist/third-parties/integration.d.mts +12 -8
  83. package/dist/third-parties/integration.d.mts.map +1 -1
  84. package/dist/third-parties/integration.mjs +13 -7
  85. package/dist/third-parties/integration.mjs.map +1 -1
  86. package/dist/third-parties/linkedin-insight-tag.cjs +0 -4
  87. package/dist/third-parties/linkedin-insight-tag.cjs.map +1 -1
  88. package/dist/third-parties/linkedin-insight-tag.d.cts +4 -2
  89. package/dist/third-parties/linkedin-insight-tag.d.cts.map +1 -1
  90. package/dist/third-parties/linkedin-insight-tag.d.mts +4 -2
  91. package/dist/third-parties/linkedin-insight-tag.d.mts.map +1 -1
  92. package/dist/third-parties/linkedin-insight-tag.mjs +0 -4
  93. package/dist/third-parties/linkedin-insight-tag.mjs.map +1 -1
  94. package/dist/third-parties/meta-pixel.cjs +1 -3
  95. package/dist/third-parties/meta-pixel.cjs.map +1 -1
  96. package/dist/third-parties/meta-pixel.d.cts +4 -2
  97. package/dist/third-parties/meta-pixel.d.cts.map +1 -1
  98. package/dist/third-parties/meta-pixel.d.mts +4 -2
  99. package/dist/third-parties/meta-pixel.d.mts.map +1 -1
  100. package/dist/third-parties/meta-pixel.mjs +3 -5
  101. package/dist/third-parties/meta-pixel.mjs.map +1 -1
  102. package/dist/third-parties/microsoft-uet.cjs +7 -2
  103. package/dist/third-parties/microsoft-uet.cjs.map +1 -1
  104. package/dist/third-parties/microsoft-uet.d.cts +10 -3
  105. package/dist/third-parties/microsoft-uet.d.cts.map +1 -1
  106. package/dist/third-parties/microsoft-uet.d.mts +10 -3
  107. package/dist/third-parties/microsoft-uet.d.mts.map +1 -1
  108. package/dist/third-parties/microsoft-uet.mjs +8 -4
  109. package/dist/third-parties/microsoft-uet.mjs.map +1 -1
  110. package/dist/third-parties/openai-pixel.cjs +1 -3
  111. package/dist/third-parties/openai-pixel.cjs.map +1 -1
  112. package/dist/third-parties/openai-pixel.d.cts +4 -2
  113. package/dist/third-parties/openai-pixel.d.cts.map +1 -1
  114. package/dist/third-parties/openai-pixel.d.mts +4 -2
  115. package/dist/third-parties/openai-pixel.d.mts.map +1 -1
  116. package/dist/third-parties/openai-pixel.mjs +3 -5
  117. package/dist/third-parties/openai-pixel.mjs.map +1 -1
  118. package/dist/third-parties/reddit-pixel.cjs +1 -3
  119. package/dist/third-parties/reddit-pixel.cjs.map +1 -1
  120. package/dist/third-parties/reddit-pixel.d.cts +4 -2
  121. package/dist/third-parties/reddit-pixel.d.cts.map +1 -1
  122. package/dist/third-parties/reddit-pixel.d.mts +4 -2
  123. package/dist/third-parties/reddit-pixel.d.mts.map +1 -1
  124. package/dist/third-parties/reddit-pixel.mjs +3 -5
  125. package/dist/third-parties/reddit-pixel.mjs.map +1 -1
  126. package/dist/track/fbq.cjs +5 -0
  127. package/dist/track/fbq.cjs.map +1 -1
  128. package/dist/track/fbq.d.cts +2 -0
  129. package/dist/track/fbq.d.cts.map +1 -1
  130. package/dist/track/fbq.d.mts +2 -0
  131. package/dist/track/fbq.d.mts.map +1 -1
  132. package/dist/track/fbq.mjs +5 -1
  133. package/dist/track/fbq.mjs.map +1 -1
  134. package/dist/track/oaiq.cjs +5 -0
  135. package/dist/track/oaiq.cjs.map +1 -1
  136. package/dist/track/oaiq.d.cts +2 -0
  137. package/dist/track/oaiq.d.cts.map +1 -1
  138. package/dist/track/oaiq.d.mts +2 -0
  139. package/dist/track/oaiq.d.mts.map +1 -1
  140. package/dist/track/oaiq.mjs +5 -1
  141. package/dist/track/oaiq.mjs.map +1 -1
  142. package/dist/track/rdt.cjs +5 -0
  143. package/dist/track/rdt.cjs.map +1 -1
  144. package/dist/track/rdt.d.cts +2 -0
  145. package/dist/track/rdt.d.cts.map +1 -1
  146. package/dist/track/rdt.d.mts +2 -0
  147. package/dist/track/rdt.d.mts.map +1 -1
  148. package/dist/track/rdt.mjs +5 -1
  149. package/dist/track/rdt.mjs.map +1 -1
  150. package/package.json +1 -16
  151. package/dist/server/legacy.cjs +0 -3
  152. package/dist/server/legacy.d.cts +0 -2
  153. package/dist/server/legacy.d.mts +0 -2
  154. package/dist/server/legacy.mjs +0 -1
  155. package/dist/server/meta-conversions-api.cjs +0 -205
  156. package/dist/server/meta-conversions-api.cjs.map +0 -1
  157. package/dist/server/meta-conversions-api.d.cts +0 -8
  158. package/dist/server/meta-conversions-api.d.cts.map +0 -1
  159. package/dist/server/meta-conversions-api.d.mts +0 -8
  160. package/dist/server/meta-conversions-api.d.mts.map +0 -1
  161. package/dist/server/meta-conversions-api.mjs +0 -201
  162. package/dist/server/meta-conversions-api.mjs.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { getFirst } from "../utils/field.mjs";
2
- import { adsTracker } from "./integration.mjs";
3
- import { mapFBEvent } from "../track/fbq.mjs";
2
+ import { adEvents, adsTracker } from "./integration.mjs";
3
+ import { isStandardFBEvent, mapFBEvent } from "../track/fbq.mjs";
4
4
  // src/third-parties/meta-pixel.ts
5
5
  const metrics = [
6
6
  "CLS",
@@ -43,12 +43,10 @@ function setFBUser(pixelId) {
43
43
  });
44
44
  };
45
45
  }
46
- /** Meta Pixel: the events `mapFBEvent` maps to a Meta standard event, and `customEvents`. */
47
46
  function metaAds(options) {
48
- const isStandard = (name) => mapFBEvent(name)[0] === "track";
49
47
  return {
50
48
  type: "ads",
51
- track: adsTracker(sendFBEvent, isStandard, options.customEvents ?? []),
49
+ track: adsTracker(sendFBEvent, adEvents(isStandardFBEvent, options.customEvents)),
52
50
  setUser: setFBUser(options.pixelId),
53
51
  script: {
54
52
  id: "meta-pixel",
@@ -1 +1 @@
1
- {"version":3,"file":"meta-pixel.mjs","names":[],"sources":["../../src/third-parties/meta-pixel.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport { type FBQ, type PixelId, mapFBEvent } from '../track/fbq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\nimport { type AdsOptions, type Integration, adsTracker } from './integration';\n\ndeclare global {\n interface Window {\n /** Undefined until the Meta Pixel script has loaded. */\n fbq?: FBQ['fbq'];\n }\n}\n\nconst metrics = ['CLS', 'FCP', 'FID', 'INP', 'LCP', 'TTFB'];\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return false;\n }\n if (metrics.includes(name)) return;\n if (window.location.host.includes('127.0.0.1')) return;\n if (window.location.host.includes('localhost')) return;\n\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n // The two branches are identical on purpose. `fbq` is overloaded per `type` — 'track' takes a\n // standard event name with its typed properties, 'trackCustom' an arbitrary string — and what\n // `mapFBEvent` returns is a union of both shapes. Narrowing `type` is what picks a single\n // overload; collapsing the branches leaves the call matching none of them.\n if (type === 'track') {\n window.fbq(type, fbEventName, fbEventProperties, options);\n } else {\n window.fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function setFBUser(pixelId: PixelId) {\n return ({ user_id, user_data }: UpdateVisitorDTO) => {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n\n const address = getFirst(user_data?.address);\n\n window.fbq('init', pixelId, {\n em: getFirst(user_data?.email),\n fn: address?.first_name,\n ln: address?.last_name,\n ph: getFirst(user_data?.phone_number),\n external_id: user_id,\n ct: address?.city,\n // `st` is Meta's state/province field, not the street address.\n st: address?.region,\n zp: address?.postal_code,\n country: address?.country,\n });\n };\n}\n\n/** Meta Pixel: the events `mapFBEvent` maps to a Meta standard event, and `customEvents`. */\nexport function metaAds(options: { pixelId: PixelId } & AdsOptions): Integration {\n const isStandard = (name: string) => mapFBEvent(name as TrackName)[0] === 'track';\n return {\n type: 'ads',\n track: adsTracker(sendFBEvent, isStandard, options.customEvents ?? []),\n setUser: setFBUser(options.pixelId),\n script: {\n id: 'meta-pixel',\n inline: `\n !(function (f, b, e, v, n, t, s) {\n if (f.fbq) return;\n n = f.fbq = function () {\n n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);\n };\n if (!f._fbq) f._fbq = n;\n n.push = n;\n n.loaded = !0;\n n.version = '2.0';\n n.queue = [];\n t = b.createElement(e);\n t.async = !0;\n t.src = v;\n s = b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t, s);\n })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', ${JSON.stringify(options.pixelId)});\n fbq('track', 'PageView');\n `,\n },\n };\n}\n"],"mappings":";;;;AAaA,MAAM,UAAU;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;AAAM;AAE1D,SAAgB,YACd,MACA,YACA,UACA;CACA,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;EAChD,QAAQ,KAAK,8BAA8B;EAC3C,OAAO;CACT;CACA,IAAI,QAAQ,SAAS,IAAI,GAAG;CAC5B,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAChD,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAEhD,MAAM,UAAU,EAAE,SAAS,SAAS;CACpC,MAAM,CAAC,MAAM,aAAa,qBAAqB,WAAW,MAAM,UAAU;CAK1E,IAAI,SAAS,SACX,OAAO,IAAI,MAAM,aAAa,mBAAmB,OAAO;MAExD,OAAO,IAAI,MAAM,aAAa,mBAAmB,OAAO;AAE5D;AAEA,SAAgB,UAAU,SAAkB;CAC1C,QAAQ,EAAE,SAAS,gBAAkC;EACnD,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;GAChD,QAAQ,KAAK,8BAA8B;GAC3C;EACF;EAEA,MAAM,UAAU,SAAS,WAAW,OAAO;EAE3C,OAAO,IAAI,QAAQ,SAAS;GAC1B,IAAI,SAAS,WAAW,KAAK;GAC7B,IAAI,SAAS;GACb,IAAI,SAAS;GACb,IAAI,SAAS,WAAW,YAAY;GACpC,aAAa;GACb,IAAI,SAAS;GAEb,IAAI,SAAS;GACb,IAAI,SAAS;GACb,SAAS,SAAS;EACpB,CAAC;CACH;AACF;;AAGA,SAAgB,QAAQ,SAAyD;CAC/E,MAAM,cAAc,SAAiB,WAAW,IAAiB,CAAC,CAAC,OAAO;CAC1E,OAAO;EACL,MAAM;EACN,OAAO,WAAW,aAAa,YAAY,QAAQ,gBAAgB,CAAC,CAAC;EACrE,SAAS,UAAU,QAAQ,OAAO;EAClC,QAAQ;GACN,IAAI;GACJ,QAAQ;;;;;;;;;;;;;;;;;sBAiBQ,KAAK,UAAU,QAAQ,OAAO,EAAE;;;EAGlD;CACF;AACF"}
1
+ {"version":3,"file":"meta-pixel.mjs","names":[],"sources":["../../src/third-parties/meta-pixel.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport { type FBQ, type PixelId, isStandardFBEvent, mapFBEvent } from '../track/fbq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\nimport { type AdsOptions, type Integration, adEvents, adsTracker } from './integration';\n\ndeclare global {\n interface Window {\n /** Undefined until the Meta Pixel script has loaded. */\n fbq?: FBQ['fbq'];\n }\n}\n\nconst metrics = ['CLS', 'FCP', 'FID', 'INP', 'LCP', 'TTFB'];\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return false;\n }\n if (metrics.includes(name)) return;\n if (window.location.host.includes('127.0.0.1')) return;\n if (window.location.host.includes('localhost')) return;\n\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n // The two branches are identical on purpose. `fbq` is overloaded per `type` — 'track' takes a\n // standard event name with its typed properties, 'trackCustom' an arbitrary string — and what\n // `mapFBEvent` returns is a union of both shapes. Narrowing `type` is what picks a single\n // overload; collapsing the branches leaves the call matching none of them.\n if (type === 'track') {\n window.fbq(type, fbEventName, fbEventProperties, options);\n } else {\n window.fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function setFBUser(pixelId: PixelId) {\n return ({ user_id, user_data }: UpdateVisitorDTO) => {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n\n const address = getFirst(user_data?.address);\n\n window.fbq('init', pixelId, {\n em: getFirst(user_data?.email),\n fn: address?.first_name,\n ln: address?.last_name,\n ph: getFirst(user_data?.phone_number),\n external_id: user_id,\n ct: address?.city,\n // `st` is Meta's state/province field, not the street address.\n st: address?.region,\n zp: address?.postal_code,\n country: address?.country,\n });\n };\n}\n\n/** Meta Pixel: the events `mapFBEvent` maps to a Meta standard event, and `customEvents`. */\n/** Meta's configuration, shared by `metaAds` in the browser and `metaConversions` on the server. */\nexport interface MetaAdsOptions extends AdsOptions {\n pixelId: PixelId;\n}\n\nexport function metaAds(options: MetaAdsOptions): Integration {\n return {\n type: 'ads',\n track: adsTracker(sendFBEvent, adEvents(isStandardFBEvent, options.customEvents)),\n setUser: setFBUser(options.pixelId),\n script: {\n id: 'meta-pixel',\n inline: `\n !(function (f, b, e, v, n, t, s) {\n if (f.fbq) return;\n n = f.fbq = function () {\n n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);\n };\n if (!f._fbq) f._fbq = n;\n n.push = n;\n n.loaded = !0;\n n.version = '2.0';\n n.queue = [];\n t = b.createElement(e);\n t.async = !0;\n t.src = v;\n s = b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t, s);\n })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', ${JSON.stringify(options.pixelId)});\n fbq('track', 'PageView');\n `,\n },\n };\n}\n"],"mappings":";;;;AAaA,MAAM,UAAU;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;AAAM;AAE1D,SAAgB,YACd,MACA,YACA,UACA;CACA,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;EAChD,QAAQ,KAAK,8BAA8B;EAC3C,OAAO;CACT;CACA,IAAI,QAAQ,SAAS,IAAI,GAAG;CAC5B,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAChD,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAEhD,MAAM,UAAU,EAAE,SAAS,SAAS;CACpC,MAAM,CAAC,MAAM,aAAa,qBAAqB,WAAW,MAAM,UAAU;CAK1E,IAAI,SAAS,SACX,OAAO,IAAI,MAAM,aAAa,mBAAmB,OAAO;MAExD,OAAO,IAAI,MAAM,aAAa,mBAAmB,OAAO;AAE5D;AAEA,SAAgB,UAAU,SAAkB;CAC1C,QAAQ,EAAE,SAAS,gBAAkC;EACnD,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;GAChD,QAAQ,KAAK,8BAA8B;GAC3C;EACF;EAEA,MAAM,UAAU,SAAS,WAAW,OAAO;EAE3C,OAAO,IAAI,QAAQ,SAAS;GAC1B,IAAI,SAAS,WAAW,KAAK;GAC7B,IAAI,SAAS;GACb,IAAI,SAAS;GACb,IAAI,SAAS,WAAW,YAAY;GACpC,aAAa;GACb,IAAI,SAAS;GAEb,IAAI,SAAS;GACb,IAAI,SAAS;GACb,SAAS,SAAS;EACpB,CAAC;CACH;AACF;AAQA,SAAgB,QAAQ,SAAsC;CAC5D,OAAO;EACL,MAAM;EACN,OAAO,WAAW,aAAa,SAAS,mBAAmB,QAAQ,YAAY,CAAC;EAChF,SAAS,UAAU,QAAQ,OAAO;EAClC,QAAQ;GACN,IAAI;GACJ,QAAQ;;;;;;;;;;;;;;;;;sBAiBQ,KAAK,UAAU,QAAQ,OAAO,EAAE;;;EAGlD;CACF;AACF"}
@@ -147,13 +147,17 @@ function uetCustomerIdOf(integrations = []) {
147
147
  * loads itself), the consent mode default pushed inside it so bat.js reads it before the first
148
148
  * page load.
149
149
  */
150
- function microsoftAds(options) {
150
+ /** The events UET receives: `events` (the GA4 conversion events by default) and `customEvents`. */
151
+ function uetEvents(options) {
151
152
  const events = options.events ?? require_third_parties_integration.CONVERSION_EVENTS;
153
+ return require_third_parties_integration.adEvents((name) => events.includes(name), options.customEvents);
154
+ }
155
+ function microsoftAds(options) {
152
156
  const consent = options.consent ?? { ad_storage: "granted" };
153
157
  const defaults = consent ? `w[u].push("consent", "default", ${JSON.stringify(consent)});` : "";
154
158
  return {
155
159
  type: "ads",
156
- track: require_third_parties_integration.adsTracker(sendUETEvent, (name) => events.includes(name), options.customEvents ?? []),
160
+ track: require_third_parties_integration.adsTracker(sendUETEvent, uetEvents(options)),
157
161
  setUser: setUETUser,
158
162
  script: {
159
163
  id: "uet-tag",
@@ -188,5 +192,6 @@ exports.setUETConsent = setUETConsent;
188
192
  exports.setUETUser = setUETUser;
189
193
  exports.syncUETVisitor = syncUETVisitor;
190
194
  exports.uetCustomerIdOf = uetCustomerIdOf;
195
+ exports.uetEvents = uetEvents;
191
196
 
192
197
  //# sourceMappingURL=microsoft-uet.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"microsoft-uet.cjs","names":["mapUETEvent","getFirst","visitorId","CONVERSION_EVENTS","adsTracker"],"sources":["../../src/third-parties/microsoft-uet.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { type UETConsent, type UETQ, mapUETEvent } from '../track/uetq';\nimport { getFirst } from '../utils/field';\nimport { sha256 } from '../utils/sha256';\nimport { visitorId } from '../visitor/id';\nimport { type AdsOptions, CONVERSION_EVENTS, type Integration, adsTracker } from './integration';\n\ndeclare global {\n interface Window {\n /**\n * Defined by the UET snippet before `bat.js` loads (as a plain array), so pushes made early\n * are queued rather than lost. Undefined only where the snippet was never installed.\n */\n uetq?: UETQ;\n }\n}\n\nconst metrics = ['CLS', 'FCP', 'FID', 'INP', 'LCP', 'TTFB'];\n\n/** Drop `undefined` fields: bat.js validates every key it receives, and `undefined` is a value. */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction clean(value: unknown): any {\n return JSON.parse(JSON.stringify(value));\n}\n\nfunction isLocal(): boolean {\n return window.location.host.includes('127.0.0.1') || window.location.host.includes('localhost');\n}\n\n/**\n * Forward an internal track event to the Microsoft Advertising UET tag.\n *\n * `eventId` is reused as UET's `event_id` so the browser event deduplicates against the same\n * conversion sent through the Conversions API (`sendMicrosoftEvents`). The action name is the\n * internal name on both channels — see `mapUETEvent`.\n *\n * `page_view` is not forwarded: bat.js turns that action into its page-load beacon, which the\n * snippet already fires on load and, with `enableAutoSpaTracking: true` (the setting in\n * Microsoft's generated snippet), on every history change — forwarding the SDK's own page views\n * would report each page twice. The tag owns page loads; this tracker owns everything else.\n */\nexport function sendUETEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.uetq) {\n console.warn('uetq has not been initialized');\n return false;\n }\n if (metrics.includes(name) || name === 'page_view') return;\n if (isLocal()) return;\n\n const [action, params] = mapUETEvent(name, properties, eventId);\n window.uetq.push('event', action, clean(params));\n}\n\n/**\n * Enhanced conversions: hand the tag the visitor's email and phone so Microsoft can match a\n * conversion to an ad click without a third-party cookie. A `set` applies to every event fired\n * from the page afterwards, `pageLoad` included, and the tag fires a `pid` beacon on its own\n * when the page load already went out. Values are sent raw — the tag normalizes and SHA-256\n * hashes them in the browser (bat.js `validatePid`) before anything leaves the page.\n *\n * A setter itself, like `setGAUser`, rather than a factory like `setFBUser(pixelId)`: UET is\n * bound to its tag by the snippet and `set` addresses whichever tag drains `uetq`, so there is\n * nothing to bind first.\n */\nexport function setUETUser({ user_id, user_data }: UpdateVisitorDTO) {\n if (typeof window === 'undefined' || !window.uetq) {\n console.warn('uetq has not been initialized');\n return;\n }\n\n // A signed-in user is also the moment the ID Sync pixel can carry a `UID` — see `syncUETVisitor`.\n if (user_id) void syncUETVisitor(user_id);\n\n const em = getFirst(user_data?.email);\n const ph = getFirst(user_data?.phone_number);\n if (!em && !ph) return;\n\n window.uetq.push('set', { pid: clean({ em, ph }) });\n}\n\n/**\n * UET consent mode. Push `default` before the tag loads (the tag processes `consent` early, ahead\n * of the queued events) and `update` when the visitor decides. With `ad_storage: 'denied'` the\n * tag neither writes its cookies nor reads the `msclkid` from the URL.\n * https://help.ads.microsoft.com/#apex/ads/en/60119/1\n */\nexport function setUETConsent(mode: 'default' | 'update', consent: UETConsent) {\n if (typeof window === 'undefined') return;\n window.uetq ??= [] as unknown as UETQ;\n window.uetq.push('consent', mode, consent);\n}\n\n/**\n * The Conversions API's client-side ID Sync pixel: ties the visitor id sent server-side as\n * `anonymousId` to Microsoft's own identifier, so server events can be attributed across\n * contexts (view-through, audiences). Microsoft requires it for remarketing built from CAPI\n * events and recommends it for measurement quality; fire it at least once per session, ideally\n * on the first page view. A pixel rather than a fetch on purpose: Microsoft must observe the\n * browser context of the sync, which a server-side call cannot carry.\n *\n * `customerId` is the Microsoft Advertising customer id (`cid` in the UI's URLs) — not the UET\n * tag id. `visitorId` is the SDK visitor id (`visitorId()`), which is what\n * `sendMicrosoftEvents` sends as `anonymousId`; Microsoft requires the two to be equal.\n * `userId` is the raw signed-in user id: it is SHA-256 hashed here, exactly as the server sender\n * hashes it into `externalId`, so the pair matches as well. Hashing is asynchronous, so the\n * pixel fires once the digest resolves; where SubtleCrypto is unavailable (an insecure context)\n * the pixel goes out without `UID` rather than with a raw id.\n * https://learn.microsoft.com/en-us/advertising/guides/uet-conversion-api-integration#id-sync-and-why-it-matters\n */\n/**\n * The Microsoft Advertising customer id the ID Sync pixel reports to, set once by the framework\n * `Analytics` component's `uetCustomerId` prop (or `configureUET`). Unset, nothing syncs.\n */\nlet uetCustomerId: string | undefined;\n\nexport function configureUET(options: { customerId?: string | number }) {\n uetCustomerId = options.customerId === undefined ? undefined : String(options.customerId);\n}\n\n/**\n * Sync the SDK visitor — the `anonymousId` of the events the server sends to the Conversions\n * API — with Microsoft, plus the user's `UID` when one is known. The `Analytics` components run\n * it on mount so every visit syncs at least once, anonymous visitors included (they are who\n * remarketing audiences are built from), and `setUETUser` runs it again on sign-in.\n */\nexport async function syncUETVisitor(userId?: string): Promise<void> {\n if (!uetCustomerId) return;\n sendUETIdSync({ customerId: uetCustomerId, visitorId: visitorId(), userId });\n}\n\nexport function sendUETIdSync(options: {\n customerId: string | number;\n visitorId: string;\n /** The signed-in user's id, raw; hashed before it leaves the page. */\n userId?: string;\n}) {\n if (typeof window === 'undefined' || typeof Image === 'undefined') return;\n if (isLocal()) return;\n\n const fire = (uid?: string) => {\n const params = new URLSearchParams({\n Red3: `BACID_${options.customerId}`,\n VID: options.visitorId,\n });\n if (uid) params.set('UID', uid);\n new Image().src = `https://c.bing.com/c.gif?${params.toString()}`;\n };\n\n if (!options.userId) {\n fire();\n return;\n }\n sha256(options.userId).then(fire, () => fire());\n}\n\n/** What `microsoftAds` returns: an integration that also names the customer id for ID Sync. */\nexport type MicrosoftAdsIntegration = Integration & { readonly uetCustomerId?: `${number}` };\n\n/** The customer id of the `microsoftAds` integration among these, for `useUETIdSync`. */\nexport function uetCustomerIdOf(integrations: readonly Integration[] = []) {\n return integrations.find(\n (integration): integration is MicrosoftAdsIntegration => 'uetCustomerId' in integration\n )?.uetCustomerId;\n}\n\n/**\n * Microsoft Advertising UET. UET has no standard events to map to — a conversion goal is defined\n * on an action name in the ads UI — so it receives an explicit list, the GA4 conversion events\n * by default (`CONVERSION_EVENTS`), plus `customEvents`.\n *\n * Its script is Microsoft's UET snippet with `enableAutoSpaTracking: true` (the tag reports page\n * loads itself), the consent mode default pushed inside it so bat.js reads it before the first\n * page load.\n */\nexport function microsoftAds(\n options: {\n tagId: `${number}`;\n /** Microsoft Advertising customer id (`cid` in the ads UI's URLs): enables the ID Sync pixel. */\n customerId?: `${number}`;\n /**\n * The UET consent mode default, `ad_storage: granted` unless given: how the tag behaves\n * without a signal, so Microsoft stops flagging EEA/UK/CH events as missing consent. Sites\n * with a consent banner pass `{ ad_storage: 'denied' }` and send `update` with\n * `setUETConsent`; `false` pushes no default. https://help.ads.microsoft.com/#apex/ads/en/60119/1\n */\n consent?: UETConsent | false;\n events?: readonly EventName[];\n } & AdsOptions\n): MicrosoftAdsIntegration {\n const events: readonly string[] = options.events ?? CONVERSION_EVENTS;\n const consent = options.consent ?? { ad_storage: 'granted' };\n const defaults = consent ? `w[u].push(\"consent\", \"default\", ${JSON.stringify(consent)});` : '';\n return {\n type: 'ads',\n track: adsTracker(sendUETEvent, (name) => events.includes(name), options.customEvents ?? []),\n setUser: setUETUser,\n script: {\n id: 'uet-tag',\n inline: `\n (function (w, d, t, u, o) {\n w[u] = w[u] || [], o.ts = (new Date).getTime();\n ${defaults}\n var n = d.createElement(t);\n n.src = \"https://bat.bing.net/bat.js?ti=\" + o.ti + (\"uetq\" != u ? \"&q=\" + u : \"\"),\n n.async = 1, n.onload = n.onreadystatechange = function() {\n var s = this.readyState;\n s && \"loaded\" !== s && \"complete\" !== s ||\n (o.q = w[u], w[u] = new UET(o), w[u].push(\"pageLoad\"),\n n.onload = n.onreadystatechange = null)\n };\n var i = d.getElementsByTagName(t)[0];\n i.parentNode.insertBefore(n, i);\n })(window, document, \"script\", \"uetq\", {\n ti: ${JSON.stringify(options.tagId)},\n enableAutoSpaTracking: true\n });\n `,\n },\n uetCustomerId: options.customerId,\n };\n}\n"],"mappings":";;;;;;;AAkBA,MAAM,UAAU;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;AAAM;;AAI1D,SAAS,MAAM,OAA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AC,eAAe;CACpB,cAAc;EAAE,YAAY;EAAe,WAAWC,mBAAAA,UAAU;EAAG;CAAO,CAAC;AAC7E;AAEA,SAAgB,cAAc,SAK3B;CACD,IAAI,OAAO,WAAW,eAAe,OAAO,UAAU,aAAa;CACnE,IAAI,QAAQ,GAAG;CAEf,MAAM,QAAQ,QAAiB;EAC7B,MAAM,SAAS,IAAI,gBAAgB;GACjC,MAAM,SAAS,QAAQ;GACvB,KAAK,QAAQ;EACf,CAAC;EACD,IAAI,KAAK,OAAO,IAAI,OAAO,GAAG;EAC9B,IAAI,MAAM,CAAC,CAAC,MAAM,4BAA4B,OAAO,SAAS;CAChE;CAEA,IAAI,CAAC,QAAQ,QAAQ;EACnB,KAAK;EACL;CACF;CACA,qBAAA,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;AAChD;;AAMA,SAAgB,gBAAgB,eAAuC,CAAC,GAAG;CACzE,OAAO,aAAa,MACjB,gBAAwD,mBAAmB,WAC9E,CAAC,EAAE;AACL;;;;;;;;;;AAWA,SAAgB,aACd,SAayB;CACzB,MAAM,SAA4B,QAAQ,UAAUC,kCAAAA;CACpD,MAAM,UAAU,QAAQ,WAAW,EAAE,YAAY,UAAU;CAC3D,MAAM,WAAW,UAAU,mCAAmC,KAAK,UAAU,OAAO,EAAE,MAAM;CAC5F,OAAO;EACL,MAAM;EACN,OAAOC,kCAAAA,WAAW,eAAe,SAAS,OAAO,SAAS,IAAI,GAAG,QAAQ,gBAAgB,CAAC,CAAC;EAC3F,SAAS;EACT,QAAQ;GACN,IAAI;GACJ,QAAQ;;;YAGF,SAAS;;;;;;;;;;;;gBAYL,KAAK,UAAU,QAAQ,KAAK,EAAE;;;;EAI1C;EACA,eAAe,QAAQ;CACzB;AACF"}
1
+ {"version":3,"file":"microsoft-uet.cjs","names":["mapUETEvent","getFirst","visitorId","CONVERSION_EVENTS","adEvents","adsTracker"],"sources":["../../src/third-parties/microsoft-uet.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { type UETConsent, type UETQ, mapUETEvent } from '../track/uetq';\nimport { getFirst } from '../utils/field';\nimport { sha256 } from '../utils/sha256';\nimport { visitorId } from '../visitor/id';\nimport {\n type AdsOptions,\n CONVERSION_EVENTS,\n type Integration,\n adEvents,\n adsTracker,\n} from './integration';\n\ndeclare global {\n interface Window {\n /**\n * Defined by the UET snippet before `bat.js` loads (as a plain array), so pushes made early\n * are queued rather than lost. Undefined only where the snippet was never installed.\n */\n uetq?: UETQ;\n }\n}\n\nconst metrics = ['CLS', 'FCP', 'FID', 'INP', 'LCP', 'TTFB'];\n\n/** Drop `undefined` fields: bat.js validates every key it receives, and `undefined` is a value. */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction clean(value: unknown): any {\n return JSON.parse(JSON.stringify(value));\n}\n\nfunction isLocal(): boolean {\n return window.location.host.includes('127.0.0.1') || window.location.host.includes('localhost');\n}\n\n/**\n * Forward an internal track event to the Microsoft Advertising UET tag.\n *\n * `eventId` is reused as UET's `event_id` so the browser event deduplicates against the same\n * conversion sent through the Conversions API (`sendMicrosoftEvents`). The action name is the\n * internal name on both channels — see `mapUETEvent`.\n *\n * `page_view` is not forwarded: bat.js turns that action into its page-load beacon, which the\n * snippet already fires on load and, with `enableAutoSpaTracking: true` (the setting in\n * Microsoft's generated snippet), on every history change — forwarding the SDK's own page views\n * would report each page twice. The tag owns page loads; this tracker owns everything else.\n */\nexport function sendUETEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.uetq) {\n console.warn('uetq has not been initialized');\n return false;\n }\n if (metrics.includes(name) || name === 'page_view') return;\n if (isLocal()) return;\n\n const [action, params] = mapUETEvent(name, properties, eventId);\n window.uetq.push('event', action, clean(params));\n}\n\n/**\n * Enhanced conversions: hand the tag the visitor's email and phone so Microsoft can match a\n * conversion to an ad click without a third-party cookie. A `set` applies to every event fired\n * from the page afterwards, `pageLoad` included, and the tag fires a `pid` beacon on its own\n * when the page load already went out. Values are sent raw — the tag normalizes and SHA-256\n * hashes them in the browser (bat.js `validatePid`) before anything leaves the page.\n *\n * A setter itself, like `setGAUser`, rather than a factory like `setFBUser(pixelId)`: UET is\n * bound to its tag by the snippet and `set` addresses whichever tag drains `uetq`, so there is\n * nothing to bind first.\n */\nexport function setUETUser({ user_id, user_data }: UpdateVisitorDTO) {\n if (typeof window === 'undefined' || !window.uetq) {\n console.warn('uetq has not been initialized');\n return;\n }\n\n // A signed-in user is also the moment the ID Sync pixel can carry a `UID` — see `syncUETVisitor`.\n if (user_id) void syncUETVisitor(user_id);\n\n const em = getFirst(user_data?.email);\n const ph = getFirst(user_data?.phone_number);\n if (!em && !ph) return;\n\n window.uetq.push('set', { pid: clean({ em, ph }) });\n}\n\n/**\n * UET consent mode. Push `default` before the tag loads (the tag processes `consent` early, ahead\n * of the queued events) and `update` when the visitor decides. With `ad_storage: 'denied'` the\n * tag neither writes its cookies nor reads the `msclkid` from the URL.\n * https://help.ads.microsoft.com/#apex/ads/en/60119/1\n */\nexport function setUETConsent(mode: 'default' | 'update', consent: UETConsent) {\n if (typeof window === 'undefined') return;\n window.uetq ??= [] as unknown as UETQ;\n window.uetq.push('consent', mode, consent);\n}\n\n/**\n * The Conversions API's client-side ID Sync pixel: ties the visitor id sent server-side as\n * `anonymousId` to Microsoft's own identifier, so server events can be attributed across\n * contexts (view-through, audiences). Microsoft requires it for remarketing built from CAPI\n * events and recommends it for measurement quality; fire it at least once per session, ideally\n * on the first page view. A pixel rather than a fetch on purpose: Microsoft must observe the\n * browser context of the sync, which a server-side call cannot carry.\n *\n * `customerId` is the Microsoft Advertising customer id (`cid` in the UI's URLs) — not the UET\n * tag id. `visitorId` is the SDK visitor id (`visitorId()`), which is what\n * `sendMicrosoftEvents` sends as `anonymousId`; Microsoft requires the two to be equal.\n * `userId` is the raw signed-in user id: it is SHA-256 hashed here, exactly as the server sender\n * hashes it into `externalId`, so the pair matches as well. Hashing is asynchronous, so the\n * pixel fires once the digest resolves; where SubtleCrypto is unavailable (an insecure context)\n * the pixel goes out without `UID` rather than with a raw id.\n * https://learn.microsoft.com/en-us/advertising/guides/uet-conversion-api-integration#id-sync-and-why-it-matters\n */\n/**\n * The Microsoft Advertising customer id the ID Sync pixel reports to, set once by the framework\n * `Analytics` component's `uetCustomerId` prop (or `configureUET`). Unset, nothing syncs.\n */\nlet uetCustomerId: string | undefined;\n\nexport function configureUET(options: { customerId?: string | number }) {\n uetCustomerId = options.customerId === undefined ? undefined : String(options.customerId);\n}\n\n/**\n * Sync the SDK visitor — the `anonymousId` of the events the server sends to the Conversions\n * API — with Microsoft, plus the user's `UID` when one is known. The `Analytics` components run\n * it on mount so every visit syncs at least once, anonymous visitors included (they are who\n * remarketing audiences are built from), and `setUETUser` runs it again on sign-in.\n */\nexport async function syncUETVisitor(userId?: string): Promise<void> {\n if (!uetCustomerId) return;\n sendUETIdSync({ customerId: uetCustomerId, visitorId: visitorId(), userId });\n}\n\nexport function sendUETIdSync(options: {\n customerId: string | number;\n visitorId: string;\n /** The signed-in user's id, raw; hashed before it leaves the page. */\n userId?: string;\n}) {\n if (typeof window === 'undefined' || typeof Image === 'undefined') return;\n if (isLocal()) return;\n\n const fire = (uid?: string) => {\n const params = new URLSearchParams({\n Red3: `BACID_${options.customerId}`,\n VID: options.visitorId,\n });\n if (uid) params.set('UID', uid);\n new Image().src = `https://c.bing.com/c.gif?${params.toString()}`;\n };\n\n if (!options.userId) {\n fire();\n return;\n }\n sha256(options.userId).then(fire, () => fire());\n}\n\n/** What `microsoftAds` returns: an integration that also names the customer id for ID Sync. */\nexport type MicrosoftAdsIntegration = Integration & { readonly uetCustomerId?: `${number}` };\n\n/** The customer id of the `microsoftAds` integration among these, for `useUETIdSync`. */\nexport function uetCustomerIdOf(integrations: readonly Integration[] = []) {\n return integrations.find(\n (integration): integration is MicrosoftAdsIntegration => 'uetCustomerId' in integration\n )?.uetCustomerId;\n}\n\n/**\n * Microsoft Advertising UET. UET has no standard events to map to — a conversion goal is defined\n * on an action name in the ads UI — so it receives an explicit list, the GA4 conversion events\n * by default (`CONVERSION_EVENTS`), plus `customEvents`.\n *\n * Its script is Microsoft's UET snippet with `enableAutoSpaTracking: true` (the tag reports page\n * loads itself), the consent mode default pushed inside it so bat.js reads it before the first\n * page load.\n */\n/** The events UET receives: `events` (the GA4 conversion events by default) and `customEvents`. */\nexport function uetEvents(options: Pick<MicrosoftAdsOptions, 'events' | 'customEvents'>) {\n const events: readonly string[] = options.events ?? CONVERSION_EVENTS;\n return adEvents((name) => events.includes(name), options.customEvents);\n}\n\n/**\n * Microsoft's configuration, shared by `microsoftAds` and `microsoftConversions` on the server.\n */\nexport interface MicrosoftAdsOptions extends AdsOptions {\n tagId: `${number}`;\n /** Microsoft Advertising customer id (`cid` in the ads UI's URLs): enables the ID Sync pixel. */\n customerId?: `${number}`;\n /**\n * The UET consent mode default, `ad_storage: granted` unless given: how the tag behaves\n * without a signal, so Microsoft stops flagging EEA/UK/CH events as missing consent. Sites\n * with a consent banner pass `{ ad_storage: 'denied' }` and send `update` with\n * `setUETConsent`; `false` pushes no default. https://help.ads.microsoft.com/#apex/ads/en/60119/1\n */\n consent?: UETConsent | false;\n /** The events UET receives, `CONVERSION_EVENTS` by default; names `track` accepts. */\n events?: readonly TrackName[];\n}\n\nexport function microsoftAds(options: MicrosoftAdsOptions): MicrosoftAdsIntegration {\n const consent = options.consent ?? { ad_storage: 'granted' };\n const defaults = consent ? `w[u].push(\"consent\", \"default\", ${JSON.stringify(consent)});` : '';\n return {\n type: 'ads',\n track: adsTracker(sendUETEvent, uetEvents(options)),\n setUser: setUETUser,\n script: {\n id: 'uet-tag',\n inline: `\n (function (w, d, t, u, o) {\n w[u] = w[u] || [], o.ts = (new Date).getTime();\n ${defaults}\n var n = d.createElement(t);\n n.src = \"https://bat.bing.net/bat.js?ti=\" + o.ti + (\"uetq\" != u ? \"&q=\" + u : \"\"),\n n.async = 1, n.onload = n.onreadystatechange = function() {\n var s = this.readyState;\n s && \"loaded\" !== s && \"complete\" !== s ||\n (o.q = w[u], w[u] = new UET(o), w[u].push(\"pageLoad\"),\n n.onload = n.onreadystatechange = null)\n };\n var i = d.getElementsByTagName(t)[0];\n i.parentNode.insertBefore(n, i);\n })(window, document, \"script\", \"uetq\", {\n ti: ${JSON.stringify(options.tagId)},\n enableAutoSpaTracking: true\n });\n `,\n },\n uetCustomerId: options.customerId,\n };\n}\n"],"mappings":";;;;;;;AAwBA,MAAM,UAAU;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;AAAM;;AAI1D,SAAS,MAAM,OAAqB;CAClC,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AACzC;AAEA,SAAS,UAAmB;CAC1B,OAAO,OAAO,SAAS,KAAK,SAAS,WAAW,KAAK,OAAO,SAAS,KAAK,SAAS,WAAW;AAChG;;;;;;;;;;;;;AAcA,SAAgB,aACd,MACA,YACA,SACA;CACA,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;EACjD,QAAQ,KAAK,+BAA+B;EAC5C,OAAO;CACT;CACA,IAAI,QAAQ,SAAS,IAAI,KAAK,SAAS,aAAa;CACpD,IAAI,QAAQ,GAAG;CAEf,MAAM,CAAC,QAAQ,UAAUA,mBAAAA,YAAY,MAAM,YAAY,OAAO;CAC9D,OAAO,KAAK,KAAK,SAAS,QAAQ,MAAM,MAAM,CAAC;AACjD;;;;;;;;;;;;AAaA,SAAgB,WAAW,EAAE,SAAS,aAA+B;CACnE,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;EACjD,QAAQ,KAAK,+BAA+B;EAC5C;CACF;CAGA,IAAI,SAAS,eAAoB,OAAO;CAExC,MAAM,KAAKC,oBAAAA,SAAS,WAAW,KAAK;CACpC,MAAM,KAAKA,oBAAAA,SAAS,WAAW,YAAY;CAC3C,IAAI,CAAC,MAAM,CAAC,IAAI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BA,SAAgB,aAAa,SAAuD;CAClF,MAAM,UAAU,QAAQ,WAAW,EAAE,YAAY,UAAU;CAC3D,MAAM,WAAW,UAAU,mCAAmC,KAAK,UAAU,OAAO,EAAE,MAAM;CAC5F,OAAO;EACL,MAAM;EACN,OAAOC,kCAAAA,WAAW,cAAc,UAAU,OAAO,CAAC;EAClD,SAAS;EACT,QAAQ;GACN,IAAI;GACJ,QAAQ;;;YAGF,SAAS;;;;;;;;;;;;gBAYL,KAAK,UAAU,QAAQ,KAAK,EAAE;;;;EAI1C;EACA,eAAe,QAAQ;CACzB;AACF"}
@@ -74,7 +74,12 @@ export declare function uetCustomerIdOf(integrations?: readonly Integration[]):
74
74
  * loads itself), the consent mode default pushed inside it so bat.js reads it before the first
75
75
  * page load.
76
76
  */
77
- export declare function microsoftAds(options: {
77
+ /** The events UET receives: `events` (the GA4 conversion events by default) and `customEvents`. */
78
+ export declare function uetEvents(options: Pick<MicrosoftAdsOptions, 'events' | 'customEvents'>): (name: string) => boolean;
79
+ /**
80
+ * Microsoft's configuration, shared by `microsoftAds` and `microsoftConversions` on the server.
81
+ */
82
+ export interface MicrosoftAdsOptions extends AdsOptions {
78
83
  tagId: `${number}`;
79
84
  /** Microsoft Advertising customer id (`cid` in the ads UI's URLs): enables the ID Sync pixel. */
80
85
  customerId?: `${number}`;
@@ -85,6 +90,8 @@ export declare function microsoftAds(options: {
85
90
  * `setUETConsent`; `false` pushes no default. https://help.ads.microsoft.com/#apex/ads/en/60119/1
86
91
  */
87
92
  consent?: UETConsent | false;
88
- events?: readonly EventName[];
89
- } & AdsOptions): MicrosoftAdsIntegration;
93
+ /** The events UET receives, `CONVERSION_EVENTS` by default; names `track` accepts. */
94
+ events?: readonly TrackName[];
95
+ }
96
+ export declare function microsoftAds(options: MicrosoftAdsOptions): MicrosoftAdsIntegration;
90
97
  //# sourceMappingURL=microsoft-uet.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"microsoft-uet.d.cts","names":[],"sources":["../../src/third-parties/microsoft-uet.ts"],"mappings":";;;;QAQQ;YACI;;;;;IAKR,OAAO;;;;;;;;;;;;;;;wBA4BK,aAAa,UAAU,WACrC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;;;;;;;;;;;;wBAwBc,aAAa,SAAS,aAAa;;;;;;;wBAsBnC,cAAc,4BAA4B,SAAS;wBA6BnD,aAAa;EAAW;;;;;;;;wBAUlB,eAAe,kBAAkB;wBAKvC,cAAc;EAC5B;EACA;;EAEA;;;YAsBU,0BAA0B;WAAyB;;;wBAG/C,gBAAgB,wBAAuB;;;;;;;;;;wBAevC,aACd;EACE;;EAEA;;;;;;;EAOA,UAAU;EACV,kBAAkB;IAChB,aACH"}
1
+ {"version":3,"file":"microsoft-uet.d.cts","names":[],"sources":["../../src/third-parties/microsoft-uet.ts"],"mappings":";;;;QAcQ;YACI;;;;;IAKR,OAAO;;;;;;;;;;;;;;;wBA4BK,aAAa,UAAU,WACrC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;;;;;;;;;;;;wBAwBc,aAAa,SAAS,aAAa;;;;;;;wBAsBnC,cAAc,4BAA4B,SAAS;wBA6BnD,aAAa;EAAW;;;;;;;;wBAUlB,eAAe,kBAAkB;wBAKvC,cAAc;EAC5B;EACA;;EAEA;;;YAsBU,0BAA0B;WAAyB;;;wBAG/C,gBAAgB,wBAAuB;;;;;;;;;;;wBAgBvC,UAAU,SAAS,KAAK,mDAA+C;;;;iBAQtE,4BAA4B;EAC3C;;EAEA;;;;;;;EAOA,UAAU;;EAEV,kBAAkB;;wBAGJ,aAAa,SAAS,sBAAsB"}
@@ -74,7 +74,12 @@ export declare function uetCustomerIdOf(integrations?: readonly Integration[]):
74
74
  * loads itself), the consent mode default pushed inside it so bat.js reads it before the first
75
75
  * page load.
76
76
  */
77
- export declare function microsoftAds(options: {
77
+ /** The events UET receives: `events` (the GA4 conversion events by default) and `customEvents`. */
78
+ export declare function uetEvents(options: Pick<MicrosoftAdsOptions, 'events' | 'customEvents'>): (name: string) => boolean;
79
+ /**
80
+ * Microsoft's configuration, shared by `microsoftAds` and `microsoftConversions` on the server.
81
+ */
82
+ export interface MicrosoftAdsOptions extends AdsOptions {
78
83
  tagId: `${number}`;
79
84
  /** Microsoft Advertising customer id (`cid` in the ads UI's URLs): enables the ID Sync pixel. */
80
85
  customerId?: `${number}`;
@@ -85,6 +90,8 @@ export declare function microsoftAds(options: {
85
90
  * `setUETConsent`; `false` pushes no default. https://help.ads.microsoft.com/#apex/ads/en/60119/1
86
91
  */
87
92
  consent?: UETConsent | false;
88
- events?: readonly EventName[];
89
- } & AdsOptions): MicrosoftAdsIntegration;
93
+ /** The events UET receives, `CONVERSION_EVENTS` by default; names `track` accepts. */
94
+ events?: readonly TrackName[];
95
+ }
96
+ export declare function microsoftAds(options: MicrosoftAdsOptions): MicrosoftAdsIntegration;
90
97
  //# sourceMappingURL=microsoft-uet.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"microsoft-uet.d.mts","names":[],"sources":["../../src/third-parties/microsoft-uet.ts"],"mappings":";;;;QAQQ;YACI;;;;;IAKR,OAAO;;;;;;;;;;;;;;;wBA4BK,aAAa,UAAU,WACrC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;;;;;;;;;;;;wBAwBc,aAAa,SAAS,aAAa;;;;;;;wBAsBnC,cAAc,4BAA4B,SAAS;wBA6BnD,aAAa;EAAW;;;;;;;;wBAUlB,eAAe,kBAAkB;wBAKvC,cAAc;EAC5B;EACA;;EAEA;;;YAsBU,0BAA0B;WAAyB;;;wBAG/C,gBAAgB,wBAAuB;;;;;;;;;;wBAevC,aACd;EACE;;EAEA;;;;;;;EAOA,UAAU;EACV,kBAAkB;IAChB,aACH"}
1
+ {"version":3,"file":"microsoft-uet.d.mts","names":[],"sources":["../../src/third-parties/microsoft-uet.ts"],"mappings":";;;;QAcQ;YACI;;;;;IAKR,OAAO;;;;;;;;;;;;;;;wBA4BK,aAAa,UAAU,WACrC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;;;;;;;;;;;;wBAwBc,aAAa,SAAS,aAAa;;;;;;;wBAsBnC,cAAc,4BAA4B,SAAS;wBA6BnD,aAAa;EAAW;;;;;;;;wBAUlB,eAAe,kBAAkB;wBAKvC,cAAc;EAC5B;EACA;;EAEA;;;YAsBU,0BAA0B;WAAyB;;;wBAG/C,gBAAgB,wBAAuB;;;;;;;;;;;wBAgBvC,UAAU,SAAS,KAAK,mDAA+C;;;;iBAQtE,4BAA4B;EAC3C;;EAEA;;;;;;;EAOA,UAAU;;EAEV,kBAAkB;;wBAGJ,aAAa,SAAS,sBAAsB"}
@@ -2,7 +2,7 @@ import { visitorId } from "../visitor/id.mjs";
2
2
  import { mapUETEvent } from "../track/uetq.mjs";
3
3
  import { getFirst } from "../utils/field.mjs";
4
4
  import { sha256 } from "../utils/sha256.mjs";
5
- import { CONVERSION_EVENTS, adsTracker } from "./integration.mjs";
5
+ import { CONVERSION_EVENTS, adEvents, adsTracker } from "./integration.mjs";
6
6
  // src/third-parties/microsoft-uet.ts
7
7
  const metrics = [
8
8
  "CLS",
@@ -146,13 +146,17 @@ function uetCustomerIdOf(integrations = []) {
146
146
  * loads itself), the consent mode default pushed inside it so bat.js reads it before the first
147
147
  * page load.
148
148
  */
149
- function microsoftAds(options) {
149
+ /** The events UET receives: `events` (the GA4 conversion events by default) and `customEvents`. */
150
+ function uetEvents(options) {
150
151
  const events = options.events ?? CONVERSION_EVENTS;
152
+ return adEvents((name) => events.includes(name), options.customEvents);
153
+ }
154
+ function microsoftAds(options) {
151
155
  const consent = options.consent ?? { ad_storage: "granted" };
152
156
  const defaults = consent ? `w[u].push("consent", "default", ${JSON.stringify(consent)});` : "";
153
157
  return {
154
158
  type: "ads",
155
- track: adsTracker(sendUETEvent, (name) => events.includes(name), options.customEvents ?? []),
159
+ track: adsTracker(sendUETEvent, uetEvents(options)),
156
160
  setUser: setUETUser,
157
161
  script: {
158
162
  id: "uet-tag",
@@ -179,6 +183,6 @@ function microsoftAds(options) {
179
183
  uetCustomerId: options.customerId
180
184
  };
181
185
  }
182
- export { configureUET, microsoftAds, sendUETEvent, sendUETIdSync, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf };
186
+ export { configureUET, microsoftAds, sendUETEvent, sendUETIdSync, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf, uetEvents };
183
187
 
184
188
  //# sourceMappingURL=microsoft-uet.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"microsoft-uet.mjs","names":[],"sources":["../../src/third-parties/microsoft-uet.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { type UETConsent, type UETQ, mapUETEvent } from '../track/uetq';\nimport { getFirst } from '../utils/field';\nimport { sha256 } from '../utils/sha256';\nimport { visitorId } from '../visitor/id';\nimport { type AdsOptions, CONVERSION_EVENTS, type Integration, adsTracker } from './integration';\n\ndeclare global {\n interface Window {\n /**\n * Defined by the UET snippet before `bat.js` loads (as a plain array), so pushes made early\n * are queued rather than lost. Undefined only where the snippet was never installed.\n */\n uetq?: UETQ;\n }\n}\n\nconst metrics = ['CLS', 'FCP', 'FID', 'INP', 'LCP', 'TTFB'];\n\n/** Drop `undefined` fields: bat.js validates every key it receives, and `undefined` is a value. */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction clean(value: unknown): any {\n return JSON.parse(JSON.stringify(value));\n}\n\nfunction isLocal(): boolean {\n return window.location.host.includes('127.0.0.1') || window.location.host.includes('localhost');\n}\n\n/**\n * Forward an internal track event to the Microsoft Advertising UET tag.\n *\n * `eventId` is reused as UET's `event_id` so the browser event deduplicates against the same\n * conversion sent through the Conversions API (`sendMicrosoftEvents`). The action name is the\n * internal name on both channels — see `mapUETEvent`.\n *\n * `page_view` is not forwarded: bat.js turns that action into its page-load beacon, which the\n * snippet already fires on load and, with `enableAutoSpaTracking: true` (the setting in\n * Microsoft's generated snippet), on every history change — forwarding the SDK's own page views\n * would report each page twice. The tag owns page loads; this tracker owns everything else.\n */\nexport function sendUETEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.uetq) {\n console.warn('uetq has not been initialized');\n return false;\n }\n if (metrics.includes(name) || name === 'page_view') return;\n if (isLocal()) return;\n\n const [action, params] = mapUETEvent(name, properties, eventId);\n window.uetq.push('event', action, clean(params));\n}\n\n/**\n * Enhanced conversions: hand the tag the visitor's email and phone so Microsoft can match a\n * conversion to an ad click without a third-party cookie. A `set` applies to every event fired\n * from the page afterwards, `pageLoad` included, and the tag fires a `pid` beacon on its own\n * when the page load already went out. Values are sent raw — the tag normalizes and SHA-256\n * hashes them in the browser (bat.js `validatePid`) before anything leaves the page.\n *\n * A setter itself, like `setGAUser`, rather than a factory like `setFBUser(pixelId)`: UET is\n * bound to its tag by the snippet and `set` addresses whichever tag drains `uetq`, so there is\n * nothing to bind first.\n */\nexport function setUETUser({ user_id, user_data }: UpdateVisitorDTO) {\n if (typeof window === 'undefined' || !window.uetq) {\n console.warn('uetq has not been initialized');\n return;\n }\n\n // A signed-in user is also the moment the ID Sync pixel can carry a `UID` — see `syncUETVisitor`.\n if (user_id) void syncUETVisitor(user_id);\n\n const em = getFirst(user_data?.email);\n const ph = getFirst(user_data?.phone_number);\n if (!em && !ph) return;\n\n window.uetq.push('set', { pid: clean({ em, ph }) });\n}\n\n/**\n * UET consent mode. Push `default` before the tag loads (the tag processes `consent` early, ahead\n * of the queued events) and `update` when the visitor decides. With `ad_storage: 'denied'` the\n * tag neither writes its cookies nor reads the `msclkid` from the URL.\n * https://help.ads.microsoft.com/#apex/ads/en/60119/1\n */\nexport function setUETConsent(mode: 'default' | 'update', consent: UETConsent) {\n if (typeof window === 'undefined') return;\n window.uetq ??= [] as unknown as UETQ;\n window.uetq.push('consent', mode, consent);\n}\n\n/**\n * The Conversions API's client-side ID Sync pixel: ties the visitor id sent server-side as\n * `anonymousId` to Microsoft's own identifier, so server events can be attributed across\n * contexts (view-through, audiences). Microsoft requires it for remarketing built from CAPI\n * events and recommends it for measurement quality; fire it at least once per session, ideally\n * on the first page view. A pixel rather than a fetch on purpose: Microsoft must observe the\n * browser context of the sync, which a server-side call cannot carry.\n *\n * `customerId` is the Microsoft Advertising customer id (`cid` in the UI's URLs) — not the UET\n * tag id. `visitorId` is the SDK visitor id (`visitorId()`), which is what\n * `sendMicrosoftEvents` sends as `anonymousId`; Microsoft requires the two to be equal.\n * `userId` is the raw signed-in user id: it is SHA-256 hashed here, exactly as the server sender\n * hashes it into `externalId`, so the pair matches as well. Hashing is asynchronous, so the\n * pixel fires once the digest resolves; where SubtleCrypto is unavailable (an insecure context)\n * the pixel goes out without `UID` rather than with a raw id.\n * https://learn.microsoft.com/en-us/advertising/guides/uet-conversion-api-integration#id-sync-and-why-it-matters\n */\n/**\n * The Microsoft Advertising customer id the ID Sync pixel reports to, set once by the framework\n * `Analytics` component's `uetCustomerId` prop (or `configureUET`). Unset, nothing syncs.\n */\nlet uetCustomerId: string | undefined;\n\nexport function configureUET(options: { customerId?: string | number }) {\n uetCustomerId = options.customerId === undefined ? undefined : String(options.customerId);\n}\n\n/**\n * Sync the SDK visitor — the `anonymousId` of the events the server sends to the Conversions\n * API — with Microsoft, plus the user's `UID` when one is known. The `Analytics` components run\n * it on mount so every visit syncs at least once, anonymous visitors included (they are who\n * remarketing audiences are built from), and `setUETUser` runs it again on sign-in.\n */\nexport async function syncUETVisitor(userId?: string): Promise<void> {\n if (!uetCustomerId) return;\n sendUETIdSync({ customerId: uetCustomerId, visitorId: visitorId(), userId });\n}\n\nexport function sendUETIdSync(options: {\n customerId: string | number;\n visitorId: string;\n /** The signed-in user's id, raw; hashed before it leaves the page. */\n userId?: string;\n}) {\n if (typeof window === 'undefined' || typeof Image === 'undefined') return;\n if (isLocal()) return;\n\n const fire = (uid?: string) => {\n const params = new URLSearchParams({\n Red3: `BACID_${options.customerId}`,\n VID: options.visitorId,\n });\n if (uid) params.set('UID', uid);\n new Image().src = `https://c.bing.com/c.gif?${params.toString()}`;\n };\n\n if (!options.userId) {\n fire();\n return;\n }\n sha256(options.userId).then(fire, () => fire());\n}\n\n/** What `microsoftAds` returns: an integration that also names the customer id for ID Sync. */\nexport type MicrosoftAdsIntegration = Integration & { readonly uetCustomerId?: `${number}` };\n\n/** The customer id of the `microsoftAds` integration among these, for `useUETIdSync`. */\nexport function uetCustomerIdOf(integrations: readonly Integration[] = []) {\n return integrations.find(\n (integration): integration is MicrosoftAdsIntegration => 'uetCustomerId' in integration\n )?.uetCustomerId;\n}\n\n/**\n * Microsoft Advertising UET. UET has no standard events to map to — a conversion goal is defined\n * on an action name in the ads UI — so it receives an explicit list, the GA4 conversion events\n * by default (`CONVERSION_EVENTS`), plus `customEvents`.\n *\n * Its script is Microsoft's UET snippet with `enableAutoSpaTracking: true` (the tag reports page\n * loads itself), the consent mode default pushed inside it so bat.js reads it before the first\n * page load.\n */\nexport function microsoftAds(\n options: {\n tagId: `${number}`;\n /** Microsoft Advertising customer id (`cid` in the ads UI's URLs): enables the ID Sync pixel. */\n customerId?: `${number}`;\n /**\n * The UET consent mode default, `ad_storage: granted` unless given: how the tag behaves\n * without a signal, so Microsoft stops flagging EEA/UK/CH events as missing consent. Sites\n * with a consent banner pass `{ ad_storage: 'denied' }` and send `update` with\n * `setUETConsent`; `false` pushes no default. https://help.ads.microsoft.com/#apex/ads/en/60119/1\n */\n consent?: UETConsent | false;\n events?: readonly EventName[];\n } & AdsOptions\n): MicrosoftAdsIntegration {\n const events: readonly string[] = options.events ?? CONVERSION_EVENTS;\n const consent = options.consent ?? { ad_storage: 'granted' };\n const defaults = consent ? `w[u].push(\"consent\", \"default\", ${JSON.stringify(consent)});` : '';\n return {\n type: 'ads',\n track: adsTracker(sendUETEvent, (name) => events.includes(name), options.customEvents ?? []),\n setUser: setUETUser,\n script: {\n id: 'uet-tag',\n inline: `\n (function (w, d, t, u, o) {\n w[u] = w[u] || [], o.ts = (new Date).getTime();\n ${defaults}\n var n = d.createElement(t);\n n.src = \"https://bat.bing.net/bat.js?ti=\" + o.ti + (\"uetq\" != u ? \"&q=\" + u : \"\"),\n n.async = 1, n.onload = n.onreadystatechange = function() {\n var s = this.readyState;\n s && \"loaded\" !== s && \"complete\" !== s ||\n (o.q = w[u], w[u] = new UET(o), w[u].push(\"pageLoad\"),\n n.onload = n.onreadystatechange = null)\n };\n var i = d.getElementsByTagName(t)[0];\n i.parentNode.insertBefore(n, i);\n })(window, document, \"script\", \"uetq\", {\n ti: ${JSON.stringify(options.tagId)},\n enableAutoSpaTracking: true\n });\n `,\n },\n uetCustomerId: options.customerId,\n };\n}\n"],"mappings":";;;;;;AAkBA,MAAM,UAAU;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;AAAM;;AAI1D,SAAS,MAAM,OAAqB;CAClC,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AACzC;AAEA,SAAS,UAAmB;CAC1B,OAAO,OAAO,SAAS,KAAK,SAAS,WAAW,KAAK,OAAO,SAAS,KAAK,SAAS,WAAW;AAChG;;;;;;;;;;;;;AAcA,SAAgB,aACd,MACA,YACA,SACA;CACA,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;EACjD,QAAQ,KAAK,+BAA+B;EAC5C,OAAO;CACT;CACA,IAAI,QAAQ,SAAS,IAAI,KAAK,SAAS,aAAa;CACpD,IAAI,QAAQ,GAAG;CAEf,MAAM,CAAC,QAAQ,UAAU,YAAY,MAAM,YAAY,OAAO;CAC9D,OAAO,KAAK,KAAK,SAAS,QAAQ,MAAM,MAAM,CAAC;AACjD;;;;;;;;;;;;AAaA,SAAgB,WAAW,EAAE,SAAS,aAA+B;CACnE,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;EACjD,QAAQ,KAAK,+BAA+B;EAC5C;CACF;CAGA,IAAI,SAAS,eAAoB,OAAO;CAExC,MAAM,KAAK,SAAS,WAAW,KAAK;CACpC,MA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U;CAC3D,MAAM,WAAW,UAAU,mCAAmC,KAAK,UAAU,OAAO,EAAE,MAAM;CAC5F,OAAO;EACL,MAAM;EACN,OAAO,WAAW,eAAe,SAAS,OAAO,SAAS,IAAI,GAAG,QAAQ,gBAAgB,CAAC,CAAC;EAC3F,SAAS;EACT,QAAQ;GACN,IAAI;GACJ,QAAQ;;;YAGF,SAAS;;;;;;;;;;;;gBAYL,KAAK,UAAU,QAAQ,KAAK,EAAE;;;;EAI1C;EACA,eAAe,QAAQ;CACzB;AACF"}
1
+ {"version":3,"file":"microsoft-uet.mjs","names":[],"sources":["../../src/third-parties/microsoft-uet.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { type UETConsent, type UETQ, mapUETEvent } from '../track/uetq';\nimport { getFirst } from '../utils/field';\nimport { sha256 } from '../utils/sha256';\nimport { visitorId } from '../visitor/id';\nimport {\n type AdsOptions,\n CONVERSION_EVENTS,\n type Integration,\n adEvents,\n adsTracker,\n} from './integration';\n\ndeclare global {\n interface Window {\n /**\n * Defined by the UET snippet before `bat.js` loads (as a plain array), so pushes made early\n * are queued rather than lost. Undefined only where the snippet was never installed.\n */\n uetq?: UETQ;\n }\n}\n\nconst metrics = ['CLS', 'FCP', 'FID', 'INP', 'LCP', 'TTFB'];\n\n/** Drop `undefined` fields: bat.js validates every key it receives, and `undefined` is a value. */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction clean(value: unknown): any {\n return JSON.parse(JSON.stringify(value));\n}\n\nfunction isLocal(): boolean {\n return window.location.host.includes('127.0.0.1') || window.location.host.includes('localhost');\n}\n\n/**\n * Forward an internal track event to the Microsoft Advertising UET tag.\n *\n * `eventId` is reused as UET's `event_id` so the browser event deduplicates against the same\n * conversion sent through the Conversions API (`sendMicrosoftEvents`). The action name is the\n * internal name on both channels — see `mapUETEvent`.\n *\n * `page_view` is not forwarded: bat.js turns that action into its page-load beacon, which the\n * snippet already fires on load and, with `enableAutoSpaTracking: true` (the setting in\n * Microsoft's generated snippet), on every history change — forwarding the SDK's own page views\n * would report each page twice. The tag owns page loads; this tracker owns everything else.\n */\nexport function sendUETEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.uetq) {\n console.warn('uetq has not been initialized');\n return false;\n }\n if (metrics.includes(name) || name === 'page_view') return;\n if (isLocal()) return;\n\n const [action, params] = mapUETEvent(name, properties, eventId);\n window.uetq.push('event', action, clean(params));\n}\n\n/**\n * Enhanced conversions: hand the tag the visitor's email and phone so Microsoft can match a\n * conversion to an ad click without a third-party cookie. A `set` applies to every event fired\n * from the page afterwards, `pageLoad` included, and the tag fires a `pid` beacon on its own\n * when the page load already went out. Values are sent raw — the tag normalizes and SHA-256\n * hashes them in the browser (bat.js `validatePid`) before anything leaves the page.\n *\n * A setter itself, like `setGAUser`, rather than a factory like `setFBUser(pixelId)`: UET is\n * bound to its tag by the snippet and `set` addresses whichever tag drains `uetq`, so there is\n * nothing to bind first.\n */\nexport function setUETUser({ user_id, user_data }: UpdateVisitorDTO) {\n if (typeof window === 'undefined' || !window.uetq) {\n console.warn('uetq has not been initialized');\n return;\n }\n\n // A signed-in user is also the moment the ID Sync pixel can carry a `UID` — see `syncUETVisitor`.\n if (user_id) void syncUETVisitor(user_id);\n\n const em = getFirst(user_data?.email);\n const ph = getFirst(user_data?.phone_number);\n if (!em && !ph) return;\n\n window.uetq.push('set', { pid: clean({ em, ph }) });\n}\n\n/**\n * UET consent mode. Push `default` before the tag loads (the tag processes `consent` early, ahead\n * of the queued events) and `update` when the visitor decides. With `ad_storage: 'denied'` the\n * tag neither writes its cookies nor reads the `msclkid` from the URL.\n * https://help.ads.microsoft.com/#apex/ads/en/60119/1\n */\nexport function setUETConsent(mode: 'default' | 'update', consent: UETConsent) {\n if (typeof window === 'undefined') return;\n window.uetq ??= [] as unknown as UETQ;\n window.uetq.push('consent', mode, consent);\n}\n\n/**\n * The Conversions API's client-side ID Sync pixel: ties the visitor id sent server-side as\n * `anonymousId` to Microsoft's own identifier, so server events can be attributed across\n * contexts (view-through, audiences). Microsoft requires it for remarketing built from CAPI\n * events and recommends it for measurement quality; fire it at least once per session, ideally\n * on the first page view. A pixel rather than a fetch on purpose: Microsoft must observe the\n * browser context of the sync, which a server-side call cannot carry.\n *\n * `customerId` is the Microsoft Advertising customer id (`cid` in the UI's URLs) — not the UET\n * tag id. `visitorId` is the SDK visitor id (`visitorId()`), which is what\n * `sendMicrosoftEvents` sends as `anonymousId`; Microsoft requires the two to be equal.\n * `userId` is the raw signed-in user id: it is SHA-256 hashed here, exactly as the server sender\n * hashes it into `externalId`, so the pair matches as well. Hashing is asynchronous, so the\n * pixel fires once the digest resolves; where SubtleCrypto is unavailable (an insecure context)\n * the pixel goes out without `UID` rather than with a raw id.\n * https://learn.microsoft.com/en-us/advertising/guides/uet-conversion-api-integration#id-sync-and-why-it-matters\n */\n/**\n * The Microsoft Advertising customer id the ID Sync pixel reports to, set once by the framework\n * `Analytics` component's `uetCustomerId` prop (or `configureUET`). Unset, nothing syncs.\n */\nlet uetCustomerId: string | undefined;\n\nexport function configureUET(options: { customerId?: string | number }) {\n uetCustomerId = options.customerId === undefined ? undefined : String(options.customerId);\n}\n\n/**\n * Sync the SDK visitor — the `anonymousId` of the events the server sends to the Conversions\n * API — with Microsoft, plus the user's `UID` when one is known. The `Analytics` components run\n * it on mount so every visit syncs at least once, anonymous visitors included (they are who\n * remarketing audiences are built from), and `setUETUser` runs it again on sign-in.\n */\nexport async function syncUETVisitor(userId?: string): Promise<void> {\n if (!uetCustomerId) return;\n sendUETIdSync({ customerId: uetCustomerId, visitorId: visitorId(), userId });\n}\n\nexport function sendUETIdSync(options: {\n customerId: string | number;\n visitorId: string;\n /** The signed-in user's id, raw; hashed before it leaves the page. */\n userId?: string;\n}) {\n if (typeof window === 'undefined' || typeof Image === 'undefined') return;\n if (isLocal()) return;\n\n const fire = (uid?: string) => {\n const params = new URLSearchParams({\n Red3: `BACID_${options.customerId}`,\n VID: options.visitorId,\n });\n if (uid) params.set('UID', uid);\n new Image().src = `https://c.bing.com/c.gif?${params.toString()}`;\n };\n\n if (!options.userId) {\n fire();\n return;\n }\n sha256(options.userId).then(fire, () => fire());\n}\n\n/** What `microsoftAds` returns: an integration that also names the customer id for ID Sync. */\nexport type MicrosoftAdsIntegration = Integration & { readonly uetCustomerId?: `${number}` };\n\n/** The customer id of the `microsoftAds` integration among these, for `useUETIdSync`. */\nexport function uetCustomerIdOf(integrations: readonly Integration[] = []) {\n return integrations.find(\n (integration): integration is MicrosoftAdsIntegration => 'uetCustomerId' in integration\n )?.uetCustomerId;\n}\n\n/**\n * Microsoft Advertising UET. UET has no standard events to map to — a conversion goal is defined\n * on an action name in the ads UI — so it receives an explicit list, the GA4 conversion events\n * by default (`CONVERSION_EVENTS`), plus `customEvents`.\n *\n * Its script is Microsoft's UET snippet with `enableAutoSpaTracking: true` (the tag reports page\n * loads itself), the consent mode default pushed inside it so bat.js reads it before the first\n * page load.\n */\n/** The events UET receives: `events` (the GA4 conversion events by default) and `customEvents`. */\nexport function uetEvents(options: Pick<MicrosoftAdsOptions, 'events' | 'customEvents'>) {\n const events: readonly string[] = options.events ?? CONVERSION_EVENTS;\n return adEvents((name) => events.includes(name), options.customEvents);\n}\n\n/**\n * Microsoft's configuration, shared by `microsoftAds` and `microsoftConversions` on the server.\n */\nexport interface MicrosoftAdsOptions extends AdsOptions {\n tagId: `${number}`;\n /** Microsoft Advertising customer id (`cid` in the ads UI's URLs): enables the ID Sync pixel. */\n customerId?: `${number}`;\n /**\n * The UET consent mode default, `ad_storage: granted` unless given: how the tag behaves\n * without a signal, so Microsoft stops flagging EEA/UK/CH events as missing consent. Sites\n * with a consent banner pass `{ ad_storage: 'denied' }` and send `update` with\n * `setUETConsent`; `false` pushes no default. https://help.ads.microsoft.com/#apex/ads/en/60119/1\n */\n consent?: UETConsent | false;\n /** The events UET receives, `CONVERSION_EVENTS` by default; names `track` accepts. */\n events?: readonly TrackName[];\n}\n\nexport function microsoftAds(options: MicrosoftAdsOptions): MicrosoftAdsIntegration {\n const consent = options.consent ?? { ad_storage: 'granted' };\n const defaults = consent ? `w[u].push(\"consent\", \"default\", ${JSON.stringify(consent)});` : '';\n return {\n type: 'ads',\n track: adsTracker(sendUETEvent, uetEvents(options)),\n setUser: setUETUser,\n script: {\n id: 'uet-tag',\n inline: `\n (function (w, d, t, u, o) {\n w[u] = w[u] || [], o.ts = (new Date).getTime();\n ${defaults}\n var n = d.createElement(t);\n n.src = \"https://bat.bing.net/bat.js?ti=\" + o.ti + (\"uetq\" != u ? \"&q=\" + u : \"\"),\n n.async = 1, n.onload = n.onreadystatechange = function() {\n var s = this.readyState;\n s && \"loaded\" !== s && \"complete\" !== s ||\n (o.q = w[u], w[u] = new UET(o), w[u].push(\"pageLoad\"),\n n.onload = n.onreadystatechange = null)\n };\n var i = d.getElementsByTagName(t)[0];\n i.parentNode.insertBefore(n, i);\n })(window, document, \"script\", \"uetq\", {\n ti: ${JSON.stringify(options.tagId)},\n enableAutoSpaTracking: true\n });\n `,\n },\n uetCustomerId: options.customerId,\n };\n}\n"],"mappings":";;;;;;AAwBA,MAAM,UAAU;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;AAAM;;AAI1D,SAAS,MAAM,OAAqB;CAClC,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AACzC;AAEA,SAAS,UAAmB;CAC1B,OAAO,OAAO,SAAS,KAAK,SAAS,WAAW,KAAK,OAAO,SAAS,KAAK,SAAS,WAAW;AAChG;;;;;;;;;;;;;AAcA,SAAgB,aACd,MACA,YACA,SACA;CACA,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;EACjD,QAAQ,KAAK,+BAA+B;EAC5C,OAAO;CACT;CACA,IAAI,QAAQ,SAAS,IAAI,KAAK,SAAS,aAAa;CACpD,IAAI,QAAQ,GAAG;CAEf,MAAM,CAAC,Q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AQ;EACnB,KAAK;EACL;CACF;CACA,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;AAChD;;AAMA,SAAgB,gBAAgB,eAAuC,CAAC,GAAG;CACzE,OAAO,aAAa,MACjB,gBAAwD,mBAAmB,WAC9E,CAAC,EAAE;AACL;;;;;;;;;;;AAYA,SAAgB,UAAU,SAA+D;CACvF,MAAM,SAA4B,QAAQ,UAAU;CACpD,OAAO,UAAU,SAAS,OAAO,SAAS,IAAI,GAAG,QAAQ,YAAY;AACvE;AAoBA,SAAgB,aAAa,SAAuD;CAClF,MAAM,UAAU,QAAQ,WAAW,EAAE,YAAY,UAAU;CAC3D,MAAM,WAAW,UAAU,mCAAmC,KAAK,UAAU,OAAO,EAAE,MAAM;CAC5F,OAAO;EACL,MAAM;EACN,OAAO,WAAW,cAAc,UAAU,OAAO,CAAC;EAClD,SAAS;EACT,QAAQ;GACN,IAAI;GACJ,QAAQ;;;YAGF,SAAS;;;;;;;;;;;;gBAYL,KAAK,UAAU,QAAQ,KAAK,EAAE;;;;EAI1C;EACA,eAAe,QAAQ;CACzB;AACF"}
@@ -79,12 +79,10 @@ function setOpenAIUser(pixelId) {
79
79
  })).catch(() => init({}));
80
80
  };
81
81
  }
82
- /** OpenAI measurement pixel: the events `mapOAIEvent` maps to a standard event, and `customEvents`. */
83
82
  function openaiAds(options) {
84
- const isStandard = (name) => require_track_oaiq.mapOAIEvent(name).type !== "custom";
85
83
  return {
86
84
  type: "ads",
87
- track: require_third_parties_integration.adsTracker(sendOpenAIEvent, isStandard, options.customEvents ?? []),
85
+ track: require_third_parties_integration.adsTracker(sendOpenAIEvent, require_third_parties_integration.adEvents(require_track_oaiq.isStandardOAIEvent, options.customEvents)),
88
86
  setUser: setOpenAIUser(options.pixelId),
89
87
  script: {
90
88
  id: "openai-pixel",
@@ -1 +1 @@
1
- {"version":3,"file":"openai-pixel.cjs","names":["NON_AD_EVENTS","mapOAIEvent","APP_EVENTS","oaiCustomEventName","getFirst","sha256","normalizeOAIPhone","normalizeOAIName","adsTracker"],"sources":["../../src/third-parties/openai-pixel.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport {\n APP_EVENTS,\n NON_AD_EVENTS,\n type OAIQ,\n type OAIQUser,\n mapOAIEvent,\n normalizeOAIName,\n normalizeOAIPhone,\n oaiCustomEventName,\n} from '../track/oaiq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\nimport { sha256 } from '../utils/sha256';\nimport { type AdsOptions, type Integration, adsTracker } from './integration';\n\ndeclare global {\n interface Window {\n /** Undefined until the OpenAI pixel script has loaded. */\n oaiq?: OAIQ['oaiq'];\n }\n}\n\n/** Drop `undefined` fields so the SDK only receives populated values. */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction clean(value: unknown): any {\n return JSON.parse(JSON.stringify(value));\n}\n\n/**\n * Forward an internal track event to the OpenAI measurement pixel.\n * `eventId` is reused as the OpenAI `event_id` so browser events deduplicate against the\n * Conversions API. https://developers.openai.com/ads/measurement-pixel\n */\nexport function sendOpenAIEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.oaiq) {\n console.warn('oaiq has not been initialized');\n return false;\n }\n if (NON_AD_EVENTS.includes(name)) return;\n if (window.location.host.includes('127.0.0.1')) return;\n if (window.location.host.includes('localhost')) return;\n\n const { type, data } = mapOAIEvent(name, properties);\n // OpenAI takes the app events from the Conversions API only.\n if (APP_EVENTS.includes(type as never)) return;\n if (type === 'custom') {\n // Named as the Conversions API names it, so the two deduplicate; skipped when it cannot be.\n const custom_event_name = oaiCustomEventName(name);\n if (!custom_event_name) return;\n window.oaiq('measure', 'custom', clean(data), { event_id: eventId, custom_event_name });\n } else {\n window.oaiq('measure', type, clean(data), { event_id: eventId });\n }\n}\n\n/**\n * Re-initialize the pixel with hashed user identity for better conversion matching. Email, phone,\n * external id and names are normalized as OpenAI documents and hashed client-side; geographic\n * fields are sent raw. Hashing is asynchronous, so the `init` call is deferred until the digests\n * resolve.\n */\nexport function setOpenAIUser(pixelId: string) {\n return ({ user_id, user_data }: UpdateVisitorDTO) => {\n if (typeof window === 'undefined' || !window.oaiq) {\n console.warn('oaiq has not been initialized');\n return;\n }\n // Capture the narrowed reference so the deferred `init` closure keeps it non-optional.\n const oaiq = window.oaiq;\n\n const email = getFirst(user_data?.email)?.trim().toLowerCase() || undefined;\n const phone = getFirst(user_data?.phone_number);\n const address = getFirst(user_data?.address);\n\n const base: OAIQUser = {\n country: address?.country?.trim().toUpperCase(),\n city: address?.city?.trim(),\n region: address?.region?.trim(),\n postal_code: address?.postal_code?.trim(),\n };\n\n const init = (hashed: Partial<OAIQUser>) => {\n oaiq('init', { pixelId, user: clean({ ...base, ...hashed }) });\n };\n\n const hash = (value: string | undefined) => (value ? sha256(value) : undefined);\n Promise.all([\n hash(email),\n hash(phone ? normalizeOAIPhone(phone) : undefined),\n hash(user_id?.trim()),\n hash(normalizeOAIName(address?.first_name)),\n hash(normalizeOAIName(address?.last_name)),\n ])\n .then(([email_sha256, phone_number_sha256, external_id_sha256, first, last]) =>\n init({\n email_sha256,\n phone_number_sha256,\n external_id_sha256,\n first_name_sha256: first,\n last_name_sha256: last,\n })\n )\n .catch(() => init({}));\n };\n}\n\n/** OpenAI measurement pixel: the events `mapOAIEvent` maps to a standard event, and `customEvents`. */\nexport function openaiAds(options: { pixelId: string } & AdsOptions): Integration {\n const isStandard = (name: string) => mapOAIEvent(name as TrackName).type !== 'custom';\n return {\n type: 'ads',\n track: adsTracker(sendOpenAIEvent, isStandard, options.customEvents ?? []),\n setUser: setOpenAIUser(options.pixelId),\n script: {\n id: 'openai-pixel',\n inline: `\n (function (w, d, s, u) {\n if (w.oaiq) return;\n var q = function () {\n q.q.push(arguments);\n };\n q.q = [];\n w.oaiq = q;\n var js = d.createElement(s);\n js.async = true;\n js.src = u;\n var f = d.getElementsByTagName(s)[0];\n f.parentNode.insertBefore(js, f);\n })(window, document, \"script\", \"https://bzrcdn.openai.com/sdk/oaiq.min.js\");\n oaiq(\"init\", { pixelId: ${JSON.stringify(options.pixelId)} });\n oaiq(\"measure\", \"page_viewed\", { type: \"contents\" });\n `,\n },\n };\n}\n"],"mappings":";;;;;;;AAyBA,SAAS,MAAM,OAAqB;CAClC,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AACzC;;;;;;AAOA,SAAgB,gBACd,MACA,YACA,SACA;CACA,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;EACjD,QAAQ,KAAK,+BAA+B;EAC5C,OAAO;CACT;CACA,IAAIA,mBAAAA,cAAc,SAAS,IAAI,GAAG;CAClC,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAChD,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAEhD,MAAM,EAAE,MAAM,SAASC,mBAAAA,YAAY,MAAM,UAAU;CAEnD,IAAIC,mBAAAA,WAAW,SAAS,IAAa,GAAG;CACxC,IAAI,SAAS,UAAU;EAErB,MAAM,oBAAoBC,mBAAAA,mBAAmB,IAAI;EACjD,IAAI,CAAC,mBAAmB;EACxB,OAAO,KAAK,WAAW,UAAU,MAAM,IAAI,GAAG;GAAE,UAAU;GAAS;EAAkB,CAAC;CACxF,OACE,OAAO,KAAK,WAAW,MAAM,MAAM,IAAI,GAAG,EAAE,UAAU,QAAQ,CAAC;AAEnE;;;;;;;AAQA,SAAgB,cAAc,SAAiB;CAC7C,QAAQ,EAAE,SAAS,gBAAkC;EACnD,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;GACjD,QAAQ,KAAK,+BAA+B;GAC5C;EACF;EAEA,MAAM,OAAO,OAAO;EAEpB,MAAM,QAAQC,oBAAAA,SAAS,WAAW,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,YAAY,KAAK,KAAA;EAClE,MAAM,QAAQA,oBAAAA,SAAS,WAAW,YAA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omEventName","getFirst","sha256","normalizeOAIPhone","normalizeOAIName","adsTracker","adEvents","isStandardOAIEvent"],"sources":["../../src/third-parties/openai-pixel.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport {\n APP_EVENTS,\n NON_AD_EVENTS,\n type OAIQ,\n type OAIQUser,\n isStandardOAIEvent,\n mapOAIEvent,\n normalizeOAIName,\n normalizeOAIPhone,\n oaiCustomEventName,\n} from '../track/oaiq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\nimport { sha256 } from '../utils/sha256';\nimport { type AdsOptions, type Integration, adEvents, adsTracker } from './integration';\n\ndeclare global {\n interface Window {\n /** Undefined until the OpenAI pixel script has loaded. */\n oaiq?: OAIQ['oaiq'];\n }\n}\n\n/** Drop `undefined` fields so the SDK only receives populated values. */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction clean(value: unknown): any {\n return JSON.parse(JSON.stringify(value));\n}\n\n/**\n * Forward an internal track event to the OpenAI measurement pixel.\n * `eventId` is reused as the OpenAI `event_id` so browser events deduplicate against the\n * Conversions API. https://developers.openai.com/ads/measurement-pixel\n */\nexport function sendOpenAIEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.oaiq) {\n console.warn('oaiq has not been initialized');\n return false;\n }\n if (NON_AD_EVENTS.includes(name)) return;\n if (window.location.host.includes('127.0.0.1')) return;\n if (window.location.host.includes('localhost')) return;\n\n const { type, data } = mapOAIEvent(name, properties);\n // OpenAI takes the app events from the Conversions API only.\n if (APP_EVENTS.includes(type as never)) return;\n if (type === 'custom') {\n // Named as the Conversions API names it, so the two deduplicate; skipped when it cannot be.\n const custom_event_name = oaiCustomEventName(name);\n if (!custom_event_name) return;\n window.oaiq('measure', 'custom', clean(data), { event_id: eventId, custom_event_name });\n } else {\n window.oaiq('measure', type, clean(data), { event_id: eventId });\n }\n}\n\n/**\n * Re-initialize the pixel with hashed user identity for better conversion matching. Email, phone,\n * external id and names are normalized as OpenAI documents and hashed client-side; geographic\n * fields are sent raw. Hashing is asynchronous, so the `init` call is deferred until the digests\n * resolve.\n */\nexport function setOpenAIUser(pixelId: string) {\n return ({ user_id, user_data }: UpdateVisitorDTO) => {\n if (typeof window === 'undefined' || !window.oaiq) {\n console.warn('oaiq has not been initialized');\n return;\n }\n // Capture the narrowed reference so the deferred `init` closure keeps it non-optional.\n const oaiq = window.oaiq;\n\n const email = getFirst(user_data?.email)?.trim().toLowerCase() || undefined;\n const phone = getFirst(user_data?.phone_number);\n const address = getFirst(user_data?.address);\n\n const base: OAIQUser = {\n country: address?.country?.trim().toUpperCase(),\n city: address?.city?.trim(),\n region: address?.region?.trim(),\n postal_code: address?.postal_code?.trim(),\n };\n\n const init = (hashed: Partial<OAIQUser>) => {\n oaiq('init', { pixelId, user: clean({ ...base, ...hashed }) });\n };\n\n const hash = (value: string | undefined) => (value ? sha256(value) : undefined);\n Promise.all([\n hash(email),\n hash(phone ? normalizeOAIPhone(phone) : undefined),\n hash(user_id?.trim()),\n hash(normalizeOAIName(address?.first_name)),\n hash(normalizeOAIName(address?.last_name)),\n ])\n .then(([email_sha256, phone_number_sha256, external_id_sha256, first, last]) =>\n init({\n email_sha256,\n phone_number_sha256,\n external_id_sha256,\n first_name_sha256: first,\n last_name_sha256: last,\n })\n )\n .catch(() => init({}));\n };\n}\n\n/** OpenAI measurement pixel: the events `mapOAIEvent` maps to a standard event, and `customEvents`. */\n/** OpenAI's configuration, shared by `openaiAds` and `openaiConversions` on the server. */\nexport interface OpenAIAdsOptions extends AdsOptions {\n pixelId: string;\n}\n\nexport function openaiAds(options: OpenAIAdsOptions): Integration {\n return {\n type: 'ads',\n track: adsTracker(sendOpenAIEvent, adEvents(isStandardOAIEvent, options.customEvents)),\n setUser: setOpenAIUser(options.pixelId),\n script: {\n id: 'openai-pixel',\n inline: `\n (function (w, d, s, u) {\n if (w.oaiq) return;\n var q = function () {\n q.q.push(arguments);\n };\n q.q = [];\n w.oaiq = q;\n var js = d.createElement(s);\n js.async = true;\n js.src = u;\n var f = d.getElementsByTagName(s)[0];\n f.parentNode.insertBefore(js, f);\n })(window, document, \"script\", \"https://bzrcdn.openai.com/sdk/oaiq.min.js\");\n oaiq(\"init\", { pixelId: ${JSON.stringify(options.pixelId)} });\n oaiq(\"measure\", \"page_viewed\", { type: \"contents\" });\n `,\n },\n };\n}\n"],"mappings":";;;;;;;AA0BA,SAAS,MAAM,OAAqB;CAClC,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AACzC;;;;;;AAOA,SAAgB,gBACd,MACA,YACA,SACA;CACA,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;EACjD,QAAQ,KAAK,+BAA+B;EAC5C,OAAO;CACT;CACA,IAAIA,mBAAAA,cAAc,SAAS,IAAI,GAAG;CAClC,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAChD,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAEhD,MAAM,EAAE,MAAM,SAASC,mBAAAA,YAAY,MAAM,UAAU;CAEnD,IAAIC,mBAAAA,WAAW,SAAS,IAAa,GAAG;CACxC,IAAI,SAAS,UAAU;EAErB,MAAM,oBAAoBC,mBAAAA,mBAAmB,IAAI;EACjD,IAAI,CAAC,mBAAmB;EACxB,OAAO,KAAK,WAAW,UAAU,MAAM,IAAI,GAAG;GAAE,UAAU;GAAS;EAAkB,CAAC;CACxF,OACE,OAAO,KAAK,WAAW,MAAM,MAAM,IAAI,GAAG,EAAE,UAAU,QAAQ,CAAC;AAEnE;;;;;;;AAQA,SAAgB,cAAc,SAAiB;CAC7C,QAAQ,EAAE,SAAS,gBAAkC;EACnD,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;GACjD,QAAQ,KAAK,+BAA+B;GAC5C;EACF;EAEA,MAAM,OAAO,OAAO;EAEpB,MAAM,QAAQC,oBAAAA,SAAS,WAAW,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enAIEvent<T extends EventName>(name: TrackName<T>,
22
22
  */
23
23
  export declare function setOpenAIUser(pixelId: string): ({ user_id, user_data }: UpdateVisitorDTO) => void;
24
24
  /** OpenAI measurement pixel: the events `mapOAIEvent` maps to a standard event, and `customEvents`. */
25
- export declare function openaiAds(options: {
25
+ /** OpenAI's configuration, shared by `openaiAds` and `openaiConversions` on the server. */
26
+ export interface OpenAIAdsOptions extends AdsOptions {
26
27
  pixelId: string;
27
- } & AdsOptions): Integration;
28
+ }
29
+ export declare function openaiAds(options: OpenAIAdsOptions): Integration;
28
30
  //# sourceMappingURL=openai-pixel.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"openai-pixel.d.cts","names":[],"sources":["../../src/third-parties/openai-pixel.ts"],"mappings":";;;;QAgBQ;YACI;;IAER,OAAO;;;;;;;;wBAeK,gBAAgB,UAAU,WACxC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;;;;;;;wBA6Bc,cAAc,qBAAe,SAAA,aACX;;wBA6ClB,UAAU;EAAW;IAAoB,aAAa"}
1
+ {"version":3,"file":"openai-pixel.d.cts","names":[],"sources":["../../src/third-parties/openai-pixel.ts"],"mappings":";;;;QAiBQ;YACI;;IAER,OAAO;;;;;;;;wBAeK,gBAAgB,UAAU,WACxC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;;;;;;;wBA6Bc,cAAc,qBAAe,SAAA,aACX;;;iBA8CjB,yBAAyB;EACxC;;wBAGc,UAAU,SAAS,mBAAmB"}
@@ -22,7 +22,9 @@ export declare function sendOpenAIEvent<T extends EventName>(name: TrackName<T>,
22
22
  */
23
23
  export declare function setOpenAIUser(pixelId: string): ({ user_id, user_data }: UpdateVisitorDTO) => void;
24
24
  /** OpenAI measurement pixel: the events `mapOAIEvent` maps to a standard event, and `customEvents`. */
25
- export declare function openaiAds(options: {
25
+ /** OpenAI's configuration, shared by `openaiAds` and `openaiConversions` on the server. */
26
+ export interface OpenAIAdsOptions extends AdsOptions {
26
27
  pixelId: string;
27
- } & AdsOptions): Integration;
28
+ }
29
+ export declare function openaiAds(options: OpenAIAdsOptions): Integration;
28
30
  //# sourceMappingURL=openai-pixel.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"openai-pixel.d.mts","names":[],"sources":["../../src/third-parties/openai-pixel.ts"],"mappings":";;;;QAgBQ;YACI;;IAER,OAAO;;;;;;;;wBAeK,gBAAgB,UAAU,WACxC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;;;;;;;wBA6Bc,cAAc,qBAAe,SAAA,aACX;;wBA6ClB,UAAU;EAAW;IAAoB,aAAa"}
1
+ {"version":3,"file":"openai-pixel.d.mts","names":[],"sources":["../../src/third-parties/openai-pixel.ts"],"mappings":";;;;QAiBQ;YACI;;IAER,OAAO;;;;;;;;wBAeK,gBAAgB,UAAU,WACxC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;;;;;;;wBA6Bc,cAAc,qBAAe,SAAA,aACX;;;iBA8CjB,yBAAyB;EACxC;;wBAGc,UAAU,SAAS,mBAAmB"}
@@ -1,7 +1,7 @@
1
1
  import { getFirst } from "../utils/field.mjs";
2
2
  import { sha256 } from "../utils/sha256.mjs";
3
- import { adsTracker } from "./integration.mjs";
4
- import { APP_EVENTS, NON_AD_EVENTS, mapOAIEvent, normalizeOAIName, normalizeOAIPhone, oaiCustomEventName } from "../track/oaiq.mjs";
3
+ import { adEvents, adsTracker } from "./integration.mjs";
4
+ import { APP_EVENTS, NON_AD_EVENTS, isStandardOAIEvent, mapOAIEvent, normalizeOAIName, normalizeOAIPhone, oaiCustomEventName } from "../track/oaiq.mjs";
5
5
  // src/third-parties/openai-pixel.ts
6
6
  /** Drop `undefined` fields so the SDK only receives populated values. */
7
7
  function clean(value) {
@@ -78,12 +78,10 @@ function setOpenAIUser(pixelId) {
78
78
  })).catch(() => init({}));
79
79
  };
80
80
  }
81
- /** OpenAI measurement pixel: the events `mapOAIEvent` maps to a standard event, and `customEvents`. */
82
81
  function openaiAds(options) {
83
- const isStandard = (name) => mapOAIEvent(name).type !== "custom";
84
82
  return {
85
83
  type: "ads",
86
- track: adsTracker(sendOpenAIEvent, isStandard, options.customEvents ?? []),
84
+ track: adsTracker(sendOpenAIEvent, adEvents(isStandardOAIEvent, options.customEvents)),
87
85
  setUser: setOpenAIUser(options.pixelId),
88
86
  script: {
89
87
  id: "openai-pixel",
@@ -1 +1 @@
1
- {"version":3,"file":"openai-pixel.mjs","names":[],"sources":["../../src/third-parties/openai-pixel.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport {\n APP_EVENTS,\n NON_AD_EVENTS,\n type OAIQ,\n type OAIQUser,\n mapOAIEvent,\n normalizeOAIName,\n normalizeOAIPhone,\n oaiCustomEventName,\n} from '../track/oaiq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\nimport { sha256 } from '../utils/sha256';\nimport { type AdsOptions, type Integration, adsTracker } from './integration';\n\ndeclare global {\n interface Window {\n /** Undefined until the OpenAI pixel script has loaded. */\n oaiq?: OAIQ['oaiq'];\n }\n}\n\n/** Drop `undefined` fields so the SDK only receives populated values. */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction clean(value: unknown): any {\n return JSON.parse(JSON.stringify(value));\n}\n\n/**\n * Forward an internal track event to the OpenAI measurement pixel.\n * `eventId` is reused as the OpenAI `event_id` so browser events deduplicate against the\n * Conversions API. https://developers.openai.com/ads/measurement-pixel\n */\nexport function sendOpenAIEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.oaiq) {\n console.warn('oaiq has not been initialized');\n return false;\n }\n if (NON_AD_EVENTS.includes(name)) return;\n if (window.location.host.includes('127.0.0.1')) return;\n if (window.location.host.includes('localhost')) return;\n\n const { type, data } = mapOAIEvent(name, properties);\n // OpenAI takes the app events from the Conversions API only.\n if (APP_EVENTS.includes(type as never)) return;\n if (type === 'custom') {\n // Named as the Conversions API names it, so the two deduplicate; skipped when it cannot be.\n const custom_event_name = oaiCustomEventName(name);\n if (!custom_event_name) return;\n window.oaiq('measure', 'custom', clean(data), { event_id: eventId, custom_event_name });\n } else {\n window.oaiq('measure', type, clean(data), { event_id: eventId });\n }\n}\n\n/**\n * Re-initialize the pixel with hashed user identity for better conversion matching. Email, phone,\n * external id and names are normalized as OpenAI documents and hashed client-side; geographic\n * fields are sent raw. Hashing is asynchronous, so the `init` call is deferred until the digests\n * resolve.\n */\nexport function setOpenAIUser(pixelId: string) {\n return ({ user_id, user_data }: UpdateVisitorDTO) => {\n if (typeof window === 'undefined' || !window.oaiq) {\n console.warn('oaiq has not been initialized');\n return;\n }\n // Capture the narrowed reference so the deferred `init` closure keeps it non-optional.\n const oaiq = window.oaiq;\n\n const email = getFirst(user_data?.email)?.trim().toLowerCase() || undefined;\n const phone = getFirst(user_data?.phone_number);\n const address = getFirst(user_data?.address);\n\n const base: OAIQUser = {\n country: address?.country?.trim().toUpperCase(),\n city: address?.city?.trim(),\n region: address?.region?.trim(),\n postal_code: address?.postal_code?.trim(),\n };\n\n const init = (hashed: Partial<OAIQUser>) => {\n oaiq('init', { pixelId, user: clean({ ...base, ...hashed }) });\n };\n\n const hash = (value: string | undefined) => (value ? sha256(value) : undefined);\n Promise.all([\n hash(email),\n hash(phone ? normalizeOAIPhone(phone) : undefined),\n hash(user_id?.trim()),\n hash(normalizeOAIName(address?.first_name)),\n hash(normalizeOAIName(address?.last_name)),\n ])\n .then(([email_sha256, phone_number_sha256, external_id_sha256, first, last]) =>\n init({\n email_sha256,\n phone_number_sha256,\n external_id_sha256,\n first_name_sha256: first,\n last_name_sha256: last,\n })\n )\n .catch(() => init({}));\n };\n}\n\n/** OpenAI measurement pixel: the events `mapOAIEvent` maps to a standard event, and `customEvents`. */\nexport function openaiAds(options: { pixelId: string } & AdsOptions): Integration {\n const isStandard = (name: string) => mapOAIEvent(name as TrackName).type !== 'custom';\n return {\n type: 'ads',\n track: adsTracker(sendOpenAIEvent, isStandard, options.customEvents ?? []),\n setUser: setOpenAIUser(options.pixelId),\n script: {\n id: 'openai-pixel',\n inline: `\n (function (w, d, s, u) {\n if (w.oaiq) return;\n var q = function () {\n q.q.push(arguments);\n };\n q.q = [];\n w.oaiq = q;\n var js = d.createElement(s);\n js.async = true;\n js.src = u;\n var f = d.getElementsByTagName(s)[0];\n f.parentNode.insertBefore(js, f);\n })(window, document, \"script\", \"https://bzrcdn.openai.com/sdk/oaiq.min.js\");\n oaiq(\"init\", { pixelId: ${JSON.stringify(options.pixelId)} });\n oaiq(\"measure\", \"page_viewed\", { type: \"contents\" });\n `,\n },\n };\n}\n"],"mappings":";;;;;;AAyBA,SAAS,MAAM,OAAqB;CAClC,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AACzC;;;;;;AAOA,SAAgB,gBACd,MACA,YACA,SACA;CACA,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;EACjD,QAAQ,KAAK,+BAA+B;EAC5C,OAAO;CACT;CACA,IAAI,cAAc,SAAS,IAAI,GAAG;CAClC,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAChD,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAEhD,MAAM,EAAE,MAAM,SAAS,YAAY,MAAM,UAAU;CAEnD,IAAI,WAAW,SAAS,IAAa,GAAG;CACxC,IAAI,SAAS,UAAU;EAErB,MAAM,oBAAoB,mBAAmB,IAAI;EACjD,IAAI,CAAC,mBAAmB;EACxB,OAAO,KAAK,WAAW,UAAU,MAAM,IAAI,GAAG;GAAE,UAAU;GAAS;EAAkB,CAAC;CACxF,OACE,OAAO,KAAK,WAAW,MAAM,MAAM,IAAI,GAAG,EAAE,UAAU,QAAQ,CAAC;AAEnE;;;;;;;AAQA,SAAgB,cAAc,SAAiB;CAC7C,QAAQ,EAAE,SAAS,gBAAkC;EACnD,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAA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UAAU,QAAQ,OAAO,EAAE;;;EAG9D;CACF;AACF"}
1
+ {"version":3,"file":"openai-pixel.mjs","names":[],"sources":["../../src/third-parties/openai-pixel.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport {\n APP_EVENTS,\n NON_AD_EVENTS,\n type OAIQ,\n type OAIQUser,\n isStandardOAIEvent,\n mapOAIEvent,\n normalizeOAIName,\n normalizeOAIPhone,\n oaiCustomEventName,\n} from '../track/oaiq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\nimport { sha256 } from '../utils/sha256';\nimport { type AdsOptions, type Integration, adEvents, adsTracker } from './integration';\n\ndeclare global {\n interface Window {\n /** Undefined until the OpenAI pixel script has loaded. */\n oaiq?: OAIQ['oaiq'];\n }\n}\n\n/** Drop `undefined` fields so the SDK only receives populated values. */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction clean(value: unknown): any {\n return JSON.parse(JSON.stringify(value));\n}\n\n/**\n * Forward an internal track event to the OpenAI measurement pixel.\n * `eventId` is reused as the OpenAI `event_id` so browser events deduplicate against the\n * Conversions API. https://developers.openai.com/ads/measurement-pixel\n */\nexport function sendOpenAIEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.oaiq) {\n console.warn('oaiq has not been initialized');\n return false;\n }\n if (NON_AD_EVENTS.includes(name)) return;\n if (window.location.host.includes('127.0.0.1')) return;\n if (window.location.host.includes('localhost')) return;\n\n const { type, data } = mapOAIEvent(name, properties);\n // OpenAI takes the app events from the Conversions API only.\n if (APP_EVENTS.includes(type as never)) return;\n if (type === 'custom') {\n // Named as the Conversions API names it, so the two deduplicate; skipped when it cannot be.\n const custom_event_name = oaiCustomEventName(name);\n if (!custom_event_name) return;\n window.oaiq('measure', 'custom', clean(data), { event_id: eventId, custom_event_name });\n } else {\n window.oaiq('measure', type, clean(data), { event_id: eventId });\n }\n}\n\n/**\n * Re-initialize the pixel with hashed user identity for better conversion matching. Email, phone,\n * external id and names are normalized as OpenAI documents and hashed client-side; geographic\n * fields are sent raw. Hashing is asynchronous, so the `init` call is deferred until the digests\n * resolve.\n */\nexport function setOpenAIUser(pixelId: string) {\n return ({ user_id, user_data }: UpdateVisitorDTO) => {\n if (typeof window === 'undefined' || !window.oaiq) {\n console.warn('oaiq has not been initialized');\n return;\n }\n // Capture the narrowed reference so the deferred `init` closure keeps it non-optional.\n const oaiq = window.oaiq;\n\n const email = getFirst(user_data?.email)?.trim().toLowerCase() || undefined;\n const phone = getFirst(user_data?.phone_number);\n const address = getFirst(user_data?.address);\n\n const base: OAIQUser = {\n country: address?.country?.trim().toUpperCase(),\n city: address?.city?.trim(),\n region: address?.region?.trim(),\n postal_code: address?.postal_code?.trim(),\n };\n\n const init = (hashed: Partial<OAIQUser>) => {\n oaiq('init', { pixelId, user: clean({ ...base, ...hashed }) });\n };\n\n const hash = (value: string | undefined) => (value ? sha256(value) : undefined);\n Promise.all([\n hash(email),\n hash(phone ? normalizeOAIPhone(phone) : undefined),\n hash(user_id?.trim()),\n hash(normalizeOAIName(address?.first_name)),\n hash(normalizeOAIName(address?.last_name)),\n ])\n .then(([email_sha256, phone_number_sha256, external_id_sha256, first, last]) =>\n init({\n email_sha256,\n phone_number_sha256,\n external_id_sha256,\n first_name_sha256: first,\n last_name_sha256: last,\n })\n )\n .catch(() => init({}));\n };\n}\n\n/** OpenAI measurement pixel: the events `mapOAIEvent` maps to a standard event, and `customEvents`. */\n/** OpenAI's configuration, shared by `openaiAds` and `openaiConversions` on the server. */\nexport interface OpenAIAdsOptions extends AdsOptions {\n pixelId: string;\n}\n\nexport function openaiAds(options: OpenAIAdsOptions): Integration {\n return {\n type: 'ads',\n track: adsTracker(sendOpenAIEvent, adEvents(isStandardOAIEvent, options.customEvents)),\n setUser: setOpenAIUser(options.pixelId),\n script: {\n id: 'openai-pixel',\n inline: `\n (function (w, d, s, u) {\n if (w.oaiq) return;\n var q = function () {\n q.q.push(arguments);\n };\n q.q = [];\n w.oaiq = q;\n var js = d.createElement(s);\n js.async = true;\n js.src = u;\n var f = d.getElementsByTagName(s)[0];\n f.parentNode.insertBefore(js, f);\n })(window, document, \"script\", \"https://bzrcdn.openai.com/sdk/oaiq.min.js\");\n oaiq(\"init\", { pixelId: ${JSON.stringify(options.pixelId)} });\n oaiq(\"measure\", \"page_viewed\", { type: \"contents\" });\n `,\n },\n };\n}\n"],"mappings":";;;;;;AA0BA,SAAS,MAAM,OAAqB;CAClC,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AACzC;;;;;;AAOA,SAAgB,gBACd,MACA,YACA,SACA;CACA,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;EACjD,QAAQ,KAAK,+BAA+B;EAC5C,OAAO;CACT;CACA,IAAI,cAAc,SAAS,IAAI,GAAG;CAClC,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAChD,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAEhD,MAAM,EAAE,MAAM,SAAS,YAAY,MAAM,UAAU;CAEnD,IAAI,WAAW,SAAS,IAAa,GAAG;CACxC,IAAI,SAAS,UAAU;EAErB,MAAM,oBAAoB,mBAAmB,IAAI;EACjD,IAAI,CAAC,mBAAmB;EACxB,OAAO,KAAK,WAAW,UAAU,MAAM,IAAI,GAAG;GAAE,UAAU;GAAS;EAAkB,CAAC;CACxF,OACE,OAAO,KAAK,WAAW,MAAM,MAAM,IAAI,GAAG,EAAE,UAAU,QAAQ,CAAC;AAEnE;;;;;;;AAQA,SAAgB,cAAc,SAAiB;CAC7C,QAAQ,EAAE,SAAS,gBAAkC;EACnD,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;GACjD,QAAQ,KAAK,+BAA+B;GAC5C;EACF;EAEA,MAAM,OAAO,OAAO;EAEpB,MAAM,QAAQ,SAAS,WAAW,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,YAAY,KAAK,KAAA;EAClE,MAAM,QAAQ,SAAS,WAAW,YAAY;EAC9C,MAAM,UAAU,SAAS,WAAW,OAAO;EAE3C,MAAM,OAAiB;GACrB,SAAS,SAAS,SAAS,KAAK,CAAC,CAAC,YAAY;GAC9C,MAAM,SAAS,MAAM,KAAK;GAC1B,QAAQ,SAAS,QAAQ,KAAK;GAC9B,aAAa,SAAS,aAAa,KAAK;EAC1C;EAEA,MAAM,QAAQ,WAA8B;GAC1C,KAAK,QAAQ;IAAE;IAAS,MAAM,MAAM;KAAE,GAAG;KAAM,GAAG;IAAO,CAAC;GAAE,CAAC;EAC/D;EAEA,MAAM,QAAQ,UAA+B,QAAQ,OAAO,KAAK,IAAI,KAAA;EACrE,QAAQ,IAAI;GACV,KAAK,KAAK;GACV,KAAK,QAAQ,kBAAkB,KAAK,IAAI,KAAA,CAAS;GACjD,KAAK,SAAS,KAAK,CAAC;GACpB,KAAK,iBAAiB,SAAS,UAAU,CAAC;GAC1C,KAAK,iBAAiB,SAAS,SAAS,CAAC;EAC3C,CAAC,CAAC,CACC,MAAM,CAAC,cAAc,qBAAqB,oBAAoB,OAAO,UACpE,KAAK;GACH;GACA;GACA;GACA,mBAAmB;GACnB,kBAAkB;EACpB,CAAC,CACH,CAAC,CACA,YAAY,KAAK,CAAC,CAAC,CAAC;CACzB;AACF;AAQA,SAAgB,UAAU,SAAwC;CAChE,OAAO;EACL,MAAM;EACN,OAAO,WAAW,iBAAiB,SAAS,oBAAoB,QAAQ,YAAY,CAAC;EACrF,SAAS,cAAc,QAAQ,OAAO;EACtC,QAAQ;GACN,IAAI;GACJ,QAAQ;;;;;;;;;;;;;;kCAcoB,KAAK,UAAU,QAAQ,OAAO,EAAE;;;EAG9D;CACF;AACF"}
@@ -36,13 +36,11 @@ function setRedditUser(pixelId) {
36
36
  });
37
37
  };
38
38
  }
39
- /** Reddit Pixel: the events `mapRDTEvent` maps to a Reddit standard event, and `customEvents`. */
40
39
  function redditAds(options) {
41
- const isStandard = (name) => require_track_rdt.mapRDTEvent(name)[0] !== "Custom";
42
40
  const src = `https://www.redditstatic.com/ads/pixel.js?pixel_id=${encodeURIComponent(options.pixelId)}`;
43
41
  return {
44
42
  type: "ads",
45
- track: require_third_parties_integration.adsTracker(sendRedditEvent, isStandard, options.customEvents ?? []),
43
+ track: require_third_parties_integration.adsTracker(sendRedditEvent, require_third_parties_integration.adEvents(require_track_rdt.isStandardRDTEvent, options.customEvents)),
46
44
  setUser: setRedditUser(options.pixelId),
47
45
  script: {
48
46
  id: "reddit-pixel",
@@ -1 +1 @@
1
- {"version":3,"file":"reddit-pixel.cjs","names":["mapRDTEvent","getFirst","adsTracker"],"sources":["../../src/third-parties/reddit-pixel.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport { type PixelId, type RDT, mapRDTEvent } from '../track/rdt';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\nimport { type AdsOptions, type Integration, adsTracker } from './integration';\n\ndeclare global {\n interface Window {\n /** Undefined until the Reddit Pixel script has loaded. */\n rdt?: RDT['rdt'];\n }\n}\n\nconst metrics = ['CLS', 'FCP', 'FID', 'INP', 'LCP', 'TTFB'];\n\nexport function sendRedditEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.rdt) {\n console.warn('rdt has not been initialized');\n return false;\n }\n if (metrics.includes(name)) return;\n if (window.location.host.includes('127.0.0.1')) return;\n if (window.location.host.includes('localhost')) return;\n\n const [type, params] = mapRDTEvent(name, properties, eventId);\n // The two branches are identical on purpose: `rdt('track', ...)` is overloaded — a standard\n // event name carries its own params type, 'Custom' carries `CustomEventParams` — and what\n // `mapRDTEvent` returns is a union of both. Narrowing `type` is what picks a single overload.\n if (type === 'Custom') {\n window.rdt('track', type, JSON.parse(JSON.stringify(params)));\n } else {\n window.rdt('track', type, JSON.parse(JSON.stringify(params)));\n }\n}\n\nexport function setRedditUser(pixelId: PixelId) {\n return ({ user_id, user_data }: UpdateVisitorDTO) => {\n if (typeof window === 'undefined' || !window.rdt) {\n console.warn('rdt has not been initialized');\n return;\n }\n\n window.rdt('init', pixelId, {\n email: getFirst(user_data?.email),\n phoneNumber: getFirst(user_data?.phone_number),\n externalId: user_id,\n });\n };\n}\n\n/** Reddit Pixel: the events `mapRDTEvent` maps to a Reddit standard event, and `customEvents`. */\nexport function redditAds(options: { pixelId: PixelId } & AdsOptions): Integration {\n const isStandard = (name: string) => mapRDTEvent(name as TrackName)[0] !== 'Custom';\n // As the Ads console's tag: the pixel loads with its id.\n const src = `https://www.redditstatic.com/ads/pixel.js?pixel_id=${encodeURIComponent(options.pixelId)}`;\n return {\n type: 'ads',\n track: adsTracker(sendRedditEvent, isStandard, options.customEvents ?? []),\n setUser: setRedditUser(options.pixelId),\n script: {\n id: 'reddit-pixel',\n inline: `\n !function(w,d) {\n if(!w.rdt) {\n var p = w.rdt = function() {\n p.sendEvent ? p.sendEvent.apply(p,arguments) : p.callQueue.push(arguments)\n };\n p.callQueue = [];\n var t = d.createElement(\"script\");\n t.src = ${JSON.stringify(src)};\n t.async = !0;\n var s = d.getElementsByTagName(\"script\")[0];\n s.parentNode.insertBefore(t,s)\n }\n }(window, document);\n rdt('init', ${JSON.stringify(options.pixelId)});\n rdt('track', 'PageVisit');\n `,\n },\n };\n}\n"],"mappings":";;;;;AAaA,MAAM,UAAU;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;AAAM;AAE1D,SAAgB,gBACd,MACA,YACA,SACA;CACA,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;EAChD,QAAQ,KAAK,8BAA8B;EAC3C,OAAO;CACT;CACA,IAAI,QAAQ,SAAS,IAAI,GAAG;CAC5B,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAChD,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAEhD,MAAM,CAAC,MAAM,UAAUA,kBAAAA,YAAY,MAAM,YAAY,OAAO;CAI5D,IAAI,SAAS,UACX,OAAO,IAAI,SAAS,MAAM,KAAK,MAAM,KAAK,UAAU,MAAM,CAAC,CAAC;MAE5D,OAAO,IAAI,SAAS,MAAM,KAAK,MAAM,KAAK,UAAU,MAAM,CAAC,CAAC;AAEhE;AAEA,SAAgB,cAAc,SAAkB;CAC9C,QAAQ,EAAE,SAAS,gBAAkC;EACnD,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;GAChD,QAAQ,KAAK,8BAA8B;GAC3C;EACF;EAEA,OAAO,IAAI,QAAQ,SAAS;GAC1B,OAAOC,oBAAAA,SAAS,WAAW,KAAK;GAChC,aAAaA,oBAAAA,SAAS,WAAW,YAAY;GAC7C,YAAY;EACd,CAAC;CACH;AACF;;AAGA,SAAgB,UAAU,SAAyD;CACjF,MAAM,cAAc,SAAiBD,kBAAAA,YAAY,IAAiB,CAAC,CAAC,OAAO;CAE3E,MAAM,MAAM,sDAAsD,mBAAmB,QAAQ,OAAO;CACpG,OAAO;EACL,MAAM;EACN,OAAOE,kCAAAA,WAAW,iBAAiB,YAAY,QAAQ,gBAAgB,CAAC,CAAC;EACzE,SAAS,cAAc,QAAQ,OAAO;EACtC,QAAQ;GACN,IAAI;GACJ,QAAQ;;;;;;;;sBAQQ,KAAK,UAAU,GAAG,EAAE;;;;;;sBAMpB,KAAK,UAAU,QAAQ,OAAO,EAAE;;;EAGlD;CACF;AACF"}
1
+ {"version":3,"file":"reddit-pixel.cjs","names":["mapRDTEvent","getFirst","adsTracker","adEvents","isStandardRDTEvent"],"sources":["../../src/third-parties/reddit-pixel.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport { type PixelId, type RDT, isStandardRDTEvent, mapRDTEvent } from '../track/rdt';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { getFirst } from '../utils/field';\nimport { type AdsOptions, type Integration, adEvents, adsTracker } from './integration';\n\ndeclare global {\n interface Window {\n /** Undefined until the Reddit Pixel script has loaded. */\n rdt?: RDT['rdt'];\n }\n}\n\nconst metrics = ['CLS', 'FCP', 'FID', 'INP', 'LCP', 'TTFB'];\n\nexport function sendRedditEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.rdt) {\n console.warn('rdt has not been initialized');\n return false;\n }\n if (metrics.includes(name)) return;\n if (window.location.host.includes('127.0.0.1')) return;\n if (window.location.host.includes('localhost')) return;\n\n const [type, params] = mapRDTEvent(name, properties, eventId);\n // The two branches are identical on purpose: `rdt('track', ...)` is overloaded — a standard\n // event name carries its own params type, 'Custom' carries `CustomEventParams` — and what\n // `mapRDTEvent` returns is a union of both. Narrowing `type` is what picks a single overload.\n if (type === 'Custom') {\n window.rdt('track', type, JSON.parse(JSON.stringify(params)));\n } else {\n window.rdt('track', type, JSON.parse(JSON.stringify(params)));\n }\n}\n\nexport function setRedditUser(pixelId: PixelId) {\n return ({ user_id, user_data }: UpdateVisitorDTO) => {\n if (typeof window === 'undefined' || !window.rdt) {\n console.warn('rdt has not been initialized');\n return;\n }\n\n window.rdt('init', pixelId, {\n email: getFirst(user_data?.email),\n phoneNumber: getFirst(user_data?.phone_number),\n externalId: user_id,\n });\n };\n}\n\n/** Reddit Pixel: the events `mapRDTEvent` maps to a Reddit standard event, and `customEvents`. */\n/** Reddit's configuration, shared by `redditAds` and `redditConversions` on the server. */\nexport interface RedditAdsOptions extends AdsOptions {\n pixelId: PixelId;\n}\n\nexport function redditAds(options: RedditAdsOptions): Integration {\n // As the Ads console's tag: the pixel loads with its id.\n const src = `https://www.redditstatic.com/ads/pixel.js?pixel_id=${encodeURIComponent(options.pixelId)}`;\n return {\n type: 'ads',\n track: adsTracker(sendRedditEvent, adEvents(isStandardRDTEvent, options.customEvents)),\n setUser: setRedditUser(options.pixelId),\n script: {\n id: 'reddit-pixel',\n inline: `\n !function(w,d) {\n if(!w.rdt) {\n var p = w.rdt = function() {\n p.sendEvent ? p.sendEvent.apply(p,arguments) : p.callQueue.push(arguments)\n };\n p.callQueue = [];\n var t = d.createElement(\"script\");\n t.src = ${JSON.stringify(src)};\n t.async = !0;\n var s = d.getElementsByTagName(\"script\")[0];\n s.parentNode.insertBefore(t,s)\n }\n }(window, document);\n rdt('init', ${JSON.stringify(options.pixelId)});\n rdt('track', 'PageVisit');\n `,\n },\n };\n}\n"],"mappings":";;;;;AAaA,MAAM,UAAU;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;AAAM;AAE1D,SAAgB,gBACd,MACA,YACA,SACA;CACA,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;EAChD,QAAQ,KAAK,8BAA8B;EAC3C,OAAO;CACT;CACA,IAAI,QAAQ,SAAS,IAAI,GAAG;CAC5B,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAChD,IAAI,OAAO,SAAS,KAAK,SAAS,WAAW,GAAG;CAEhD,MAAM,CAAC,MAAM,UAAUA,kBAAAA,YAAY,MAAM,YAAY,OAAO;CAI5D,IAAI,SAAS,UACX,OAAO,IAAI,SAAS,MAAM,KAAK,MAAM,KAAK,UAAU,MAAM,CAAC,CAAC;MAE5D,OAAO,IAAI,SAAS,MAAM,KAAK,MAAM,KAAK,UAAU,MAAM,CAAC,CAAC;AAEhE;AAEA,SAAgB,cAAc,SAAkB;CAC9C,QAAQ,EAAE,SAAS,gBAAkC;EACnD,IAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;GAChD,QAAQ,KAAK,8BAA8B;GAC3C;EACF;EAEA,OAAO,IAAI,QAAQ,SAAS;GAC1B,OAAOC,oBAAAA,SAAS,WAAW,KAAK;GAChC,aAAaA,oBAAAA,SAAS,WAAW,YAAY;GAC7C,YAAY;EACd,CAAC;CACH;AACF;AAQA,SAAgB,UAAU,SAAwC;CAEhE,MAAM,MAAM,sDAAsD,mBAAmB,QAAQ,OAAO;CACpG,OAAO;EACL,MAAM;EACN,OAAOC,kCAAAA,WAAW,iBAAiBC,kCAAAA,SAASC,kBAAAA,oBAAoB,QAAQ,YAAY,CAAC;EACrF,SAAS,cAAc,QAAQ,OAAO;EACtC,QAAQ;GACN,IAAI;GACJ,QAAQ;;;;;;;;sBAQQ,KAAK,UAAU,GAAG,EAAE;;;;;;sBAMpB,KAAK,UAAU,QAAQ,OAAO,EAAE;;;EAGlD;CACF;AACF"}
@@ -11,7 +11,9 @@ declare global {
11
11
  export declare function sendRedditEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, eventId?: string): false | undefined;
12
12
  export declare function setRedditUser(pixelId: PixelId): ({ user_id, user_data }: UpdateVisitorDTO) => void;
13
13
  /** Reddit Pixel: the events `mapRDTEvent` maps to a Reddit standard event, and `customEvents`. */
14
- export declare function redditAds(options: {
14
+ /** Reddit's configuration, shared by `redditAds` and `redditConversions` on the server. */
15
+ export interface RedditAdsOptions extends AdsOptions {
15
16
  pixelId: PixelId;
16
- } & AdsOptions): Integration;
17
+ }
18
+ export declare function redditAds(options: RedditAdsOptions): Integration;
17
19
  //# sourceMappingURL=reddit-pixel.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reddit-pixel.d.cts","names":[],"sources":["../../src/third-parties/reddit-pixel.ts"],"mappings":";;;;QAMQ;YACI;;IAER,MAAM;;;wBAMM,gBAAgB,UAAU,WACxC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;wBAqBc,cAAc,SAAS,aAAO,SAAA,aACZ;;wBAelB,UAAU;EAAW,SAAS;IAAY,aAAa"}
1
+ {"version":3,"file":"reddit-pixel.d.cts","names":[],"sources":["../../src/third-parties/reddit-pixel.ts"],"mappings":";;;;QAMQ;YACI;;IAER,MAAM;;;wBAMM,gBAAgB,UAAU,WACxC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;wBAqBc,cAAc,SAAS,aAAO,SAAA,aACZ;;;iBAgBjB,yBAAyB;EACxC,SAAS;;wBAGK,UAAU,SAAS,mBAAmB"}
@@ -11,7 +11,9 @@ declare global {
11
11
  export declare function sendRedditEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, eventId?: string): false | undefined;
12
12
  export declare function setRedditUser(pixelId: PixelId): ({ user_id, user_data }: UpdateVisitorDTO) => void;
13
13
  /** Reddit Pixel: the events `mapRDTEvent` maps to a Reddit standard event, and `customEvents`. */
14
- export declare function redditAds(options: {
14
+ /** Reddit's configuration, shared by `redditAds` and `redditConversions` on the server. */
15
+ export interface RedditAdsOptions extends AdsOptions {
15
16
  pixelId: PixelId;
16
- } & AdsOptions): Integration;
17
+ }
18
+ export declare function redditAds(options: RedditAdsOptions): Integration;
17
19
  //# sourceMappingURL=reddit-pixel.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reddit-pixel.d.mts","names":[],"sources":["../../src/third-parties/reddit-pixel.ts"],"mappings":";;;;QAMQ;YACI;;IAER,MAAM;;;wBAMM,gBAAgB,UAAU,WACxC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;wBAqBc,cAAc,SAAS,aAAO,SAAA,aACZ;;wBAelB,UAAU;EAAW,SAAS;IAAY,aAAa"}
1
+ {"version":3,"file":"reddit-pixel.d.mts","names":[],"sources":["../../src/third-parties/reddit-pixel.ts"],"mappings":";;;;QAMQ;YACI;;IAER,MAAM;;;wBAMM,gBAAgB,UAAU,WACxC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;wBAqBc,cAAc,SAAS,aAAO,SAAA,aACZ;;;iBAgBjB,yBAAyB;EACxC,SAAS;;wBAGK,UAAU,SAAS,mBAAmB"}
@@ -1,6 +1,6 @@
1
1
  import { getFirst } from "../utils/field.mjs";
2
- import { adsTracker } from "./integration.mjs";
3
- import { mapRDTEvent } from "../track/rdt.mjs";
2
+ import { adEvents, adsTracker } from "./integration.mjs";
3
+ import { isStandardRDTEvent, mapRDTEvent } from "../track/rdt.mjs";
4
4
  // src/third-parties/reddit-pixel.ts
5
5
  const metrics = [
6
6
  "CLS",
@@ -35,13 +35,11 @@ function setRedditUser(pixelId) {
35
35
  });
36
36
  };
37
37
  }
38
- /** Reddit Pixel: the events `mapRDTEvent` maps to a Reddit standard event, and `customEvents`. */
39
38
  function redditAds(options) {
40
- const isStandard = (name) => mapRDTEvent(name)[0] !== "Custom";
41
39
  const src = `https://www.redditstatic.com/ads/pixel.js?pixel_id=${encodeURIComponent(options.pixelId)}`;
42
40
  return {
43
41
  type: "ads",
44
- track: adsTracker(sendRedditEvent, isStandard, options.customEvents ?? []),
42
+ track: adsTracker(sendRedditEvent, adEvents(isStandardRDTEvent, options.customEvents)),
45
43
  setUser: setRedditUser(options.pixelId),
46
44
  script: {
47
45
  id: "reddit-pixel",