@shware/analytics 15.0.1 → 16.0.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 +89 -36
  2. package/dist/native/fbsdk.cjs +45 -1
  3. package/dist/native/fbsdk.cjs.map +1 -1
  4. package/dist/native/fbsdk.d.cts +23 -1
  5. package/dist/native/fbsdk.d.cts.map +1 -1
  6. package/dist/native/fbsdk.d.mts +23 -1
  7. package/dist/native/fbsdk.d.mts.map +1 -1
  8. package/dist/native/fbsdk.mjs +44 -2
  9. package/dist/native/fbsdk.mjs.map +1 -1
  10. package/dist/native/firebase.cjs +27 -0
  11. package/dist/native/firebase.cjs.map +1 -1
  12. package/dist/native/firebase.d.cts +11 -0
  13. package/dist/native/firebase.d.cts.map +1 -1
  14. package/dist/native/firebase.d.mts +11 -0
  15. package/dist/native/firebase.d.mts.map +1 -1
  16. package/dist/native/firebase.mjs +27 -2
  17. package/dist/native/firebase.mjs.map +1 -1
  18. package/dist/next/index.cjs +10 -123
  19. package/dist/next/index.cjs.map +1 -1
  20. package/dist/next/index.d.cts +2 -31
  21. package/dist/next/index.d.cts.map +1 -1
  22. package/dist/next/index.d.mts +2 -31
  23. package/dist/next/index.d.mts.map +1 -1
  24. package/dist/next/index.mjs +10 -123
  25. package/dist/next/index.mjs.map +1 -1
  26. package/dist/react/index.cjs +45 -0
  27. package/dist/react/index.cjs.map +1 -0
  28. package/dist/react/index.d.cts +15 -0
  29. package/dist/react/index.d.cts.map +1 -0
  30. package/dist/react/index.d.mts +15 -0
  31. package/dist/react/index.d.mts.map +1 -0
  32. package/dist/react/index.mjs +43 -0
  33. package/dist/react/index.mjs.map +1 -0
  34. package/dist/react/use-feature-flag.cjs +23 -0
  35. package/dist/react/use-feature-flag.cjs.map +1 -0
  36. package/dist/react/use-feature-flag.d.cts +10 -0
  37. package/dist/react/use-feature-flag.d.cts.map +1 -0
  38. package/dist/react/use-feature-flag.d.mts +10 -0
  39. package/dist/react/use-feature-flag.d.mts.map +1 -0
  40. package/dist/react/use-feature-flag.mjs +22 -0
  41. package/dist/react/use-feature-flag.mjs.map +1 -0
  42. package/dist/server/reddit-conversions-api.d.cts +1 -1
  43. package/dist/server/reddit-conversions-api.d.mts +1 -1
  44. package/dist/setup/index.cjs +4 -4
  45. package/dist/setup/index.cjs.map +1 -1
  46. package/dist/setup/index.d.cts +16 -6
  47. package/dist/setup/index.d.cts.map +1 -1
  48. package/dist/setup/index.d.mts +16 -6
  49. package/dist/setup/index.d.mts.map +1 -1
  50. package/dist/setup/index.mjs +4 -4
  51. package/dist/setup/index.mjs.map +1 -1
  52. package/dist/tanstack/index.cjs +0 -2
  53. package/dist/tanstack/index.d.cts +1 -2
  54. package/dist/tanstack/index.d.mts +1 -2
  55. package/dist/tanstack/index.mjs +1 -3
  56. package/dist/third-parties/analytics-props.cjs +28 -0
  57. package/dist/third-parties/analytics-props.cjs.map +1 -0
  58. package/dist/third-parties/analytics-props.d.cts +23 -0
  59. package/dist/third-parties/analytics-props.d.cts.map +1 -0
  60. package/dist/third-parties/analytics-props.d.mts +23 -0
  61. package/dist/third-parties/analytics-props.d.mts.map +1 -0
  62. package/dist/third-parties/analytics-props.mjs +26 -0
  63. package/dist/third-parties/analytics-props.mjs.map +1 -0
  64. package/dist/third-parties/google-analytics.cjs +32 -0
  65. package/dist/third-parties/google-analytics.cjs.map +1 -1
  66. package/dist/third-parties/google-analytics.d.cts +11 -1
  67. package/dist/third-parties/google-analytics.d.cts.map +1 -1
  68. package/dist/third-parties/google-analytics.d.mts +11 -1
  69. package/dist/third-parties/google-analytics.d.mts.map +1 -1
  70. package/dist/third-parties/google-analytics.mjs +32 -1
  71. package/dist/third-parties/google-analytics.mjs.map +1 -1
  72. package/dist/third-parties/index.cjs +16 -0
  73. package/dist/third-parties/index.d.cts +9 -7
  74. package/dist/third-parties/index.d.mts +9 -7
  75. package/dist/third-parties/index.mjs +9 -7
  76. package/dist/third-parties/integration.cjs +39 -0
  77. package/dist/third-parties/integration.cjs.map +1 -0
  78. package/dist/third-parties/integration.d.cts +57 -0
  79. package/dist/third-parties/integration.d.cts.map +1 -0
  80. package/dist/third-parties/integration.d.mts +57 -0
  81. package/dist/third-parties/integration.d.mts.map +1 -0
  82. package/dist/third-parties/integration.mjs +37 -0
  83. package/dist/third-parties/integration.mjs.map +1 -0
  84. package/dist/third-parties/linkedin-insight-tag.cjs +33 -0
  85. package/dist/third-parties/linkedin-insight-tag.cjs.map +1 -1
  86. package/dist/third-parties/linkedin-insight-tag.d.cts +12 -8
  87. package/dist/third-parties/linkedin-insight-tag.d.cts.map +1 -1
  88. package/dist/third-parties/linkedin-insight-tag.d.mts +12 -8
  89. package/dist/third-parties/linkedin-insight-tag.d.mts.map +1 -1
  90. package/dist/third-parties/linkedin-insight-tag.mjs +33 -1
  91. package/dist/third-parties/linkedin-insight-tag.mjs.map +1 -1
  92. package/dist/third-parties/meta-pixel.cjs +34 -0
  93. package/dist/third-parties/meta-pixel.cjs.map +1 -1
  94. package/dist/third-parties/meta-pixel.d.cts +5 -0
  95. package/dist/third-parties/meta-pixel.d.cts.map +1 -1
  96. package/dist/third-parties/meta-pixel.d.mts +5 -0
  97. package/dist/third-parties/meta-pixel.d.mts.map +1 -1
  98. package/dist/third-parties/meta-pixel.mjs +34 -1
  99. package/dist/third-parties/meta-pixel.mjs.map +1 -1
  100. package/dist/third-parties/microsoft-uet.cjs +49 -0
  101. package/dist/third-parties/microsoft-uet.cjs.map +1 -1
  102. package/dist/third-parties/microsoft-uet.d.cts +29 -0
  103. package/dist/third-parties/microsoft-uet.d.cts.map +1 -1
  104. package/dist/third-parties/microsoft-uet.d.mts +29 -0
  105. package/dist/third-parties/microsoft-uet.d.mts.map +1 -1
  106. package/dist/third-parties/microsoft-uet.mjs +48 -1
  107. package/dist/third-parties/microsoft-uet.mjs.map +1 -1
  108. package/dist/third-parties/openai-pixel.cjs +31 -0
  109. package/dist/third-parties/openai-pixel.cjs.map +1 -1
  110. package/dist/third-parties/openai-pixel.d.cts +5 -0
  111. package/dist/third-parties/openai-pixel.d.cts.map +1 -1
  112. package/dist/third-parties/openai-pixel.d.mts +5 -0
  113. package/dist/third-parties/openai-pixel.d.mts.map +1 -1
  114. package/dist/third-parties/openai-pixel.mjs +31 -1
  115. package/dist/third-parties/openai-pixel.mjs.map +1 -1
  116. package/dist/third-parties/posthog.cjs +97 -4
  117. package/dist/third-parties/posthog.cjs.map +1 -1
  118. package/dist/third-parties/posthog.d.cts +56 -1
  119. package/dist/third-parties/posthog.d.cts.map +1 -1
  120. package/dist/third-parties/posthog.d.mts +56 -1
  121. package/dist/third-parties/posthog.d.mts.map +1 -1
  122. package/dist/third-parties/posthog.mjs +91 -2
  123. package/dist/third-parties/posthog.mjs.map +1 -1
  124. package/dist/third-parties/reddit-pixel.cjs +32 -0
  125. package/dist/third-parties/reddit-pixel.cjs.map +1 -1
  126. package/dist/third-parties/reddit-pixel.d.cts +5 -0
  127. package/dist/third-parties/reddit-pixel.d.cts.map +1 -1
  128. package/dist/third-parties/reddit-pixel.d.mts +5 -0
  129. package/dist/third-parties/reddit-pixel.d.mts.map +1 -1
  130. package/dist/third-parties/reddit-pixel.mjs +32 -1
  131. package/dist/third-parties/reddit-pixel.mjs.map +1 -1
  132. package/dist/track/fbq.cjs +1 -1
  133. package/dist/track/fbq.cjs.map +1 -1
  134. package/dist/track/fbq.mjs +1 -1
  135. package/dist/track/fbq.mjs.map +1 -1
  136. package/dist/track/index.cjs +7 -7
  137. package/dist/track/index.cjs.map +1 -1
  138. package/dist/track/index.d.cts.map +1 -1
  139. package/dist/track/index.d.mts.map +1 -1
  140. package/dist/track/index.mjs +7 -7
  141. package/dist/track/index.mjs.map +1 -1
  142. package/dist/visitor/index.cjs +3 -3
  143. package/dist/visitor/index.cjs.map +1 -1
  144. package/dist/visitor/index.mjs +3 -3
  145. package/dist/visitor/index.mjs.map +1 -1
  146. package/package.json +11 -24
  147. package/dist/react-router/index.cjs +0 -160
  148. package/dist/react-router/index.cjs.map +0 -1
  149. package/dist/react-router/index.d.cts +0 -22
  150. package/dist/react-router/index.d.cts.map +0 -1
  151. package/dist/react-router/index.d.mts +0 -22
  152. package/dist/react-router/index.d.mts.map +0 -1
  153. package/dist/react-router/index.mjs +0 -159
  154. package/dist/react-router/index.mjs.map +0 -1
  155. package/dist/tanstack/analytics.cjs +0 -184
  156. package/dist/tanstack/analytics.cjs.map +0 -1
  157. package/dist/tanstack/analytics.d.cts +0 -33
  158. package/dist/tanstack/analytics.d.cts.map +0 -1
  159. package/dist/tanstack/analytics.d.mts +0 -33
  160. package/dist/tanstack/analytics.d.mts.map +0 -1
  161. package/dist/tanstack/analytics.mjs +0 -183
  162. package/dist/tanstack/analytics.mjs.map +0 -1
@@ -1,5 +1,6 @@
1
1
  import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
2
2
  import { UpdateVisitorDTO } from "../schema/index.cjs";
3
+ import { AdsOptions, Integration } from "./integration.cjs";
3
4
  import { FBQ, PixelId } from "../track/fbq.cjs";
4
5
  declare global {
5
6
  interface Window {
@@ -9,4 +10,8 @@ declare global {
9
10
  }
10
11
  export declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, event_id?: string): false | undefined;
11
12
  export declare function setFBUser(pixelId: PixelId): ({ user_id, user_data }: UpdateVisitorDTO) => void;
13
+ /** Meta Pixel: the events `mapFBEvent` maps to a Meta standard event, and `customEvents`. */
14
+ export declare function metaAds(options: {
15
+ pixelId: PixelId;
16
+ } & AdsOptions): Integration;
12
17
  //# sourceMappingURL=meta-pixel.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"meta-pixel.d.cts","names":[],"sources":["../../src/third-parties/meta-pixel.ts"],"mappings":";;;QAKQ;YACI;;IAER,MAAM;;;wBAMM,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;wBAuBc,UAAU,SAAS,aAAO,SAAA,aACR"}
1
+ {"version":3,"file":"meta-pixel.d.cts","names":[],"sources":["../../src/third-parties/meta-pixel.ts"],"mappings":";;;;QAMQ;YACI;;IAER,MAAM;;;wBAMM,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;wBAuBc,UAAU,SAAS,aAAO,SAAA,aACR;;wBAwBlB,QAAQ;EAAW,SAAS;IAAY,aAAa"}
@@ -1,5 +1,6 @@
1
1
  import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
2
2
  import { UpdateVisitorDTO } from "../schema/index.mjs";
3
+ import { AdsOptions, Integration } from "./integration.mjs";
3
4
  import { FBQ, PixelId } from "../track/fbq.mjs";
4
5
  declare global {
5
6
  interface Window {
@@ -9,4 +10,8 @@ declare global {
9
10
  }
10
11
  export declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, event_id?: string): false | undefined;
11
12
  export declare function setFBUser(pixelId: PixelId): ({ user_id, user_data }: UpdateVisitorDTO) => void;
13
+ /** Meta Pixel: the events `mapFBEvent` maps to a Meta standard event, and `customEvents`. */
14
+ export declare function metaAds(options: {
15
+ pixelId: PixelId;
16
+ } & AdsOptions): Integration;
12
17
  //# sourceMappingURL=meta-pixel.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"meta-pixel.d.mts","names":[],"sources":["../../src/third-parties/meta-pixel.ts"],"mappings":";;;QAKQ;YACI;;IAER,MAAM;;;wBAMM,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;wBAuBc,UAAU,SAAS,aAAO,SAAA,aACR"}
1
+ {"version":3,"file":"meta-pixel.d.mts","names":[],"sources":["../../src/third-parties/meta-pixel.ts"],"mappings":";;;;QAMQ;YACI;;IAER,MAAM;;;wBAMM,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;wBAuBc,UAAU,SAAS,aAAO,SAAA,aACR;;wBAwBlB,QAAQ;EAAW,SAAS;IAAY,aAAa"}
@@ -1,4 +1,5 @@
1
1
  import { getFirst } from "../utils/field.mjs";
2
+ import { adsTracker } from "./integration.mjs";
2
3
  import { mapFBEvent } from "../track/fbq.mjs";
3
4
  // src/third-parties/meta-pixel.ts
4
5
  const metrics = [
@@ -42,6 +43,38 @@ function setFBUser(pixelId) {
42
43
  });
43
44
  };
44
45
  }
45
- export { sendFBEvent, setFBUser };
46
+ /** Meta Pixel: the events `mapFBEvent` maps to a Meta standard event, and `customEvents`. */
47
+ function metaAds(options) {
48
+ const isStandard = (name) => mapFBEvent(name)[0] === "track";
49
+ return {
50
+ type: "ads",
51
+ track: adsTracker(sendFBEvent, isStandard, options.customEvents ?? []),
52
+ setUser: setFBUser(options.pixelId),
53
+ script: {
54
+ id: "meta-pixel",
55
+ inline: `
56
+ !(function (f, b, e, v, n, t, s) {
57
+ if (f.fbq) return;
58
+ n = f.fbq = function () {
59
+ n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
60
+ };
61
+ if (!f._fbq) f._fbq = n;
62
+ n.push = n;
63
+ n.loaded = !0;
64
+ n.version = '2.0';
65
+ n.queue = [];
66
+ t = b.createElement(e);
67
+ t.async = !0;
68
+ t.src = v;
69
+ s = b.getElementsByTagName(e)[0];
70
+ s.parentNode.insertBefore(t, s);
71
+ })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
72
+ fbq('init', ${JSON.stringify(options.pixelId)});
73
+ fbq('track', 'PageView');
74
+ `
75
+ }
76
+ };
77
+ }
78
+ export { metaAds, sendFBEvent, setFBUser };
46
79
 
47
80
  //# sourceMappingURL=meta-pixel.mjs.map
@@ -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';\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"],"mappings":";;;AAYA,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"}
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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AQ;;;;;;;;;;;;;;;;;sBAiBQ,KAAK,UAAU,QAAQ,OAAO,EAAE;;;EAGlD;CACF;AACF"}
@@ -3,6 +3,7 @@ const require_visitor_id = require("../visitor/id.cjs");
3
3
  const require_track_uetq = require("../track/uetq.cjs");
4
4
  const require_utils_field = require("../utils/field.cjs");
5
5
  const require_utils_sha256 = require("../utils/sha256.cjs");
6
+ const require_third_parties_integration = require("./integration.cjs");
6
7
  // src/third-parties/microsoft-uet.ts
7
8
  const metrics = [
8
9
  "CLS",
@@ -133,11 +134,59 @@ function sendUETIdSync(options) {
133
134
  }
134
135
  require_utils_sha256.sha256(options.userId).then(fire, () => fire());
135
136
  }
137
+ /** The customer id of the `microsoftAds` integration among these, for `useUETIdSync`. */
138
+ function uetCustomerIdOf(integrations = []) {
139
+ return integrations.find((integration) => "uetCustomerId" in integration)?.uetCustomerId;
140
+ }
141
+ /**
142
+ * Microsoft Advertising UET. UET has no standard events to map to — a conversion goal is defined
143
+ * on an action name in the ads UI — so it receives an explicit list, the GA4 conversion events
144
+ * by default (`CONVERSION_EVENTS`), plus `customEvents`.
145
+ *
146
+ * Its script is Microsoft's UET snippet with `enableAutoSpaTracking: true` (the tag reports page
147
+ * loads itself), the consent mode default pushed inside it so bat.js reads it before the first
148
+ * page load.
149
+ */
150
+ function microsoftAds(options) {
151
+ const events = options.events ?? require_third_parties_integration.CONVERSION_EVENTS;
152
+ const consent = options.consent ?? { ad_storage: "granted" };
153
+ const defaults = consent ? `w[u].push("consent", "default", ${JSON.stringify(consent)});` : "";
154
+ return {
155
+ type: "ads",
156
+ track: require_third_parties_integration.adsTracker(sendUETEvent, (name) => events.includes(name), options.customEvents ?? []),
157
+ setUser: setUETUser,
158
+ script: {
159
+ id: "uet-tag",
160
+ inline: `
161
+ (function (w, d, t, u, o) {
162
+ w[u] = w[u] || [], o.ts = (new Date).getTime();
163
+ ${defaults}
164
+ var n = d.createElement(t);
165
+ n.src = "https://bat.bing.net/bat.js?ti=" + o.ti + ("uetq" != u ? "&q=" + u : ""),
166
+ n.async = 1, n.onload = n.onreadystatechange = function() {
167
+ var s = this.readyState;
168
+ s && "loaded" !== s && "complete" !== s ||
169
+ (o.q = w[u], w[u] = new UET(o), w[u].push("pageLoad"),
170
+ n.onload = n.onreadystatechange = null)
171
+ };
172
+ var i = d.getElementsByTagName(t)[0];
173
+ i.parentNode.insertBefore(n, i);
174
+ })(window, document, "script", "uetq", {
175
+ ti: ${JSON.stringify(options.tagId)},
176
+ enableAutoSpaTracking: true
177
+ });
178
+ `
179
+ },
180
+ uetCustomerId: options.customerId
181
+ };
182
+ }
136
183
  exports.configureUET = configureUET;
184
+ exports.microsoftAds = microsoftAds;
137
185
  exports.sendUETEvent = sendUETEvent;
138
186
  exports.sendUETIdSync = sendUETIdSync;
139
187
  exports.setUETConsent = setUETConsent;
140
188
  exports.setUETUser = setUETUser;
141
189
  exports.syncUETVisitor = syncUETVisitor;
190
+ exports.uetCustomerIdOf = uetCustomerIdOf;
142
191
 
143
192
  //# sourceMappingURL=microsoft-uet.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"microsoft-uet.cjs","names":["mapUETEvent","getFirst","visitorId"],"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';\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"],"mappings":";;;;;;AAiBA,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;CAEhB,OAAO,KAAK,KAAK,OAAO,EAAE,KAAK,MAAM;EAAE;EAAI;CAAG,CAAC,EAAE,CAAC;AACpD;;;;;;;AAQA,SAAgB,cAAc,MAA4B,SAAqB;CAC7E,IAAI,OAAO,WAAW,aAAa;CACnC,OAAO,SAAS,CAAC;CACjB,OAAO,KAAK,KAAK,WAAW,MAAM,OAAO;AAC3C;;;;;;;;;;;;;;;;;;;;;;AAuBA,IAAI;AAEJ,SAAgB,aAAa,SAA2C;CACtE,gBAAgB,QAAQ,eAAe,KAAA,IAAY,KAAA,IAAY,OAAO,QAAQ,UAAU;AAC1F;;;;;;;AAQA,eAAsB,eAAe,QAAgC;CACnE,IAAI,CAAC,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"}
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)},\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ACA,eAAe,QAAQ;CACzB;AACF"}
@@ -1,5 +1,6 @@
1
1
  import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
2
2
  import { UpdateVisitorDTO } from "../schema/index.cjs";
3
+ import { AdsOptions, Integration } from "./integration.cjs";
3
4
  import { UETConsent, UETQ } from "../track/uetq.cjs";
4
5
  declare global {
5
6
  interface Window {
@@ -58,4 +59,32 @@ export declare function sendUETIdSync(options: {
58
59
  /** The signed-in user's id, raw; hashed before it leaves the page. */
59
60
  userId?: string;
60
61
  }): void;
62
+ /** What `microsoftAds` returns: an integration that also names the customer id for ID Sync. */
63
+ export type MicrosoftAdsIntegration = Integration & {
64
+ readonly uetCustomerId?: `${number}`;
65
+ };
66
+ /** The customer id of the `microsoftAds` integration among these, for `useUETIdSync`. */
67
+ export declare function uetCustomerIdOf(integrations?: readonly Integration[]): `${number}` | undefined;
68
+ /**
69
+ * Microsoft Advertising UET. UET has no standard events to map to — a conversion goal is defined
70
+ * on an action name in the ads UI — so it receives an explicit list, the GA4 conversion events
71
+ * by default (`CONVERSION_EVENTS`), plus `customEvents`.
72
+ *
73
+ * Its script is Microsoft's UET snippet with `enableAutoSpaTracking: true` (the tag reports page
74
+ * loads itself), the consent mode default pushed inside it so bat.js reads it before the first
75
+ * page load.
76
+ */
77
+ export declare function microsoftAds(options: {
78
+ tagId: `${number}`;
79
+ /** Microsoft Advertising customer id (`cid` in the ads UI's URLs): enables the ID Sync pixel. */
80
+ customerId?: `${number}`;
81
+ /**
82
+ * The UET consent mode default, `ad_storage: granted` unless given: how the tag behaves
83
+ * without a signal, so Microsoft stops flagging EEA/UK/CH events as missing consent. Sites
84
+ * with a consent banner pass `{ ad_storage: 'denied' }` and send `update` with
85
+ * `setUETConsent`; `false` pushes no default. https://help.ads.microsoft.com/#apex/ads/en/60119/1
86
+ */
87
+ consent?: UETConsent | false;
88
+ events?: readonly EventName[];
89
+ } & AdsOptions): MicrosoftAdsIntegration;
61
90
  //# 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":";;;QAOQ;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"}
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,5 +1,6 @@
1
1
  import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
2
2
  import { UpdateVisitorDTO } from "../schema/index.mjs";
3
+ import { AdsOptions, Integration } from "./integration.mjs";
3
4
  import { UETConsent, UETQ } from "../track/uetq.mjs";
4
5
  declare global {
5
6
  interface Window {
@@ -58,4 +59,32 @@ export declare function sendUETIdSync(options: {
58
59
  /** The signed-in user's id, raw; hashed before it leaves the page. */
59
60
  userId?: string;
60
61
  }): void;
62
+ /** What `microsoftAds` returns: an integration that also names the customer id for ID Sync. */
63
+ export type MicrosoftAdsIntegration = Integration & {
64
+ readonly uetCustomerId?: `${number}`;
65
+ };
66
+ /** The customer id of the `microsoftAds` integration among these, for `useUETIdSync`. */
67
+ export declare function uetCustomerIdOf(integrations?: readonly Integration[]): `${number}` | undefined;
68
+ /**
69
+ * Microsoft Advertising UET. UET has no standard events to map to — a conversion goal is defined
70
+ * on an action name in the ads UI — so it receives an explicit list, the GA4 conversion events
71
+ * by default (`CONVERSION_EVENTS`), plus `customEvents`.
72
+ *
73
+ * Its script is Microsoft's UET snippet with `enableAutoSpaTracking: true` (the tag reports page
74
+ * loads itself), the consent mode default pushed inside it so bat.js reads it before the first
75
+ * page load.
76
+ */
77
+ export declare function microsoftAds(options: {
78
+ tagId: `${number}`;
79
+ /** Microsoft Advertising customer id (`cid` in the ads UI's URLs): enables the ID Sync pixel. */
80
+ customerId?: `${number}`;
81
+ /**
82
+ * The UET consent mode default, `ad_storage: granted` unless given: how the tag behaves
83
+ * without a signal, so Microsoft stops flagging EEA/UK/CH events as missing consent. Sites
84
+ * with a consent banner pass `{ ad_storage: 'denied' }` and send `update` with
85
+ * `setUETConsent`; `false` pushes no default. https://help.ads.microsoft.com/#apex/ads/en/60119/1
86
+ */
87
+ consent?: UETConsent | false;
88
+ events?: readonly EventName[];
89
+ } & AdsOptions): MicrosoftAdsIntegration;
61
90
  //# 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":";;;QAOQ;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"}
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"}
@@ -2,6 +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
6
  // src/third-parties/microsoft-uet.ts
6
7
  const metrics = [
7
8
  "CLS",
@@ -132,6 +133,52 @@ function sendUETIdSync(options) {
132
133
  }
133
134
  sha256(options.userId).then(fire, () => fire());
134
135
  }
135
- export { configureUET, sendUETEvent, sendUETIdSync, setUETConsent, setUETUser, syncUETVisitor };
136
+ /** The customer id of the `microsoftAds` integration among these, for `useUETIdSync`. */
137
+ function uetCustomerIdOf(integrations = []) {
138
+ return integrations.find((integration) => "uetCustomerId" in integration)?.uetCustomerId;
139
+ }
140
+ /**
141
+ * Microsoft Advertising UET. UET has no standard events to map to — a conversion goal is defined
142
+ * on an action name in the ads UI — so it receives an explicit list, the GA4 conversion events
143
+ * by default (`CONVERSION_EVENTS`), plus `customEvents`.
144
+ *
145
+ * Its script is Microsoft's UET snippet with `enableAutoSpaTracking: true` (the tag reports page
146
+ * loads itself), the consent mode default pushed inside it so bat.js reads it before the first
147
+ * page load.
148
+ */
149
+ function microsoftAds(options) {
150
+ const events = options.events ?? CONVERSION_EVENTS;
151
+ const consent = options.consent ?? { ad_storage: "granted" };
152
+ const defaults = consent ? `w[u].push("consent", "default", ${JSON.stringify(consent)});` : "";
153
+ return {
154
+ type: "ads",
155
+ track: adsTracker(sendUETEvent, (name) => events.includes(name), options.customEvents ?? []),
156
+ setUser: setUETUser,
157
+ script: {
158
+ id: "uet-tag",
159
+ inline: `
160
+ (function (w, d, t, u, o) {
161
+ w[u] = w[u] || [], o.ts = (new Date).getTime();
162
+ ${defaults}
163
+ var n = d.createElement(t);
164
+ n.src = "https://bat.bing.net/bat.js?ti=" + o.ti + ("uetq" != u ? "&q=" + u : ""),
165
+ n.async = 1, n.onload = n.onreadystatechange = function() {
166
+ var s = this.readyState;
167
+ s && "loaded" !== s && "complete" !== s ||
168
+ (o.q = w[u], w[u] = new UET(o), w[u].push("pageLoad"),
169
+ n.onload = n.onreadystatechange = null)
170
+ };
171
+ var i = d.getElementsByTagName(t)[0];
172
+ i.parentNode.insertBefore(n, i);
173
+ })(window, document, "script", "uetq", {
174
+ ti: ${JSON.stringify(options.tagId)},
175
+ enableAutoSpaTracking: true
176
+ });
177
+ `
178
+ },
179
+ uetCustomerId: options.customerId
180
+ };
181
+ }
182
+ export { configureUET, microsoftAds, sendUETEvent, sendUETIdSync, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf };
136
183
 
137
184
  //# 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';\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"],"mappings":";;;;;AAiBA,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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ACF;CACA,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;AAChD"}
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,MAAM,KAAK,SAAS,WAAW,YAAY;CAC3C,IAAI,CAAC,MAAM,CAAC,IAAI;CAEhB,OAAO,KAAK,KAAK,OAAO,EAAE,KAAK,MAAM;EAAE;EAAI;CAAG,CAAC,EAAE,CAAC;AACpD;;;;;;;AAQA,SAAgB,cAAc,MAA4B,SAAqB;CAC7E,IAAI,OAAO,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Q;;;YAGF,SAAS;;;;;;;;;;;;gBAYL,KAAK,UAAU,QAAQ,KAAK,EAAE;;;;EAI1C;EACA,eAAe,QAAQ;CACzB;AACF"}
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_utils_field = require("../utils/field.cjs");
3
3
  const require_utils_sha256 = require("../utils/sha256.cjs");
4
+ const require_third_parties_integration = require("./integration.cjs");
4
5
  const require_track_oaiq = require("../track/oaiq.cjs");
5
6
  // src/third-parties/openai-pixel.ts
6
7
  /** Drop `undefined` fields so the SDK only receives populated values. */
@@ -78,6 +79,36 @@ function setOpenAIUser(pixelId) {
78
79
  })).catch(() => init({}));
79
80
  };
80
81
  }
82
+ /** OpenAI measurement pixel: the events `mapOAIEvent` maps to a standard event, and `customEvents`. */
83
+ function openaiAds(options) {
84
+ const isStandard = (name) => require_track_oaiq.mapOAIEvent(name).type !== "custom";
85
+ return {
86
+ type: "ads",
87
+ track: require_third_parties_integration.adsTracker(sendOpenAIEvent, isStandard, options.customEvents ?? []),
88
+ setUser: setOpenAIUser(options.pixelId),
89
+ script: {
90
+ id: "openai-pixel",
91
+ inline: `
92
+ (function (w, d, s, u) {
93
+ if (w.oaiq) return;
94
+ var q = function () {
95
+ q.q.push(arguments);
96
+ };
97
+ q.q = [];
98
+ w.oaiq = q;
99
+ var js = d.createElement(s);
100
+ js.async = true;
101
+ js.src = u;
102
+ var f = d.getElementsByTagName(s)[0];
103
+ f.parentNode.insertBefore(js, f);
104
+ })(window, document, "script", "https://bzrcdn.openai.com/sdk/oaiq.min.js");
105
+ oaiq("init", { pixelId: ${JSON.stringify(options.pixelId)} });
106
+ oaiq("measure", "page_viewed", { type: "contents" });
107
+ `
108
+ }
109
+ };
110
+ }
111
+ exports.openaiAds = openaiAds;
81
112
  exports.sendOpenAIEvent = sendOpenAIEvent;
82
113
  exports.setOpenAIUser = setOpenAIUser;
83
114
 
@@ -1 +1 @@
1
- {"version":3,"file":"openai-pixel.cjs","names":["NON_AD_EVENTS","mapOAIEvent","APP_EVENTS","oaiCustomEventName","getFirst","sha256","normalizeOAIPhone","normalizeOAIName"],"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';\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"],"mappings":";;;;;;AAwBA,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,MA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A,iBAAiB,SAAS,UAAU,CAAC;GAC1C,KAAKA,mBAAAA,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"}
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,EAA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A,YAAY,IAAiB,CAAC,CAAC,SAAS;CAC7E,OAAO;EACL,MAAM;EACN,OAAOO,kCAAAA,WAAW,iBAAiB,YAAY,QAAQ,gBAAgB,CAAC,CAAC;EACzE,SAAS,cAAc,QAAQ,OAAO;EACtC,QAAQ;GACN,IAAI;GACJ,QAAQ;;;;;;;;;;;;;;kCAcoB,KAAK,UAAU,QAAQ,OAAO,EAAE;;;EAG9D;CACF;AACF"}
@@ -1,5 +1,6 @@
1
1
  import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
2
2
  import { UpdateVisitorDTO } from "../schema/index.cjs";
3
+ import { AdsOptions, Integration } from "./integration.cjs";
3
4
  import { OAIQ } from "../track/oaiq.cjs";
4
5
  declare global {
5
6
  interface Window {
@@ -20,4 +21,8 @@ export declare function sendOpenAIEvent<T extends EventName>(name: TrackName<T>,
20
21
  * resolve.
21
22
  */
22
23
  export declare function setOpenAIUser(pixelId: string): ({ user_id, user_data }: UpdateVisitorDTO) => void;
24
+ /** OpenAI measurement pixel: the events `mapOAIEvent` maps to a standard event, and `customEvents`. */
25
+ export declare function openaiAds(options: {
26
+ pixelId: string;
27
+ } & AdsOptions): Integration;
23
28
  //# 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":";;;QAeQ;YACI;;IAER,OAAO;;;;;;;;wBAeK,gBAAgB,UAAU,WACxC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;;;;;;;wBA6Bc,cAAc,qBAAe,SAAA,aACX"}
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,5 +1,6 @@
1
1
  import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
2
2
  import { UpdateVisitorDTO } from "../schema/index.mjs";
3
+ import { AdsOptions, Integration } from "./integration.mjs";
3
4
  import { OAIQ } from "../track/oaiq.mjs";
4
5
  declare global {
5
6
  interface Window {
@@ -20,4 +21,8 @@ export declare function sendOpenAIEvent<T extends EventName>(name: TrackName<T>,
20
21
  * resolve.
21
22
  */
22
23
  export declare function setOpenAIUser(pixelId: string): ({ user_id, user_data }: UpdateVisitorDTO) => void;
24
+ /** OpenAI measurement pixel: the events `mapOAIEvent` maps to a standard event, and `customEvents`. */
25
+ export declare function openaiAds(options: {
26
+ pixelId: string;
27
+ } & AdsOptions): Integration;
23
28
  //# 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":";;;QAeQ;YACI;;IAER,OAAO;;;;;;;;wBAeK,gBAAgB,UAAU,WACxC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;;;;;;;wBA6Bc,cAAc,qBAAe,SAAA,aACX"}
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,5 +1,6 @@
1
1
  import { getFirst } from "../utils/field.mjs";
2
2
  import { sha256 } from "../utils/sha256.mjs";
3
+ import { adsTracker } from "./integration.mjs";
3
4
  import { APP_EVENTS, NON_AD_EVENTS, mapOAIEvent, normalizeOAIName, normalizeOAIPhone, oaiCustomEventName } from "../track/oaiq.mjs";
4
5
  // src/third-parties/openai-pixel.ts
5
6
  /** Drop `undefined` fields so the SDK only receives populated values. */
@@ -77,6 +78,35 @@ function setOpenAIUser(pixelId) {
77
78
  })).catch(() => init({}));
78
79
  };
79
80
  }
80
- export { sendOpenAIEvent, setOpenAIUser };
81
+ /** OpenAI measurement pixel: the events `mapOAIEvent` maps to a standard event, and `customEvents`. */
82
+ function openaiAds(options) {
83
+ const isStandard = (name) => mapOAIEvent(name).type !== "custom";
84
+ return {
85
+ type: "ads",
86
+ track: adsTracker(sendOpenAIEvent, isStandard, options.customEvents ?? []),
87
+ setUser: setOpenAIUser(options.pixelId),
88
+ script: {
89
+ id: "openai-pixel",
90
+ inline: `
91
+ (function (w, d, s, u) {
92
+ if (w.oaiq) return;
93
+ var q = function () {
94
+ q.q.push(arguments);
95
+ };
96
+ q.q = [];
97
+ w.oaiq = q;
98
+ var js = d.createElement(s);
99
+ js.async = true;
100
+ js.src = u;
101
+ var f = d.getElementsByTagName(s)[0];
102
+ f.parentNode.insertBefore(js, f);
103
+ })(window, document, "script", "https://bzrcdn.openai.com/sdk/oaiq.min.js");
104
+ oaiq("init", { pixelId: ${JSON.stringify(options.pixelId)} });
105
+ oaiq("measure", "page_viewed", { type: "contents" });
106
+ `
107
+ }
108
+ };
109
+ }
110
+ export { openaiAds, sendOpenAIEvent, setOpenAIUser };
81
111
 
82
112
  //# sourceMappingURL=openai-pixel.mjs.map