@shware/analytics 16.0.0 → 16.2.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 (200) hide show
  1. package/README.md +90 -5
  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/react/index.cjs +11 -2
  9. package/dist/react/index.cjs.map +1 -1
  10. package/dist/react/index.d.cts +3 -2
  11. package/dist/react/index.d.cts.map +1 -1
  12. package/dist/react/index.d.mts +3 -2
  13. package/dist/react/index.d.mts.map +1 -1
  14. package/dist/react/index.mjs +3 -2
  15. package/dist/react/index.mjs.map +1 -1
  16. package/dist/react/posthog-error-boundary.cjs +119 -0
  17. package/dist/react/posthog-error-boundary.cjs.map +1 -0
  18. package/dist/react/posthog-error-boundary.d.cts +60 -0
  19. package/dist/react/posthog-error-boundary.d.cts.map +1 -0
  20. package/dist/react/posthog-error-boundary.d.mts +60 -0
  21. package/dist/react/posthog-error-boundary.d.mts.map +1 -0
  22. package/dist/react/posthog-error-boundary.mjs +117 -0
  23. package/dist/react/posthog-error-boundary.mjs.map +1 -0
  24. package/dist/react/posthog.cjs +97 -0
  25. package/dist/react/posthog.cjs.map +1 -0
  26. package/dist/react/posthog.d.cts +41 -0
  27. package/dist/react/posthog.d.cts.map +1 -0
  28. package/dist/react/posthog.d.mts +41 -0
  29. package/dist/react/posthog.d.mts.map +1 -0
  30. package/dist/react/posthog.mjs +90 -0
  31. package/dist/react/posthog.mjs.map +1 -0
  32. package/dist/server/conversions-api-error.cjs +20 -0
  33. package/dist/server/conversions-api-error.cjs.map +1 -0
  34. package/dist/server/conversions-api-error.d.cts +17 -0
  35. package/dist/server/conversions-api-error.d.cts.map +1 -0
  36. package/dist/server/conversions-api-error.d.mts +17 -0
  37. package/dist/server/conversions-api-error.d.mts.map +1 -0
  38. package/dist/server/conversions-api-error.mjs +19 -0
  39. package/dist/server/conversions-api-error.mjs.map +1 -0
  40. package/dist/server/google-data-manager.cjs +24 -26
  41. package/dist/server/google-data-manager.cjs.map +1 -1
  42. package/dist/server/google-data-manager.d.cts +13 -5
  43. package/dist/server/google-data-manager.d.cts.map +1 -1
  44. package/dist/server/google-data-manager.d.mts +13 -5
  45. package/dist/server/google-data-manager.d.mts.map +1 -1
  46. package/dist/server/google-data-manager.mjs +24 -27
  47. package/dist/server/google-data-manager.mjs.map +1 -1
  48. package/dist/server/index.cjs +11 -0
  49. package/dist/server/index.d.cts +10 -7
  50. package/dist/server/index.d.mts +10 -7
  51. package/dist/server/index.mjs +9 -7
  52. package/dist/server/linkedin-conversions-api.cjs +29 -23
  53. package/dist/server/linkedin-conversions-api.cjs.map +1 -1
  54. package/dist/server/linkedin-conversions-api.d.cts +7 -2
  55. package/dist/server/linkedin-conversions-api.d.cts.map +1 -1
  56. package/dist/server/linkedin-conversions-api.d.mts +7 -2
  57. package/dist/server/linkedin-conversions-api.d.mts.map +1 -1
  58. package/dist/server/linkedin-conversions-api.mjs +29 -24
  59. package/dist/server/linkedin-conversions-api.mjs.map +1 -1
  60. package/dist/server/meta-capi.cjs +32 -31
  61. package/dist/server/meta-capi.cjs.map +1 -1
  62. package/dist/server/meta-capi.d.cts +12 -3
  63. package/dist/server/meta-capi.d.cts.map +1 -1
  64. package/dist/server/meta-capi.d.mts +12 -3
  65. package/dist/server/meta-capi.d.mts.map +1 -1
  66. package/dist/server/meta-capi.mjs +33 -33
  67. package/dist/server/meta-capi.mjs.map +1 -1
  68. package/dist/server/microsoft-conversions-api.cjs +33 -28
  69. package/dist/server/microsoft-conversions-api.cjs.map +1 -1
  70. package/dist/server/microsoft-conversions-api.d.cts +14 -2
  71. package/dist/server/microsoft-conversions-api.d.cts.map +1 -1
  72. package/dist/server/microsoft-conversions-api.d.mts +14 -2
  73. package/dist/server/microsoft-conversions-api.d.mts.map +1 -1
  74. package/dist/server/microsoft-conversions-api.mjs +33 -29
  75. package/dist/server/microsoft-conversions-api.mjs.map +1 -1
  76. package/dist/server/openai-conversions-api.cjs +20 -18
  77. package/dist/server/openai-conversions-api.cjs.map +1 -1
  78. package/dist/server/openai-conversions-api.d.cts +7 -0
  79. package/dist/server/openai-conversions-api.d.cts.map +1 -1
  80. package/dist/server/openai-conversions-api.d.mts +7 -0
  81. package/dist/server/openai-conversions-api.d.mts.map +1 -1
  82. package/dist/server/openai-conversions-api.mjs +21 -20
  83. package/dist/server/openai-conversions-api.mjs.map +1 -1
  84. package/dist/server/reddit-conversions-api.cjs +20 -18
  85. package/dist/server/reddit-conversions-api.cjs.map +1 -1
  86. package/dist/server/reddit-conversions-api.d.cts +7 -0
  87. package/dist/server/reddit-conversions-api.d.cts.map +1 -1
  88. package/dist/server/reddit-conversions-api.d.mts +7 -0
  89. package/dist/server/reddit-conversions-api.d.mts.map +1 -1
  90. package/dist/server/reddit-conversions-api.mjs +21 -20
  91. package/dist/server/reddit-conversions-api.mjs.map +1 -1
  92. package/dist/server/setup-conversions.cjs +62 -0
  93. package/dist/server/setup-conversions.cjs.map +1 -0
  94. package/dist/server/setup-conversions.d.cts +97 -0
  95. package/dist/server/setup-conversions.d.cts.map +1 -0
  96. package/dist/server/setup-conversions.d.mts +97 -0
  97. package/dist/server/setup-conversions.d.mts.map +1 -0
  98. package/dist/server/setup-conversions.mjs +60 -0
  99. package/dist/server/setup-conversions.mjs.map +1 -0
  100. package/dist/third-parties/index.d.cts +3 -3
  101. package/dist/third-parties/index.d.mts +3 -3
  102. package/dist/third-parties/integration.cjs +13 -6
  103. package/dist/third-parties/integration.cjs.map +1 -1
  104. package/dist/third-parties/integration.d.cts +12 -8
  105. package/dist/third-parties/integration.d.cts.map +1 -1
  106. package/dist/third-parties/integration.d.mts +12 -8
  107. package/dist/third-parties/integration.d.mts.map +1 -1
  108. package/dist/third-parties/integration.mjs +13 -7
  109. package/dist/third-parties/integration.mjs.map +1 -1
  110. package/dist/third-parties/linkedin-insight-tag.cjs +0 -4
  111. package/dist/third-parties/linkedin-insight-tag.cjs.map +1 -1
  112. package/dist/third-parties/linkedin-insight-tag.d.cts +4 -2
  113. package/dist/third-parties/linkedin-insight-tag.d.cts.map +1 -1
  114. package/dist/third-parties/linkedin-insight-tag.d.mts +4 -2
  115. package/dist/third-parties/linkedin-insight-tag.d.mts.map +1 -1
  116. package/dist/third-parties/linkedin-insight-tag.mjs +0 -4
  117. package/dist/third-parties/linkedin-insight-tag.mjs.map +1 -1
  118. package/dist/third-parties/meta-pixel.cjs +1 -3
  119. package/dist/third-parties/meta-pixel.cjs.map +1 -1
  120. package/dist/third-parties/meta-pixel.d.cts +4 -2
  121. package/dist/third-parties/meta-pixel.d.cts.map +1 -1
  122. package/dist/third-parties/meta-pixel.d.mts +4 -2
  123. package/dist/third-parties/meta-pixel.d.mts.map +1 -1
  124. package/dist/third-parties/meta-pixel.mjs +3 -5
  125. package/dist/third-parties/meta-pixel.mjs.map +1 -1
  126. package/dist/third-parties/microsoft-uet.cjs +7 -2
  127. package/dist/third-parties/microsoft-uet.cjs.map +1 -1
  128. package/dist/third-parties/microsoft-uet.d.cts +10 -3
  129. package/dist/third-parties/microsoft-uet.d.cts.map +1 -1
  130. package/dist/third-parties/microsoft-uet.d.mts +10 -3
  131. package/dist/third-parties/microsoft-uet.d.mts.map +1 -1
  132. package/dist/third-parties/microsoft-uet.mjs +8 -4
  133. package/dist/third-parties/microsoft-uet.mjs.map +1 -1
  134. package/dist/third-parties/openai-pixel.cjs +1 -3
  135. package/dist/third-parties/openai-pixel.cjs.map +1 -1
  136. package/dist/third-parties/openai-pixel.d.cts +4 -2
  137. package/dist/third-parties/openai-pixel.d.cts.map +1 -1
  138. package/dist/third-parties/openai-pixel.d.mts +4 -2
  139. package/dist/third-parties/openai-pixel.d.mts.map +1 -1
  140. package/dist/third-parties/openai-pixel.mjs +3 -5
  141. package/dist/third-parties/openai-pixel.mjs.map +1 -1
  142. package/dist/third-parties/posthog.cjs +3 -3
  143. package/dist/third-parties/posthog.cjs.map +1 -1
  144. package/dist/third-parties/posthog.d.cts +3 -3
  145. package/dist/third-parties/posthog.d.mts +3 -3
  146. package/dist/third-parties/posthog.mjs +3 -3
  147. package/dist/third-parties/posthog.mjs.map +1 -1
  148. package/dist/third-parties/reddit-pixel.cjs +1 -3
  149. package/dist/third-parties/reddit-pixel.cjs.map +1 -1
  150. package/dist/third-parties/reddit-pixel.d.cts +4 -2
  151. package/dist/third-parties/reddit-pixel.d.cts.map +1 -1
  152. package/dist/third-parties/reddit-pixel.d.mts +4 -2
  153. package/dist/third-parties/reddit-pixel.d.mts.map +1 -1
  154. package/dist/third-parties/reddit-pixel.mjs +3 -5
  155. package/dist/third-parties/reddit-pixel.mjs.map +1 -1
  156. package/dist/track/fbq.cjs +5 -0
  157. package/dist/track/fbq.cjs.map +1 -1
  158. package/dist/track/fbq.d.cts +2 -0
  159. package/dist/track/fbq.d.cts.map +1 -1
  160. package/dist/track/fbq.d.mts +2 -0
  161. package/dist/track/fbq.d.mts.map +1 -1
  162. package/dist/track/fbq.mjs +5 -1
  163. package/dist/track/fbq.mjs.map +1 -1
  164. package/dist/track/oaiq.cjs +5 -0
  165. package/dist/track/oaiq.cjs.map +1 -1
  166. package/dist/track/oaiq.d.cts +2 -0
  167. package/dist/track/oaiq.d.cts.map +1 -1
  168. package/dist/track/oaiq.d.mts +2 -0
  169. package/dist/track/oaiq.d.mts.map +1 -1
  170. package/dist/track/oaiq.mjs +5 -1
  171. package/dist/track/oaiq.mjs.map +1 -1
  172. package/dist/track/rdt.cjs +5 -0
  173. package/dist/track/rdt.cjs.map +1 -1
  174. package/dist/track/rdt.d.cts +2 -0
  175. package/dist/track/rdt.d.cts.map +1 -1
  176. package/dist/track/rdt.d.mts +2 -0
  177. package/dist/track/rdt.d.mts.map +1 -1
  178. package/dist/track/rdt.mjs +5 -1
  179. package/dist/track/rdt.mjs.map +1 -1
  180. package/package.json +1 -16
  181. package/dist/react/use-feature-flag.cjs +0 -23
  182. package/dist/react/use-feature-flag.cjs.map +0 -1
  183. package/dist/react/use-feature-flag.d.cts +0 -10
  184. package/dist/react/use-feature-flag.d.cts.map +0 -1
  185. package/dist/react/use-feature-flag.d.mts +0 -10
  186. package/dist/react/use-feature-flag.d.mts.map +0 -1
  187. package/dist/react/use-feature-flag.mjs +0 -22
  188. package/dist/react/use-feature-flag.mjs.map +0 -1
  189. package/dist/server/legacy.cjs +0 -3
  190. package/dist/server/legacy.d.cts +0 -2
  191. package/dist/server/legacy.d.mts +0 -2
  192. package/dist/server/legacy.mjs +0 -1
  193. package/dist/server/meta-conversions-api.cjs +0 -205
  194. package/dist/server/meta-conversions-api.cjs.map +0 -1
  195. package/dist/server/meta-conversions-api.d.cts +0 -8
  196. package/dist/server/meta-conversions-api.d.cts.map +0 -1
  197. package/dist/server/meta-conversions-api.d.mts +0 -8
  198. package/dist/server/meta-conversions-api.d.mts.map +0 -1
  199. package/dist/server/meta-conversions-api.mjs +0 -201
  200. package/dist/server/meta-conversions-api.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"fbq.mjs","names":["p"],"sources":["../../src/track/fbq.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-empty-object-type */\nimport { type Item, itemKey } from './gtag';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\nexport type Content = {\n id: string;\n quantity: number;\n item_price?: number;\n title?: string;\n description?: string;\n brand?: string;\n category?: string;\n delivery_category?: string;\n};\n\n/**\n * reference: https://developers.facebook.com/docs/meta-pixel/advanced/advanced-matching\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters\n */\nexport type MatchingParameters = {\n /** Email: Unhashed lowercase or hashed SHA-256 */\n em?: string;\n\n /** First Name: Lowercase letters */\n fn?: string;\n\n /** Last Name: Lowercase letters */\n ln?: string;\n\n /** Phone Number: Digits only including country code and area code */\n ph?: string;\n\n /**\n * External ID: Any unique ID from the advertiser, such as loyalty membership ID, user ID, and\n * external cookie ID.\n */\n external_id?: string;\n\n /** Gender: Single lowercase letter, f or m, if unknown, leave blank */\n ge?: 'f' | 'm' | '';\n\n /** Birthdate: Digits only with birth year, month, then day, YYYYMMDD */\n db?: number;\n\n /** City: Lowercase with any spaces removed, e.g. \"menlopark\" */\n ct?: string;\n\n /** State or Province: Lowercase two-letter state or province code, e.g. \"ca\" */\n st?: string;\n\n /** Zip or Postal Code: String */\n zp?: string;\n\n /** Country: Lowercase two-letter country code, e.g. \"us\" */\n country?: string;\n\n /** Client IP Address: Do not hash. */\n client_ip_address?: string;\n\n /** Client User Agent: Do not hash. */\n client_user_agent?: string;\n\n /**\n * Click ID: Do not hash.\n * The Facebook click ID value is stored in the _fbc browser cookie under your domain. See\n * Managing fbc and fbp Parameters for how to get this value or generate this value from a fbclid\n * query parameter.\n *\n * The format is fb.${subdomain_index}.${creation_time}.${fbclid}.\n */\n fbc?: string;\n\n /**\n * Browser ID: Do not hash.\n * The Facebook browser ID value is stored in the _fbp browser cookie under your domain. See\n * Managing fbc and fbp Parameters for how to get this value.\n *\n * The format is fb.${subdomain_index}.${creation_time}.${random_number}.\n */\n fbp?: string;\n\n /**\n * Subscription ID: Do not hash.\n * The subscription ID for the user in this transaction; it is similar to the order ID for an\n * individual product.\n */\n subscription_id?: string;\n\n /**\n * Facebook Login ID: Do not hash.\n * The ID issued by Meta when a person first logs into an instance of an app. This is also known\n * as App-Scoped ID.\n */\n fb_login_id?: number;\n\n /**\n * Lead ID: Do not hash.\n * The ID associated with a lead generated by [Meta's Lead Ads](https://developers.facebook.com/docs/marketing-api/guides/lead-ads).\n */\n lead_id?: number;\n\n /**\n * Install ID: Do not hash.\n * Your install ID. This field represents unique application installation instances.\n * Note: This parameter is for app events only.\n */\n anon_id?: string;\n\n /**\n * Your mobile advertiser ID, the advertising ID from an Android device or the Advertising\n * Identifier (IDFA) from an Apple device.\n */\n madid?: string;\n\n /**\n * Page ID: Do not hash.\n * Your Page ID. Specifies the page ID associated with the event. Use the Facebook page ID of the\n * page associated with the bot.\n */\n page_id?: string;\n\n /**\n * Page Scoped User ID: Do not hash.\n * Specifies the page-scoped user ID associated with the messenger bot that logs the event. Use\n * the page-scoped user ID provided to your webhook.\n */\n page_scoped_user_id?: string;\n\n /**\n * Do not hash.\n * Click ID generated by Meta for ads that click to WhatsApp.\n */\n ctwa_clid?: string;\n\n /**\n * Do not hash.\n * Instagram Account ID that is associated with the business.\n */\n ig_account_id?: string;\n\n /**\n * Do not hash.\n * Users who interact with Instagram are identified by Instagram-Scoped User IDs (IGSID). IGSID\n * can be obtained from this webhook.\n */\n ig_sid?: string;\n};\n\n/**\n * You can include the following predefined object properties with any custom events, and any\n * standard events that support them. Format your parameter object data using JSON. Learn more about\n * event parameters with Blueprint.\n */\nexport type ObjectProperties = {\n content_category?: string;\n content_ids?: string[];\n content_name?: string;\n\n /**\n * Either product or product_group based on the content_ids or contents being passed. If the IDs\n * being passed in content_ids or contents parameter are IDs of products, then the value should be\n * product. If product group IDs are being passed, then the value should be product_group.\n *\n * If no content_type is provided, Meta will match the event to every item that has the same ID,\n * independent of its type.\n */\n content_type?: 'product' | 'product_group' | (string & {});\n contents?: Content[];\n delivery_category?: 'in_store' | 'curbside' | 'home_delivery';\n currency?: string;\n num_items?: number;\n predicted_ltv?: number;\n search_string?: string;\n\n /** Used with the CompleteRegistration event, to show the status of the registration. */\n status?: boolean;\n value?: number;\n};\n\n/**\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/payload-helper\n */\nexport type StandardEvents = {\n AddPaymentInfo: {\n content_ids?: string[];\n contents?: Content[];\n currency?: string;\n value?: number;\n };\n AddToCart: {\n content_ids?: string[];\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents\n currency?: string;\n value?: number;\n };\n AddToWishlist: {\n content_ids?: string[];\n contents?: Content[];\n currency?: string;\n value?: number;\n };\n CompleteRegistration: {\n currency?: string;\n value?: number;\n method?: string;\n };\n Contact: {};\n CustomizeProduct: {};\n Donate: {};\n FindLocation: {};\n InitiateCheckout: {\n content_ids?: string[];\n contents?: Content[];\n currency?: string;\n num_items?: number;\n value?: number;\n };\n Lead: {\n currency?: string;\n value?: number;\n };\n Purchase: {\n content_ids?: string[]; // Required for Advantage+ catalog ads: contents or content_ids\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents or content_ids\n currency: string; // required\n num_items?: number;\n value: number; // required\n };\n Schedule: {};\n Search: {\n content_ids?: string[]; // Required for Advantage+ catalog ads: contents or content_ids\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents or content_ids\n currency?: string;\n search_string?: string;\n value?: number;\n };\n StartTrial: {\n currency?: string;\n predicted_ltv?: number;\n value?: number;\n };\n SubmitApplication: {};\n Subscribe: {\n currency?: string;\n predicted_ltv?: number;\n value?: number;\n };\n ViewContent: {\n content_ids?: string[]; // Required for Advantage+ catalog ads: contents or content_ids\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents or content_ids\n currency?: string;\n value?: number;\n };\n};\n\ntype JSONValue =\n | null\n | string\n | number\n | boolean\n | Array<JSONValue>\n | { [value: string]: JSONValue };\n\nexport type PixelId = `${number}`;\nexport type Options = { eventID?: string };\n\n/**\n * reference: https://developers.facebook.com/docs/meta-pixel/reference#standard-events\n *\n * We determine if events are identical based on their ID and name. So, for an event to be deduplicated:\n * - In corresponding events, a Meta Pixel's eventID must match the Conversion API's event_id.\n * - In corresponding events, a Meta Pixel's event must match the Conversion API's event_name.\n *\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters\n */\nexport interface FBQ {\n /**\n * reference: https://stackoverflow.com/questions/62304291/sending-user-data-parameters-via-pixel\n *\n * Call init the normal default way first:\n * `fbq('init', 'XXXXX')`\n *\n * And at a later point in time, when you have obtained additional user data, you can call init\n * again basically enriching the already running fbq instance with additional data:\n * `fbq('init', 'XXXXX', { external_id: 1234, em: 'abc@abc.com' } )`\n *\n * Only caveat is that you have to send an event after this additional init call, otherwise the\n * provided data will not be sent to Facebook.\n */\n fbq(type: 'init', pixelId: PixelId, parameters?: MatchingParameters): void;\n\n /** Enable Manual Only mode. (value = false) */\n fbq(type: 'set', key: 'autoConfig', value: boolean, pixelId: PixelId): void;\n\n fbq<T extends keyof StandardEvents>(\n type: 'track',\n event: T,\n properties?: StandardEvents[T] & ObjectProperties,\n options?: Options\n ): void;\n\n fbq(\n type: 'trackCustom',\n event: string,\n properties?: Record<string, JSONValue> & ObjectProperties,\n options?: Options\n ): void;\n\n /** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */\n fbq<T extends keyof StandardEvents>(\n type: 'trackSingle',\n pixelId: PixelId,\n event: T,\n properties?: StandardEvents[T] & ObjectProperties,\n options?: Options\n ): void;\n\n /** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */\n fbq(\n type: 'trackSingleCustom',\n pixelId: PixelId,\n event: string,\n properties?: Record<string, JSONValue> & ObjectProperties,\n options?: Options\n ): void;\n}\n\n/**\n * Please download this CSV filefor examples of properly normalized and hashed data for the\n * parameters below.\n */\nexport function normalize(parameters: MatchingParameters): MatchingParameters {\n return {\n ...parameters,\n em: parameters.em?.toLowerCase().trim(),\n ph: parameters.ph?.replace(/[-+()\\s]/g, '').replace(/^0+/, ''),\n zp: parameters.zp?.split('-').at(0)?.trim(),\n fn: parameters.fn?.toLowerCase().trim(),\n ln: parameters.ln?.toLowerCase().trim(),\n ct: parameters.ct?.toLowerCase().replace(/[\\s/-]/g, ''),\n st: parameters.st?.toLowerCase().replace(/[\\s/,.-]/g, ''),\n country: parameters.country?.toLowerCase().replace(/[\\s/-]/g, ''),\n };\n}\n\nexport function mapItems(items?: Item[]): ObjectProperties {\n if (!items) return {};\n const categories = Array.from(new Set(items.map((i) => i.item_category).filter(Boolean)));\n const contents: Content[] = items.map((item) => {\n const { quantity, price, item_name, item_brand, item_category } = item;\n return {\n id: itemKey(item),\n quantity: quantity ?? 1,\n item_price: price,\n title: item_name,\n brand: item_brand,\n category: item_category,\n };\n });\n\n return {\n content_category: categories.length === 1 ? categories.at(0) : undefined,\n contents,\n content_ids: contents.map((c) => c.id),\n num_items: items.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n };\n}\n\ntype Mapped<F extends keyof StandardEvents> = ['track', F, StandardEvents[F] & ObjectProperties];\ntype Missed<F extends string> = ['trackCustom', F, Record<string, JSONValue> & ObjectProperties];\n\nexport function mapFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n): Mapped<keyof StandardEvents> | Missed<TrackName<T>> {\n if (name === 'add_payment_info') {\n const p = properties as TrackProperties<'add_payment_info'> | undefined;\n return [\n 'track',\n 'AddPaymentInfo',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n ];\n } else if (name === 'add_to_cart') {\n const p = properties as TrackProperties<'add_to_cart'> | undefined;\n return [\n 'track',\n 'AddToCart',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n ];\n } else if (name === 'add_to_wishlist') {\n const p = properties as TrackProperties<'add_to_wishlist'> | undefined;\n return [\n 'track',\n 'AddToWishlist',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n ];\n } else if (name === 'sign_up' || name === 'login') {\n const p = properties as TrackProperties<'sign_up' | 'login'> | undefined;\n return ['track', 'CompleteRegistration', { method: p?.method }];\n } else if (name === 'contact') {\n return ['track', 'Contact', {}];\n } else if (name === 'customize_product') {\n return ['track', 'CustomizeProduct', {}];\n } else if (name === 'donate') {\n return ['track', 'Donate', {}];\n } else if (name === 'find_location') {\n return ['track', 'FindLocation', {}];\n } else if (name === 'begin_checkout') {\n const p = properties as TrackProperties<'begin_checkout'> | undefined;\n return [\n 'track',\n 'InitiateCheckout',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n ];\n } else if (name === 'generate_lead') {\n const p = properties as TrackProperties<'generate_lead'> | undefined;\n return ['track', 'Lead', { currency: p?.currency, value: p?.value }];\n } else if (name === 'purchase') {\n const p = properties as TrackProperties<'purchase'> | undefined;\n return [\n 'track',\n 'Purchase',\n { currency: p?.currency ?? 'USD', value: p?.value ?? 0, ...mapItems(p?.items) },\n ];\n } else if (name === 'schedule') {\n return ['track', 'Schedule', {}];\n } else if (name === 'search') {\n const p = properties as TrackProperties<'search'> | undefined;\n return ['track', 'Search', { search_string: p?.search_term }];\n } else if (name === 'trial_begin') {\n const p = properties as TrackProperties<'trial_begin'> | undefined;\n return ['track', 'StartTrial', { currency: p?.currency, value: p?.value }];\n } else if (name === 'submit_application') {\n return ['track', 'SubmitApplication', {}];\n } else if (name === 'subscribe') {\n const p = properties as TrackProperties<'subscribe'> | undefined;\n return ['track', 'Subscribe', { currency: p?.currency, value: p?.value }];\n } else if (name === 'view_item') {\n const p = properties as TrackProperties<'view_item'> | undefined;\n return [\n 'track',\n 'ViewContent',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n ];\n } else {\n return ['trackCustom', name, properties ?? {}];\n }\n}\n"],"mappings":";;;;;;AA+UA,SAAgB,UAAU,YAAoD;CAC5E,OAAO;EACL,GAAG;EACH,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,KAAK;EACtC,IAAI,WAAW,IAAI,QAAQ,aAAa,EAAE,CAAC,CAAC,QAAQ,OAAO,EAAE;EAC7D,IAAI,WAAW,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK;EAC1C,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,KAAK;EACtC,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,KAAK;EACtC,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,QAAQ,WAAW,EAAE;EACtD,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,QAAQ,aAAa,EAAE;EACxD,SAAS,WAAW,SAAS,YAAY,CAAC,CAAC,QAAQ,WAAW,EAAE;CAClE;AACF;AAEA,SAAgB,S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AAM,cAAc,CAAC;CAAC;AAEjD"}
1
+ {"version":3,"file":"fbq.mjs","names":["p"],"sources":["../../src/track/fbq.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-empty-object-type */\nimport { type Item, itemKey } from './gtag';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\nexport type Content = {\n id: string;\n quantity: number;\n item_price?: number;\n title?: string;\n description?: string;\n brand?: string;\n category?: string;\n delivery_category?: string;\n};\n\n/**\n * reference: https://developers.facebook.com/docs/meta-pixel/advanced/advanced-matching\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters\n */\nexport type MatchingParameters = {\n /** Email: Unhashed lowercase or hashed SHA-256 */\n em?: string;\n\n /** First Name: Lowercase letters */\n fn?: string;\n\n /** Last Name: Lowercase letters */\n ln?: string;\n\n /** Phone Number: Digits only including country code and area code */\n ph?: string;\n\n /**\n * External ID: Any unique ID from the advertiser, such as loyalty membership ID, user ID, and\n * external cookie ID.\n */\n external_id?: string;\n\n /** Gender: Single lowercase letter, f or m, if unknown, leave blank */\n ge?: 'f' | 'm' | '';\n\n /** Birthdate: Digits only with birth year, month, then day, YYYYMMDD */\n db?: number;\n\n /** City: Lowercase with any spaces removed, e.g. \"menlopark\" */\n ct?: string;\n\n /** State or Province: Lowercase two-letter state or province code, e.g. \"ca\" */\n st?: string;\n\n /** Zip or Postal Code: String */\n zp?: string;\n\n /** Country: Lowercase two-letter country code, e.g. \"us\" */\n country?: string;\n\n /** Client IP Address: Do not hash. */\n client_ip_address?: string;\n\n /** Client User Agent: Do not hash. */\n client_user_agent?: string;\n\n /**\n * Click ID: Do not hash.\n * The Facebook click ID value is stored in the _fbc browser cookie under your domain. See\n * Managing fbc and fbp Parameters for how to get this value or generate this value from a fbclid\n * query parameter.\n *\n * The format is fb.${subdomain_index}.${creation_time}.${fbclid}.\n */\n fbc?: string;\n\n /**\n * Browser ID: Do not hash.\n * The Facebook browser ID value is stored in the _fbp browser cookie under your domain. See\n * Managing fbc and fbp Parameters for how to get this value.\n *\n * The format is fb.${subdomain_index}.${creation_time}.${random_number}.\n */\n fbp?: string;\n\n /**\n * Subscription ID: Do not hash.\n * The subscription ID for the user in this transaction; it is similar to the order ID for an\n * individual product.\n */\n subscription_id?: string;\n\n /**\n * Facebook Login ID: Do not hash.\n * The ID issued by Meta when a person first logs into an instance of an app. This is also known\n * as App-Scoped ID.\n */\n fb_login_id?: number;\n\n /**\n * Lead ID: Do not hash.\n * The ID associated with a lead generated by [Meta's Lead Ads](https://developers.facebook.com/docs/marketing-api/guides/lead-ads).\n */\n lead_id?: number;\n\n /**\n * Install ID: Do not hash.\n * Your install ID. This field represents unique application installation instances.\n * Note: This parameter is for app events only.\n */\n anon_id?: string;\n\n /**\n * Your mobile advertiser ID, the advertising ID from an Android device or the Advertising\n * Identifier (IDFA) from an Apple device.\n */\n madid?: string;\n\n /**\n * Page ID: Do not hash.\n * Your Page ID. Specifies the page ID associated with the event. Use the Facebook page ID of the\n * page associated with the bot.\n */\n page_id?: string;\n\n /**\n * Page Scoped User ID: Do not hash.\n * Specifies the page-scoped user ID associated with the messenger bot that logs the event. Use\n * the page-scoped user ID provided to your webhook.\n */\n page_scoped_user_id?: string;\n\n /**\n * Do not hash.\n * Click ID generated by Meta for ads that click to WhatsApp.\n */\n ctwa_clid?: string;\n\n /**\n * Do not hash.\n * Instagram Account ID that is associated with the business.\n */\n ig_account_id?: string;\n\n /**\n * Do not hash.\n * Users who interact with Instagram are identified by Instagram-Scoped User IDs (IGSID). IGSID\n * can be obtained from this webhook.\n */\n ig_sid?: string;\n};\n\n/**\n * You can include the following predefined object properties with any custom events, and any\n * standard events that support them. Format your parameter object data using JSON. Learn more about\n * event parameters with Blueprint.\n */\nexport type ObjectProperties = {\n content_category?: string;\n content_ids?: string[];\n content_name?: string;\n\n /**\n * Either product or product_group based on the content_ids or contents being passed. If the IDs\n * being passed in content_ids or contents parameter are IDs of products, then the value should be\n * product. If product group IDs are being passed, then the value should be product_group.\n *\n * If no content_type is provided, Meta will match the event to every item that has the same ID,\n * independent of its type.\n */\n content_type?: 'product' | 'product_group' | (string & {});\n contents?: Content[];\n delivery_category?: 'in_store' | 'curbside' | 'home_delivery';\n currency?: string;\n num_items?: number;\n predicted_ltv?: number;\n search_string?: string;\n\n /** Used with the CompleteRegistration event, to show the status of the registration. */\n status?: boolean;\n value?: number;\n};\n\n/**\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/payload-helper\n */\nexport type StandardEvents = {\n AddPaymentInfo: {\n content_ids?: string[];\n contents?: Content[];\n currency?: string;\n value?: number;\n };\n AddToCart: {\n content_ids?: string[];\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents\n currency?: string;\n value?: number;\n };\n AddToWishlist: {\n content_ids?: string[];\n contents?: Content[];\n currency?: string;\n value?: number;\n };\n CompleteRegistration: {\n currency?: string;\n value?: number;\n method?: string;\n };\n Contact: {};\n CustomizeProduct: {};\n Donate: {};\n FindLocation: {};\n InitiateCheckout: {\n content_ids?: string[];\n contents?: Content[];\n currency?: string;\n num_items?: number;\n value?: number;\n };\n Lead: {\n currency?: string;\n value?: number;\n };\n Purchase: {\n content_ids?: string[]; // Required for Advantage+ catalog ads: contents or content_ids\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents or content_ids\n currency: string; // required\n num_items?: number;\n value: number; // required\n };\n Schedule: {};\n Search: {\n content_ids?: string[]; // Required for Advantage+ catalog ads: contents or content_ids\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents or content_ids\n currency?: string;\n search_string?: string;\n value?: number;\n };\n StartTrial: {\n currency?: string;\n predicted_ltv?: number;\n value?: number;\n };\n SubmitApplication: {};\n Subscribe: {\n currency?: string;\n predicted_ltv?: number;\n value?: number;\n };\n ViewContent: {\n content_ids?: string[]; // Required for Advantage+ catalog ads: contents or content_ids\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents or content_ids\n currency?: string;\n value?: number;\n };\n};\n\ntype JSONValue =\n | null\n | string\n | number\n | boolean\n | Array<JSONValue>\n | { [value: string]: JSONValue };\n\nexport type PixelId = `${number}`;\nexport type Options = { eventID?: string };\n\n/**\n * reference: https://developers.facebook.com/docs/meta-pixel/reference#standard-events\n *\n * We determine if events are identical based on their ID and name. So, for an event to be deduplicated:\n * - In corresponding events, a Meta Pixel's eventID must match the Conversion API's event_id.\n * - In corresponding events, a Meta Pixel's event must match the Conversion API's event_name.\n *\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters\n */\nexport interface FBQ {\n /**\n * reference: https://stackoverflow.com/questions/62304291/sending-user-data-parameters-via-pixel\n *\n * Call init the normal default way first:\n * `fbq('init', 'XXXXX')`\n *\n * And at a later point in time, when you have obtained additional user data, you can call init\n * again basically enriching the already running fbq instance with additional data:\n * `fbq('init', 'XXXXX', { external_id: 1234, em: 'abc@abc.com' } )`\n *\n * Only caveat is that you have to send an event after this additional init call, otherwise the\n * provided data will not be sent to Facebook.\n */\n fbq(type: 'init', pixelId: PixelId, parameters?: MatchingParameters): void;\n\n /** Enable Manual Only mode. (value = false) */\n fbq(type: 'set', key: 'autoConfig', value: boolean, pixelId: PixelId): void;\n\n fbq<T extends keyof StandardEvents>(\n type: 'track',\n event: T,\n properties?: StandardEvents[T] & ObjectProperties,\n options?: Options\n ): void;\n\n fbq(\n type: 'trackCustom',\n event: string,\n properties?: Record<string, JSONValue> & ObjectProperties,\n options?: Options\n ): void;\n\n /** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */\n fbq<T extends keyof StandardEvents>(\n type: 'trackSingle',\n pixelId: PixelId,\n event: T,\n properties?: StandardEvents[T] & ObjectProperties,\n options?: Options\n ): void;\n\n /** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */\n fbq(\n type: 'trackSingleCustom',\n pixelId: PixelId,\n event: string,\n properties?: Record<string, JSONValue> & ObjectProperties,\n options?: Options\n ): void;\n}\n\n/**\n * Please download this CSV filefor examples of properly normalized and hashed data for the\n * parameters below.\n */\nexport function normalize(parameters: MatchingParameters): MatchingParameters {\n return {\n ...parameters,\n em: parameters.em?.toLowerCase().trim(),\n ph: parameters.ph?.replace(/[-+()\\s]/g, '').replace(/^0+/, ''),\n zp: parameters.zp?.split('-').at(0)?.trim(),\n fn: parameters.fn?.toLowerCase().trim(),\n ln: parameters.ln?.toLowerCase().trim(),\n ct: parameters.ct?.toLowerCase().replace(/[\\s/-]/g, ''),\n st: parameters.st?.toLowerCase().replace(/[\\s/,.-]/g, ''),\n country: parameters.country?.toLowerCase().replace(/[\\s/-]/g, ''),\n };\n}\n\nexport function mapItems(items?: Item[]): ObjectProperties {\n if (!items) return {};\n const categories = Array.from(new Set(items.map((i) => i.item_category).filter(Boolean)));\n const contents: Content[] = items.map((item) => {\n const { quantity, price, item_name, item_brand, item_category } = item;\n return {\n id: itemKey(item),\n quantity: quantity ?? 1,\n item_price: price,\n title: item_name,\n brand: item_brand,\n category: item_category,\n };\n });\n\n return {\n content_category: categories.length === 1 ? categories.at(0) : undefined,\n contents,\n content_ids: contents.map((c) => c.id),\n num_items: items.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n };\n}\n\ntype Mapped<F extends keyof StandardEvents> = ['track', F, StandardEvents[F] & ObjectProperties];\ntype Missed<F extends string> = ['trackCustom', F, Record<string, JSONValue> & ObjectProperties];\n\nexport function mapFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n): Mapped<keyof StandardEvents> | Missed<TrackName<T>> {\n if (name === 'add_payment_info') {\n const p = properties as TrackProperties<'add_payment_info'> | undefined;\n return [\n 'track',\n 'AddPaymentInfo',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n ];\n } else if (name === 'add_to_cart') {\n const p = properties as TrackProperties<'add_to_cart'> | undefined;\n return [\n 'track',\n 'AddToCart',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n ];\n } else if (name === 'add_to_wishlist') {\n const p = properties as TrackProperties<'add_to_wishlist'> | undefined;\n return [\n 'track',\n 'AddToWishlist',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n ];\n } else if (name === 'sign_up' || name === 'login') {\n const p = properties as TrackProperties<'sign_up' | 'login'> | undefined;\n return ['track', 'CompleteRegistration', { method: p?.method }];\n } else if (name === 'contact') {\n return ['track', 'Contact', {}];\n } else if (name === 'customize_product') {\n return ['track', 'CustomizeProduct', {}];\n } else if (name === 'donate') {\n return ['track', 'Donate', {}];\n } else if (name === 'find_location') {\n return ['track', 'FindLocation', {}];\n } else if (name === 'begin_checkout') {\n const p = properties as TrackProperties<'begin_checkout'> | undefined;\n return [\n 'track',\n 'InitiateCheckout',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n ];\n } else if (name === 'generate_lead') {\n const p = properties as TrackProperties<'generate_lead'> | undefined;\n return ['track', 'Lead', { currency: p?.currency, value: p?.value }];\n } else if (name === 'purchase') {\n const p = properties as TrackProperties<'purchase'> | undefined;\n return [\n 'track',\n 'Purchase',\n { currency: p?.currency ?? 'USD', value: p?.value ?? 0, ...mapItems(p?.items) },\n ];\n } else if (name === 'schedule') {\n return ['track', 'Schedule', {}];\n } else if (name === 'search') {\n const p = properties as TrackProperties<'search'> | undefined;\n return ['track', 'Search', { search_string: p?.search_term }];\n } else if (name === 'trial_begin') {\n const p = properties as TrackProperties<'trial_begin'> | undefined;\n return ['track', 'StartTrial', { currency: p?.currency, value: p?.value }];\n } else if (name === 'submit_application') {\n return ['track', 'SubmitApplication', {}];\n } else if (name === 'subscribe') {\n const p = properties as TrackProperties<'subscribe'> | undefined;\n return ['track', 'Subscribe', { currency: p?.currency, value: p?.value }];\n } else if (name === 'view_item') {\n const p = properties as TrackProperties<'view_item'> | undefined;\n return [\n 'track',\n 'ViewContent',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n ];\n } else {\n return ['trackCustom', name, properties ?? {}];\n }\n}\n\n/** Whether `mapFBEvent` turns the event into a Meta standard event (`track`, not `trackCustom`). */\nexport function isStandardFBEvent(name: string): boolean {\n return mapFBEvent(name as TrackName)[0] === 'track';\n}\n"],"mappings":";;;;;;AA+UA,SAAgB,UAAU,YAAoD;CAC5E,OAAO;EACL,GAAG;EACH,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,KAAK;EACtC,IAAI,WAAW,IAAI,QAAQ,aAAa,EAAE,CAAC,CAAC,QAAQ,OAAO,EAAE;EAC7D,IAAI,WAAW,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK;EAC1C,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,KAAK;EACtC,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,KAAK;EACtC,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,QAAQ,WAAW,EAAE;EACtD,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,QAAQ,aAAa,EAAE;EACxD,SAAS,WAAW,SAAS,YAAY,CAAC,CAAC,QAAQ,WAAW,EAAE;CAClE;AACF;AAEA,SAAgB,SAAS,OAAkC;CACzD,IAAI,CAAC,OAAO,OAAO,CAAC;CACpB,MAAM,aAAa,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,MAAM,EAAE,aAAa,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC;CACxF,MAAM,WAAsB,MAAM,KAAK,SAAS;EAC9C,MAAM,EAAE,UAAU,OAAO,WAAW,YAAY,kBAAkB;EAClE,OAAO;GACL,IAAI,QAAQ,IAAI;GAChB,UAAU,YAAY;GACtB,YAAY;GACZ,OAAO;GACP,OAAO;GACP,UAAU;EACZ;CACF,CAAC;CAED,OAAO;EACL,kBAAkB,WAAW,WAAW,IAAI,WAAW,GAAG,CAAC,IAAI,KAAA;EAC/D;EACA,aAAa,SAAS,KAAK,MAAM,EAAE,EAAE;EACrC,WAAW,MAAM,QAAQ,KAAK,MAAM,OAAO,EAAE,YAAY,IAAI,CAAC;CAChE;AACF;AAKA,SA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,GAAG,KAAK;GAAE;EAChF;CACF,OAAO,IAAI,SAAS,YAClB,OAAO;EAAC;EAAS;EAAY,CAAC;CAAC;MAC1B,IAAI,SAAS,UAElB,OAAO;EAAC;EAAS;EAAU,EAAE,eAAeA,YAAG,YAAY;CAAC;MACvD,IAAI,SAAS,eAAe;EACjC,MAAM,IAAI;EACV,OAAO;GAAC;GAAS;GAAc;IAAE,UAAU,GAAG;IAAU,OAAO,GAAG;GAAM;EAAC;CAC3E,OAAO,IAAI,SAAS,sBAClB,OAAO;EAAC;EAAS;EAAqB,CAAC;CAAC;MACnC,IAAI,SAAS,aAAa;EAC/B,MAAM,IAAI;EACV,OAAO;GAAC;GAAS;GAAa;IAAE,UAAU,GAAG;IAAU,OAAO,GAAG;GAAM;EAAC;CAC1E,OAAO,IAAI,SAAS,aAAa;EAC/B,MAAM,IAAI;EACV,OAAO;GACL;GACA;GACA;IAAE,UAAU,GAAG;IAAU,OAAO,GAAG;IAAO,GAAG,SAAS,GAAG,KAAK;GAAE;EAClE;CACF,OACE,OAAO;EAAC;EAAe;EAAM,cAAc,CAAC;CAAC;AAEjD;;AAGA,SAAgB,kBAAkB,MAAuB;CACvD,OAAO,WAAW,IAAiB,CAAC,CAAC,OAAO;AAC9C"}
@@ -228,8 +228,13 @@ function mapOAIEvent(name, properties) {
228
228
  }
229
229
  }
230
230
  }
231
+ /** Whether `mapOAIEvent` turns the event into an OpenAI standard event rather than `custom`. */
232
+ function isStandardOAIEvent(name) {
233
+ return mapOAIEvent(name).type !== "custom";
234
+ }
231
235
  exports.APP_EVENTS = APP_EVENTS;
232
236
  exports.NON_AD_EVENTS = NON_AD_EVENTS;
237
+ exports.isStandardOAIEvent = isStandardOAIEvent;
233
238
  exports.mapContents = mapContents;
234
239
  exports.mapOAIEvent = mapOAIEvent;
235
240
  exports.normalizeOAIName = normalizeOAIName;
@@ -1 +1 @@
1
- {"version":3,"file":"oaiq.cjs","names":[],"sources":["../../src/track/oaiq.ts"],"sourcesContent":["import type { Item } from './gtag';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\nexport const NON_AD_EVENTS = [\n // metrics\n 'CLS',\n 'FCP',\n 'FID',\n 'INP',\n 'LCP',\n 'TTFB',\n // promotions\n 'view_promotion',\n 'select_promotion',\n];\n\n/**\n * Content item shared by `contents` and `plan_enrollment` events.\n * https://developers.openai.com/ads/supported-events\n */\nexport type ContentItem = {\n id?: string;\n name?: string;\n content_type?: string;\n quantity?: number;\n /** Per-item monetary value in ISO 4217 minor units (e.g., 12,999 = $129.99 USD). */\n amount?: number;\n currency?: string;\n};\n\nexport type ContentsData = {\n type: 'contents';\n /** Monetary value in ISO 4217 minor units (e.g., 12,999 = $129.99 USD). */\n amount?: number;\n currency?: string;\n contents?: ContentItem[];\n};\n\nexport type CustomerActionData = {\n type: 'customer_action';\n amount?: number;\n currency?: string;\n};\n\nexport type PlanEnrollmentData = {\n type: 'plan_enrollment';\n plan_id?: string;\n amount?: number;\n currency?: string;\n contents?: ContentItem[];\n};\n\nexport type CustomEventData = {\n type: 'custom';\n amount?: number;\n currency?: string;\n contents?: ContentItem[];\n};\n\nexport type EventData = ContentsData | CustomerActionData | PlanEnrollmentData | CustomEventData;\n\n/**\n * Standard event names and the `data` shape each one expects.\n * https://developers.openai.com/ads/supported-events\n */\nexport type StandardEvents = {\n app_installed: CustomerActionData;\n app_opened: CustomerActionData;\n appointment_scheduled: CustomerActionData;\n checkout_started: ContentsData;\n contents_viewed: ContentsData;\n items_added: ContentsData;\n lead_created: CustomerActionData;\n order_created: ContentsData;\n page_viewed: ContentsData;\n registration_completed: CustomerActionData;\n subscription_created: PlanEnrollmentData;\n trial_started: PlanEnrollmentData;\n};\n\nexport type StandardEvent = keyof StandardEvents;\n\n/**\n * The app events, which OpenAI takes \"through the Conversions API only\", with `action_source`\n * `mobile_app`: the pixel never sends them, and the server only for an app's events.\n * https://developers.openai.com/ads/supported-events\n */\nexport const APP_EVENTS: readonly StandardEvent[] = ['app_installed', 'app_opened'];\n\nconst STANDARD_EVENTS: readonly string[] = [\n 'app_installed',\n 'app_opened',\n 'appointment_scheduled',\n 'checkout_started',\n 'contents_viewed',\n 'items_added',\n 'lead_created',\n 'order_created',\n 'page_viewed',\n 'registration_completed',\n 'subscription_created',\n 'trial_started',\n] satisfies StandardEvent[];\n\n/**\n * A track name as an OpenAI `custom_event_name`: 1–64 letters, digits, underscores or hyphens,\n * starting and ending with a letter or digit, not a standard event name; the API lowercases it.\n * Anything else becomes an underscore, so `Sign Up.Clicked` is `sign_up_clicked`. Undefined when\n * nothing usable is left — the event is then not sent at all. The pixel and the server both name\n * a custom event through this, so the two still deduplicate.\n * https://developers.openai.com/ads/supported-events\n */\nexport function oaiCustomEventName(name: string): string | undefined {\n const sanitized = name\n .toLowerCase()\n .replace(/[^a-z0-9_-]+/g, '_')\n .slice(0, 64)\n .replace(/^[_-]+|[_-]+$/g, '');\n if (!sanitized || STANDARD_EVENTS.includes(sanitized)) return undefined;\n return sanitized;\n}\n\n/**\n * Identity fields passed to `oaiq(\"init\", ...)` for conversion matching. Identifiers are\n * normalized, then sent as lowercase 64-char SHA-256 hex strings; geographic values are raw.\n * https://developers.openai.com/ads/measurement-pixel#send-user-data\n */\nexport type OAIQUser = {\n email_sha256?: string;\n /** 8–15 digits with the country code, no leading `+` or zeroes (`normalizeOAIPhone`). */\n phone_number_sha256?: string;\n external_id_sha256?: string;\n /** Lowercase, without whitespace or ASCII punctuation (`normalizeOAIName`). */\n first_name_sha256?: string;\n last_name_sha256?: string;\n /** Two-letter ISO 3166-1 country code (e.g. \"US\"). */\n country?: string;\n /** Max 128 characters; OpenAI trims and lowercases it. */\n city?: string;\n /** State, province or region, max 128 characters. */\n region?: string;\n postal_code?: string;\n};\n\n/**\n * A phone number as OpenAI hashes it: whitespace, parentheses, periods and hyphens removed, then\n * the leading `+` and zeroes; 8–15 digits with the country code, else not a usable number.\n */\nexport function normalizeOAIPhone(phone: string): string | undefined {\n const digits = phone\n .replace(/[\\s().-]/g, '')\n .replace(/^\\+/, '')\n .replace(/^0+/, '');\n return /^\\d{8,15}$/.test(digits) ? digits : undefined;\n}\n\n/** A name as OpenAI hashes it: lowercase, no whitespace or ASCII punctuation, accents kept. */\nexport function normalizeOAIName(name: string | undefined): string | undefined {\n return name?.toLowerCase().replace(/[\\s!-/:-@[-`{-~]/g, '') || undefined;\n}\n\nexport type InitConfig = {\n pixelId: string;\n /** Log SDK activity to the browser console. */\n debug?: boolean;\n user?: OAIQUser;\n};\n\n/**\n * Fourth argument of `oaiq(\"measure\", ...)`. Required for custom events (carries\n * `custom_event_name`); optional for standard events.\n */\nexport type MeasureOptions = {\n /** Shared with the Conversions API to deduplicate the same conversion across browser and server. */\n event_id?: string;\n /** Required for custom events; 1-64 chars of letters, numbers, underscores, or dashes. */\n custom_event_name?: string;\n /** When true, opts the event out of user-level personalization. */\n opt_out?: boolean;\n};\n\nexport interface OAIQ {\n oaiq(command: 'init', config: InitConfig): void;\n oaiq<T extends StandardEvent>(\n command: 'measure',\n event: T,\n data: StandardEvents[T],\n options?: MeasureOptions\n ): void;\n oaiq(\n command: 'measure',\n event: 'custom',\n data: CustomEventData,\n options: MeasureOptions & { custom_event_name: string }\n ): void;\n}\n\n/**\n * Currencies whose minor unit has 0 or 3 decimal places; everything else uses 2.\n * Follows Stripe's zero-decimal convention (e.g., MGA is treated as 0, ISK is included),\n * which can differ from strict ISO 4217 exponents.\n * https://docs.stripe.com/currencies#zero-decimal\n */\nconst ZERO_DECIMAL_CURRENCIES = new Set([\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'ISK',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n]);\nconst THREE_DECIMAL_CURRENCIES = new Set(['BHD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND']);\n\n/**\n * Convert a major-unit amount (e.g., 129.99) into ISO 4217 minor units (e.g., 12,999). None\n * without a currency: the minor unit depends on it, and OpenAI requires a `currency` with every\n * `amount` — an amount alone would be invalid, not just imprecise.\n */\nexport function toMinorUnits(value?: number | null, currency?: string): number | undefined {\n if (value === undefined || value === null || Number.isNaN(value)) return undefined;\n const code = currency?.toUpperCase();\n if (!code) return undefined;\n const exponent =\n code && ZERO_DECIMAL_CURRENCIES.has(code)\n ? 0\n : code && THREE_DECIMAL_CURRENCIES.has(code)\n ? 3\n : 2;\n return Math.round(value * 10 ** exponent);\n}\n\nexport function mapContents(items?: Item[], currency?: string): ContentItem[] | undefined {\n if (!items || items.length === 0) return undefined;\n const code = currency?.toUpperCase();\n return items.map((item) => {\n const amount = toMinorUnits(item.price, currency);\n return {\n id: item.item_id,\n name: item.item_name,\n content_type: item.item_category,\n quantity: item.quantity,\n amount,\n currency: amount !== undefined ? code : undefined,\n };\n });\n}\n\n/** Safely read a property off loosely typed track properties without widening to `any`. */\nfunction prop(properties: unknown, key: string): unknown {\n return typeof properties === 'object' && properties !== null\n ? (properties as Record<string, unknown>)[key]\n : undefined;\n}\n\nfunction readValue(properties: unknown): number | undefined {\n const value = prop(properties, 'value');\n return typeof value === 'number' ? value : undefined;\n}\n\nfunction readCurrency(properties: unknown): string | undefined {\n const currency = prop(properties, 'currency');\n return typeof currency === 'string' ? currency : undefined;\n}\n\nfunction readItems(properties: unknown): Item[] | undefined {\n const items = prop(properties, 'items');\n return Array.isArray(items) ? (items as Item[]) : undefined;\n}\n\nfunction contentsData(properties: unknown): ContentsData {\n const currency = readCurrency(properties);\n return {\n type: 'contents',\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n contents: mapContents(readItems(properties), currency),\n };\n}\n\nfunction customerActionData(properties: unknown): CustomerActionData {\n const currency = readCurrency(properties);\n return {\n type: 'customer_action',\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n };\n}\n\nfunction planEnrollmentData(properties: unknown): PlanEnrollmentData {\n const currency = readCurrency(properties);\n const items = readItems(properties);\n return {\n type: 'plan_enrollment',\n plan_id: items?.[0]?.item_id,\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n contents: mapContents(items, currency),\n };\n}\n\nexport type MappedOAIEvent = {\n type: StandardEvent | 'custom';\n data: EventData;\n};\n\n/** Map an internal track event onto an OpenAI standard (or custom) conversion event. */\nexport function mapOAIEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n): MappedOAIEvent {\n switch (name) {\n // The app's first launch, recorded once by the app hook: the closest thing to an install.\n case 'first_open':\n return { type: 'app_installed', data: customerActionData(properties) };\n case 'app_open':\n return { type: 'app_opened', data: customerActionData(properties) };\n case 'page_view':\n return { type: 'page_viewed', data: contentsData(properties) };\n case 'view_item':\n case 'view_item_list':\n return { type: 'contents_viewed', data: contentsData(properties) };\n case 'begin_checkout':\n return { type: 'checkout_started', data: contentsData(properties) };\n case 'add_to_cart':\n return { type: 'items_added', data: contentsData(properties) };\n case 'purchase':\n return { type: 'order_created', data: contentsData(properties) };\n case 'generate_lead':\n case 'qualify_lead':\n return { type: 'lead_created', data: customerActionData(properties) };\n case 'sign_up':\n case 'login':\n return { type: 'registration_completed', data: customerActionData(properties) };\n case 'schedule':\n return { type: 'appointment_scheduled', data: customerActionData(properties) };\n case 'subscribe':\n return { type: 'subscription_created', data: planEnrollmentData(properties) };\n case 'trial_begin':\n return { type: 'trial_started', data: planEnrollmentData(properties) };\n default: {\n const currency = readCurrency(properties);\n return {\n type: 'custom',\n data: {\n type: 'custom',\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n contents: mapContents(readItems(properties), currency),\n },\n };\n }\n }\n}\n"],"mappings":";;AAGA,MAAa,gBAAgB;CAE3B;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;AACF;;;;;;AAyEA,MAAa,aAAuC,CAAC,iBAAiB,YAAY;AAElF,MAAM,kBAAqC;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;C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.ts"],"sourcesContent":["import type { Item } from './gtag';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\nexport const NON_AD_EVENTS = [\n // metrics\n 'CLS',\n 'FCP',\n 'FID',\n 'INP',\n 'LCP',\n 'TTFB',\n // promotions\n 'view_promotion',\n 'select_promotion',\n];\n\n/**\n * Content item shared by `contents` and `plan_enrollment` events.\n * https://developers.openai.com/ads/supported-events\n */\nexport type ContentItem = {\n id?: string;\n name?: string;\n content_type?: string;\n quantity?: number;\n /** Per-item monetary value in ISO 4217 minor units (e.g., 12,999 = $129.99 USD). */\n amount?: number;\n currency?: string;\n};\n\nexport type ContentsData = {\n type: 'contents';\n /** Monetary value in ISO 4217 minor units (e.g., 12,999 = $129.99 USD). */\n amount?: number;\n currency?: string;\n contents?: ContentItem[];\n};\n\nexport type CustomerActionData = {\n type: 'customer_action';\n amount?: number;\n currency?: string;\n};\n\nexport type PlanEnrollmentData = {\n type: 'plan_enrollment';\n plan_id?: string;\n amount?: number;\n currency?: string;\n contents?: ContentItem[];\n};\n\nexport type CustomEventData = {\n type: 'custom';\n amount?: number;\n currency?: string;\n contents?: ContentItem[];\n};\n\nexport type EventData = ContentsData | CustomerActionData | PlanEnrollmentData | CustomEventData;\n\n/**\n * Standard event names and the `data` shape each one expects.\n * https://developers.openai.com/ads/supported-events\n */\nexport type StandardEvents = {\n app_installed: CustomerActionData;\n app_opened: CustomerActionData;\n appointment_scheduled: CustomerActionData;\n checkout_started: ContentsData;\n contents_viewed: ContentsData;\n items_added: ContentsData;\n lead_created: CustomerActionData;\n order_created: ContentsData;\n page_viewed: ContentsData;\n registration_completed: CustomerActionData;\n subscription_created: PlanEnrollmentData;\n trial_started: PlanEnrollmentData;\n};\n\nexport type StandardEvent = keyof StandardEvents;\n\n/**\n * The app events, which OpenAI takes \"through the Conversions API only\", with `action_source`\n * `mobile_app`: the pixel never sends them, and the server only for an app's events.\n * https://developers.openai.com/ads/supported-events\n */\nexport const APP_EVENTS: readonly StandardEvent[] = ['app_installed', 'app_opened'];\n\nconst STANDARD_EVENTS: readonly string[] = [\n 'app_installed',\n 'app_opened',\n 'appointment_scheduled',\n 'checkout_started',\n 'contents_viewed',\n 'items_added',\n 'lead_created',\n 'order_created',\n 'page_viewed',\n 'registration_completed',\n 'subscription_created',\n 'trial_started',\n] satisfies StandardEvent[];\n\n/**\n * A track name as an OpenAI `custom_event_name`: 1–64 letters, digits, underscores or hyphens,\n * starting and ending with a letter or digit, not a standard event name; the API lowercases it.\n * Anything else becomes an underscore, so `Sign Up.Clicked` is `sign_up_clicked`. Undefined when\n * nothing usable is left — the event is then not sent at all. The pixel and the server both name\n * a custom event through this, so the two still deduplicate.\n * https://developers.openai.com/ads/supported-events\n */\nexport function oaiCustomEventName(name: string): string | undefined {\n const sanitized = name\n .toLowerCase()\n .replace(/[^a-z0-9_-]+/g, '_')\n .slice(0, 64)\n .replace(/^[_-]+|[_-]+$/g, '');\n if (!sanitized || STANDARD_EVENTS.includes(sanitized)) return undefined;\n return sanitized;\n}\n\n/**\n * Identity fields passed to `oaiq(\"init\", ...)` for conversion matching. Identifiers are\n * normalized, then sent as lowercase 64-char SHA-256 hex strings; geographic values are raw.\n * https://developers.openai.com/ads/measurement-pixel#send-user-data\n */\nexport type OAIQUser = {\n email_sha256?: string;\n /** 8–15 digits with the country code, no leading `+` or zeroes (`normalizeOAIPhone`). */\n phone_number_sha256?: string;\n external_id_sha256?: string;\n /** Lowercase, without whitespace or ASCII punctuation (`normalizeOAIName`). */\n first_name_sha256?: string;\n last_name_sha256?: string;\n /** Two-letter ISO 3166-1 country code (e.g. \"US\"). */\n country?: string;\n /** Max 128 characters; OpenAI trims and lowercases it. */\n city?: string;\n /** State, province or region, max 128 characters. */\n region?: string;\n postal_code?: string;\n};\n\n/**\n * A phone number as OpenAI hashes it: whitespace, parentheses, periods and hyphens removed, then\n * the leading `+` and zeroes; 8–15 digits with the country code, else not a usable number.\n */\nexport function normalizeOAIPhone(phone: string): string | undefined {\n const digits = phone\n .replace(/[\\s().-]/g, '')\n .replace(/^\\+/, '')\n .replace(/^0+/, '');\n return /^\\d{8,15}$/.test(digits) ? digits : undefined;\n}\n\n/** A name as OpenAI hashes it: lowercase, no whitespace or ASCII punctuation, accents kept. */\nexport function normalizeOAIName(name: string | undefined): string | undefined {\n return name?.toLowerCase().replace(/[\\s!-/:-@[-`{-~]/g, '') || undefined;\n}\n\nexport type InitConfig = {\n pixelId: string;\n /** Log SDK activity to the browser console. */\n debug?: boolean;\n user?: OAIQUser;\n};\n\n/**\n * Fourth argument of `oaiq(\"measure\", ...)`. Required for custom events (carries\n * `custom_event_name`); optional for standard events.\n */\nexport type MeasureOptions = {\n /** Shared with the Conversions API to deduplicate the same conversion across browser and server. */\n event_id?: string;\n /** Required for custom events; 1-64 chars of letters, numbers, underscores, or dashes. */\n custom_event_name?: string;\n /** When true, opts the event out of user-level personalization. */\n opt_out?: boolean;\n};\n\nexport interface OAIQ {\n oaiq(command: 'init', config: InitConfig): void;\n oaiq<T extends StandardEvent>(\n command: 'measure',\n event: T,\n data: StandardEvents[T],\n options?: MeasureOptions\n ): void;\n oaiq(\n command: 'measure',\n event: 'custom',\n data: CustomEventData,\n options: MeasureOptions & { custom_event_name: string }\n ): void;\n}\n\n/**\n * Currencies whose minor unit has 0 or 3 decimal places; everything else uses 2.\n * Follows Stripe's zero-decimal convention (e.g., MGA is treated as 0, ISK is included),\n * which can differ from strict ISO 4217 exponents.\n * https://docs.stripe.com/currencies#zero-decimal\n */\nconst ZERO_DECIMAL_CURRENCIES = new Set([\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'ISK',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n]);\nconst THREE_DECIMAL_CURRENCIES = new Set(['BHD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND']);\n\n/**\n * Convert a major-unit amount (e.g., 129.99) into ISO 4217 minor units (e.g., 12,999). None\n * without a currency: the minor unit depends on it, and OpenAI requires a `currency` with every\n * `amount` — an amount alone would be invalid, not just imprecise.\n */\nexport function toMinorUnits(value?: number | null, currency?: string): number | undefined {\n if (value === undefined || value === null || Number.isNaN(value)) return undefined;\n const code = currency?.toUpperCase();\n if (!code) return undefined;\n const exponent =\n code && ZERO_DECIMAL_CURRENCIES.has(code)\n ? 0\n : code && THREE_DECIMAL_CURRENCIES.has(code)\n ? 3\n : 2;\n return Math.round(value * 10 ** exponent);\n}\n\nexport function mapContents(items?: Item[], currency?: string): ContentItem[] | undefined {\n if (!items || items.length === 0) return undefined;\n const code = currency?.toUpperCase();\n return items.map((item) => {\n const amount = toMinorUnits(item.price, currency);\n return {\n id: item.item_id,\n name: item.item_name,\n content_type: item.item_category,\n quantity: item.quantity,\n amount,\n currency: amount !== undefined ? code : undefined,\n };\n });\n}\n\n/** Safely read a property off loosely typed track properties without widening to `any`. */\nfunction prop(properties: unknown, key: string): unknown {\n return typeof properties === 'object' && properties !== null\n ? (properties as Record<string, unknown>)[key]\n : undefined;\n}\n\nfunction readValue(properties: unknown): number | undefined {\n const value = prop(properties, 'value');\n return typeof value === 'number' ? value : undefined;\n}\n\nfunction readCurrency(properties: unknown): string | undefined {\n const currency = prop(properties, 'currency');\n return typeof currency === 'string' ? currency : undefined;\n}\n\nfunction readItems(properties: unknown): Item[] | undefined {\n const items = prop(properties, 'items');\n return Array.isArray(items) ? (items as Item[]) : undefined;\n}\n\nfunction contentsData(properties: unknown): ContentsData {\n const currency = readCurrency(properties);\n return {\n type: 'contents',\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n contents: mapContents(readItems(properties), currency),\n };\n}\n\nfunction customerActionData(properties: unknown): CustomerActionData {\n const currency = readCurrency(properties);\n return {\n type: 'customer_action',\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n };\n}\n\nfunction planEnrollmentData(properties: unknown): PlanEnrollmentData {\n const currency = readCurrency(properties);\n const items = readItems(properties);\n return {\n type: 'plan_enrollment',\n plan_id: items?.[0]?.item_id,\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n contents: mapContents(items, currency),\n };\n}\n\nexport type MappedOAIEvent = {\n type: StandardEvent | 'custom';\n data: EventData;\n};\n\n/** Map an internal track event onto an OpenAI standard (or custom) conversion event. */\nexport function mapOAIEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n): MappedOAIEvent {\n switch (name) {\n // The app's first launch, recorded once by the app hook: the closest thing to an install.\n case 'first_open':\n return { type: 'app_installed', data: customerActionData(properties) };\n case 'app_open':\n return { type: 'app_opened', data: customerActionData(properties) };\n case 'page_view':\n return { type: 'page_viewed', data: contentsData(properties) };\n case 'view_item':\n case 'view_item_list':\n return { type: 'contents_viewed', data: contentsData(properties) };\n case 'begin_checkout':\n return { type: 'checkout_started', data: contentsData(properties) };\n case 'add_to_cart':\n return { type: 'items_added', data: contentsData(properties) };\n case 'purchase':\n return { type: 'order_created', data: contentsData(properties) };\n case 'generate_lead':\n case 'qualify_lead':\n return { type: 'lead_created', data: customerActionData(properties) };\n case 'sign_up':\n case 'login':\n return { type: 'registration_completed', data: customerActionData(properties) };\n case 'schedule':\n return { type: 'appointment_scheduled', data: customerActionData(properties) };\n case 'subscribe':\n return { type: 'subscription_created', data: planEnrollmentData(properties) };\n case 'trial_begin':\n return { type: 'trial_started', data: planEnrollmentData(properties) };\n default: {\n const currency = readCurrency(properties);\n return {\n type: 'custom',\n data: {\n type: 'custom',\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n contents: mapContents(readItems(properties), currency),\n },\n };\n }\n }\n}\n\n/** Whether `mapOAIEvent` turns the event into an OpenAI standard event rather than `custom`. */\nexport function isStandardOAIEvent(name: string): boolean {\n return mapOAIEvent(name as TrackName).type !== 'custom';\n}\n"],"mappings":";;AAGA,MAAa,gBAAgB;CAE3B;CACA;CACA;CACA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,UAAU,YAAY;KAChC,UAAU,YAAY,UAAU,UAAU,GAAG,QAAQ;IACvD;GACF;EACF;CACF;AACF;;AAGA,SAAgB,mBAAmB,MAAuB;CACxD,OAAO,YAAY,IAAiB,CAAC,CAAC,SAAS;AACjD"}
@@ -140,4 +140,6 @@ export type MappedOAIEvent = {
140
140
  };
141
141
  /** Map an internal track event onto an OpenAI standard (or custom) conversion event. */
142
142
  export declare function mapOAIEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): MappedOAIEvent;
143
+ /** Whether `mapOAIEvent` turns the event into an OpenAI standard event rather than `custom`. */
144
+ export declare function isStandardOAIEvent(name: string): boolean;
143
145
  //# sourceMappingURL=oaiq.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"oaiq.d.cts","names":[],"sources":["../../src/track/oaiq.ts"],"mappings":";;qBAGa;;;;;YAiBD;EACV;EACA;EACA;EACA;;EAEA;EACA;;YAGU;EACV;;EAEA;EACA;EACA,WAAW;;YAGD;EACV;EACA;EACA;;YAGU;EACV;EACA;EACA;EACA;EACA,WAAW;;YAGD;EACV;EACA;EACA;EACA,WAAW;;YAGD,YAAY,eAAe,qBAAqB,qBAAqB;;;;;YAMrE;EACV,eAAe;EACf,YAAY;EACZ,uBAAuB;EACvB,kBAAkB;EAClB,iBAAiB;EACjB,aAAa;EACb,cAAc;EACd,eAAe;EACf,aAAa;EACb,wBAAwB;EACxB,sBAAsB;EACtB,eAAe;;YAGL,sBAAsB;;;;;;qBAOrB,qBAAqB;;;;;;;;;wBAyBlB,mBAAmB;;;;;;YAevB;EACV;;EAEA;EACA;;EAEA;EACA;;EAEA;;EAEA;;EAEA;EACA;;;;;;wBAOc,kBAAkB;;wBASlB,iBAAiB;YAIrB;EACV;;EAEA;EACA,OAAO;;;;;;YAOG;;EAEV;;EAEA;;EAEA;;iBAGe;EACf,KAAK,iBAAiB,QAAQ;EAC9B,KAAK,UAAU,eACb,oBACA,OAAO,GACP,MAAM,eAAe,IACrB,UAAU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@@ -140,4 +140,6 @@ export type MappedOAIEvent = {
140
140
  };
141
141
  /** Map an internal track event onto an OpenAI standard (or custom) conversion event. */
142
142
  export declare function mapOAIEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): MappedOAIEvent;
143
+ /** Whether `mapOAIEvent` turns the event into an OpenAI standard event rather than `custom`. */
144
+ export declare function isStandardOAIEvent(name: string): boolean;
143
145
  //# sourceMappingURL=oaiq.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"oaiq.d.mts","names":[],"sources":["../../src/track/oaiq.ts"],"mappings":";;qBAGa;;;;;YAiBD;EACV;EACA;EACA;EACA;;EAEA;EACA;;YAGU;EACV;;EAEA;EACA;EACA,WAAW;;YAGD;EACV;EACA;EACA;;YAGU;EACV;EACA;EACA;EACA;EACA,WAAW;;YAGD;EACV;EACA;EACA;EACA,WAAW;;YAGD,YAAY,eAAe,qBAAqB,qBAAqB;;;;;YAMrE;EACV,eAAe;EACf,YAAY;EACZ,uBAAuB;EACvB,kBAAkB;EAClB,iBAAiB;EACjB,aAAa;EACb,cAAc;EACd,eAAe;EACf,aAAa;EACb,wBAAwB;EACxB,sBAAsB;EACtB,eAAe;;YAGL,sBAAsB;;;;;;qBAOrB,qBAAqB;;;;;;;;;wBAyBlB,mBAAmB;;;;;;YAevB;EACV;;EAEA;EACA;;EAEA;EACA;;EAEA;;EAEA;;EAEA;EACA;;;;;;wBAOc,kBAAkB;;wBASlB,iBAAiB;YAIrB;EACV;;EAEA;EACA,OAAO;;;;;;YAOG;;EAEV;;EAEA;;EAEA;;iBAGe;EACf,KAAK,iBAAiB,QAAQ;EAC9B,KAAK,UAAU,eACb,oBACA,OAAO,GACP,MAAM,eAAe,IACrB,UAAU;EAEZ,KACE,oBACA,iBACA,MAAM,iBACN,SAAS;IAAmB;;;;;;;;wBAoChB,aAAa,uBAAuB;wBAapC,YAAY,QAAQ,QAAQ,oBAAoB;YAqEpD;EACV,MAAM;EACN,MAAM;;;wBAIQ,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB,KAC5B"}
1
+ {"version":3,"file":"oaiq.d.mts","names":[],"sources":["../../src/track/oaiq.ts"],"mappings":";;qBAGa;;;;;YAiBD;EACV;EACA;EACA;EACA;;EAEA;EACA;;YAGU;EACV;;EAEA;EACA;EACA,WAAW;;YAGD;EACV;EACA;EACA;;YAGU;EACV;EACA;EACA;EACA;EACA,WAAW;;YAGD;EACV;EACA;EACA;EACA,WAAW;;YAGD,YAAY,eAAe,qBAAqB,qBAAqB;;;;;YAMrE;EACV,eAAe;EACf,YAAY;EACZ,uBAAuB;EACvB,kBAAkB;EAClB,iBAAiB;EACjB,aAAa;EACb,cAAc;EACd,eAAe;EACf,aAAa;EACb,wBAAwB;EACxB,sBAAsB;EACtB,eAAe;;YAGL,sBAAsB;;;;;;qBAOrB,qBAAqB;;;;;;;;;wBAyBlB,mBAAmB;;;;;;YAevB;EACV;;EAEA;EACA;;EAEA;EACA;;EAEA;;EAEA;;EAEA;EACA;;;;;;wBAOc,kBAAkB;;wBASlB,iBAAiB;YAIrB;EACV;;EAEA;EACA,OAAO;;;;;;YAOG;;EAEV;;EAEA;;EAEA;;iBAGe;EACf,KAAK,iBAAiB,QAAQ;EAC9B,KAAK,UAAU,eACb,oBACA,OAAO,GACP,MAAM,eAAe,IACrB,UAAU;EAEZ,KACE,oBACA,iBACA,MAAM,iBACN,SAAS;IAAmB;;;;;;;;wBAoChB,aAAa,uBAAuB;wBAapC,YAAY,QAAQ,QAAQ,oBAAoB;YAqEpD;EACV,MAAM;EACN,MAAM;;;wBAIQ,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB,KAC5B;;wBA8Ca,mBAAmB"}
@@ -227,6 +227,10 @@ function mapOAIEvent(name, properties) {
227
227
  }
228
228
  }
229
229
  }
230
- export { APP_EVENTS, NON_AD_EVENTS, mapContents, mapOAIEvent, normalizeOAIName, normalizeOAIPhone, oaiCustomEventName, toMinorUnits };
230
+ /** Whether `mapOAIEvent` turns the event into an OpenAI standard event rather than `custom`. */
231
+ function isStandardOAIEvent(name) {
232
+ return mapOAIEvent(name).type !== "custom";
233
+ }
234
+ export { APP_EVENTS, NON_AD_EVENTS, isStandardOAIEvent, mapContents, mapOAIEvent, normalizeOAIName, normalizeOAIPhone, oaiCustomEventName, toMinorUnits };
231
235
 
232
236
  //# sourceMappingURL=oaiq.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"oaiq.mjs","names":[],"sources":["../../src/track/oaiq.ts"],"sourcesContent":["import type { Item } from './gtag';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\nexport const NON_AD_EVENTS = [\n // metrics\n 'CLS',\n 'FCP',\n 'FID',\n 'INP',\n 'LCP',\n 'TTFB',\n // promotions\n 'view_promotion',\n 'select_promotion',\n];\n\n/**\n * Content item shared by `contents` and `plan_enrollment` events.\n * https://developers.openai.com/ads/supported-events\n */\nexport type ContentItem = {\n id?: string;\n name?: string;\n content_type?: string;\n quantity?: number;\n /** Per-item monetary value in ISO 4217 minor units (e.g., 12,999 = $129.99 USD). */\n amount?: number;\n currency?: string;\n};\n\nexport type ContentsData = {\n type: 'contents';\n /** Monetary value in ISO 4217 minor units (e.g., 12,999 = $129.99 USD). */\n amount?: number;\n currency?: string;\n contents?: ContentItem[];\n};\n\nexport type CustomerActionData = {\n type: 'customer_action';\n amount?: number;\n currency?: string;\n};\n\nexport type PlanEnrollmentData = {\n type: 'plan_enrollment';\n plan_id?: string;\n amount?: number;\n currency?: string;\n contents?: ContentItem[];\n};\n\nexport type CustomEventData = {\n type: 'custom';\n amount?: number;\n currency?: string;\n contents?: ContentItem[];\n};\n\nexport type EventData = ContentsData | CustomerActionData | PlanEnrollmentData | CustomEventData;\n\n/**\n * Standard event names and the `data` shape each one expects.\n * https://developers.openai.com/ads/supported-events\n */\nexport type StandardEvents = {\n app_installed: CustomerActionData;\n app_opened: CustomerActionData;\n appointment_scheduled: CustomerActionData;\n checkout_started: ContentsData;\n contents_viewed: ContentsData;\n items_added: ContentsData;\n lead_created: CustomerActionData;\n order_created: ContentsData;\n page_viewed: ContentsData;\n registration_completed: CustomerActionData;\n subscription_created: PlanEnrollmentData;\n trial_started: PlanEnrollmentData;\n};\n\nexport type StandardEvent = keyof StandardEvents;\n\n/**\n * The app events, which OpenAI takes \"through the Conversions API only\", with `action_source`\n * `mobile_app`: the pixel never sends them, and the server only for an app's events.\n * https://developers.openai.com/ads/supported-events\n */\nexport const APP_EVENTS: readonly StandardEvent[] = ['app_installed', 'app_opened'];\n\nconst STANDARD_EVENTS: readonly string[] = [\n 'app_installed',\n 'app_opened',\n 'appointment_scheduled',\n 'checkout_started',\n 'contents_viewed',\n 'items_added',\n 'lead_created',\n 'order_created',\n 'page_viewed',\n 'registration_completed',\n 'subscription_created',\n 'trial_started',\n] satisfies StandardEvent[];\n\n/**\n * A track name as an OpenAI `custom_event_name`: 1–64 letters, digits, underscores or hyphens,\n * starting and ending with a letter or digit, not a standard event name; the API lowercases it.\n * Anything else becomes an underscore, so `Sign Up.Clicked` is `sign_up_clicked`. Undefined when\n * nothing usable is left — the event is then not sent at all. The pixel and the server both name\n * a custom event through this, so the two still deduplicate.\n * https://developers.openai.com/ads/supported-events\n */\nexport function oaiCustomEventName(name: string): string | undefined {\n const sanitized = name\n .toLowerCase()\n .replace(/[^a-z0-9_-]+/g, '_')\n .slice(0, 64)\n .replace(/^[_-]+|[_-]+$/g, '');\n if (!sanitized || STANDARD_EVENTS.includes(sanitized)) return undefined;\n return sanitized;\n}\n\n/**\n * Identity fields passed to `oaiq(\"init\", ...)` for conversion matching. Identifiers are\n * normalized, then sent as lowercase 64-char SHA-256 hex strings; geographic values are raw.\n * https://developers.openai.com/ads/measurement-pixel#send-user-data\n */\nexport type OAIQUser = {\n email_sha256?: string;\n /** 8–15 digits with the country code, no leading `+` or zeroes (`normalizeOAIPhone`). */\n phone_number_sha256?: string;\n external_id_sha256?: string;\n /** Lowercase, without whitespace or ASCII punctuation (`normalizeOAIName`). */\n first_name_sha256?: string;\n last_name_sha256?: string;\n /** Two-letter ISO 3166-1 country code (e.g. \"US\"). */\n country?: string;\n /** Max 128 characters; OpenAI trims and lowercases it. */\n city?: string;\n /** State, province or region, max 128 characters. */\n region?: string;\n postal_code?: string;\n};\n\n/**\n * A phone number as OpenAI hashes it: whitespace, parentheses, periods and hyphens removed, then\n * the leading `+` and zeroes; 8–15 digits with the country code, else not a usable number.\n */\nexport function normalizeOAIPhone(phone: string): string | undefined {\n const digits = phone\n .replace(/[\\s().-]/g, '')\n .replace(/^\\+/, '')\n .replace(/^0+/, '');\n return /^\\d{8,15}$/.test(digits) ? digits : undefined;\n}\n\n/** A name as OpenAI hashes it: lowercase, no whitespace or ASCII punctuation, accents kept. */\nexport function normalizeOAIName(name: string | undefined): string | undefined {\n return name?.toLowerCase().replace(/[\\s!-/:-@[-`{-~]/g, '') || undefined;\n}\n\nexport type InitConfig = {\n pixelId: string;\n /** Log SDK activity to the browser console. */\n debug?: boolean;\n user?: OAIQUser;\n};\n\n/**\n * Fourth argument of `oaiq(\"measure\", ...)`. Required for custom events (carries\n * `custom_event_name`); optional for standard events.\n */\nexport type MeasureOptions = {\n /** Shared with the Conversions API to deduplicate the same conversion across browser and server. */\n event_id?: string;\n /** Required for custom events; 1-64 chars of letters, numbers, underscores, or dashes. */\n custom_event_name?: string;\n /** When true, opts the event out of user-level personalization. */\n opt_out?: boolean;\n};\n\nexport interface OAIQ {\n oaiq(command: 'init', config: InitConfig): void;\n oaiq<T extends StandardEvent>(\n command: 'measure',\n event: T,\n data: StandardEvents[T],\n options?: MeasureOptions\n ): void;\n oaiq(\n command: 'measure',\n event: 'custom',\n data: CustomEventData,\n options: MeasureOptions & { custom_event_name: string }\n ): void;\n}\n\n/**\n * Currencies whose minor unit has 0 or 3 decimal places; everything else uses 2.\n * Follows Stripe's zero-decimal convention (e.g., MGA is treated as 0, ISK is included),\n * which can differ from strict ISO 4217 exponents.\n * https://docs.stripe.com/currencies#zero-decimal\n */\nconst ZERO_DECIMAL_CURRENCIES = new Set([\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'ISK',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n]);\nconst THREE_DECIMAL_CURRENCIES = new Set(['BHD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND']);\n\n/**\n * Convert a major-unit amount (e.g., 129.99) into ISO 4217 minor units (e.g., 12,999). None\n * without a currency: the minor unit depends on it, and OpenAI requires a `currency` with every\n * `amount` — an amount alone would be invalid, not just imprecise.\n */\nexport function toMinorUnits(value?: number | null, currency?: string): number | undefined {\n if (value === undefined || value === null || Number.isNaN(value)) return undefined;\n const code = currency?.toUpperCase();\n if (!code) return undefined;\n const exponent =\n code && ZERO_DECIMAL_CURRENCIES.has(code)\n ? 0\n : code && THREE_DECIMAL_CURRENCIES.has(code)\n ? 3\n : 2;\n return Math.round(value * 10 ** exponent);\n}\n\nexport function mapContents(items?: Item[], currency?: string): ContentItem[] | undefined {\n if (!items || items.length === 0) return undefined;\n const code = currency?.toUpperCase();\n return items.map((item) => {\n const amount = toMinorUnits(item.price, currency);\n return {\n id: item.item_id,\n name: item.item_name,\n content_type: item.item_category,\n quantity: item.quantity,\n amount,\n currency: amount !== undefined ? code : undefined,\n };\n });\n}\n\n/** Safely read a property off loosely typed track properties without widening to `any`. */\nfunction prop(properties: unknown, key: string): unknown {\n return typeof properties === 'object' && properties !== null\n ? (properties as Record<string, unknown>)[key]\n : undefined;\n}\n\nfunction readValue(properties: unknown): number | undefined {\n const value = prop(properties, 'value');\n return typeof value === 'number' ? value : undefined;\n}\n\nfunction readCurrency(properties: unknown): string | undefined {\n const currency = prop(properties, 'currency');\n return typeof currency === 'string' ? currency : undefined;\n}\n\nfunction readItems(properties: unknown): Item[] | undefined {\n const items = prop(properties, 'items');\n return Array.isArray(items) ? (items as Item[]) : undefined;\n}\n\nfunction contentsData(properties: unknown): ContentsData {\n const currency = readCurrency(properties);\n return {\n type: 'contents',\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n contents: mapContents(readItems(properties), currency),\n };\n}\n\nfunction customerActionData(properties: unknown): CustomerActionData {\n const currency = readCurrency(properties);\n return {\n type: 'customer_action',\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n };\n}\n\nfunction planEnrollmentData(properties: unknown): PlanEnrollmentData {\n const currency = readCurrency(properties);\n const items = readItems(properties);\n return {\n type: 'plan_enrollment',\n plan_id: items?.[0]?.item_id,\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n contents: mapContents(items, currency),\n };\n}\n\nexport type MappedOAIEvent = {\n type: StandardEvent | 'custom';\n data: EventData;\n};\n\n/** Map an internal track event onto an OpenAI standard (or custom) conversion event. */\nexport function mapOAIEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n): MappedOAIEvent {\n switch (name) {\n // The app's first launch, recorded once by the app hook: the closest thing to an install.\n case 'first_open':\n return { type: 'app_installed', data: customerActionData(properties) };\n case 'app_open':\n return { type: 'app_opened', data: customerActionData(properties) };\n case 'page_view':\n return { type: 'page_viewed', data: contentsData(properties) };\n case 'view_item':\n case 'view_item_list':\n return { type: 'contents_viewed', data: contentsData(properties) };\n case 'begin_checkout':\n return { type: 'checkout_started', data: contentsData(properties) };\n case 'add_to_cart':\n return { type: 'items_added', data: contentsData(properties) };\n case 'purchase':\n return { type: 'order_created', data: contentsData(properties) };\n case 'generate_lead':\n case 'qualify_lead':\n return { type: 'lead_created', data: customerActionData(properties) };\n case 'sign_up':\n case 'login':\n return { type: 'registration_completed', data: customerActionData(properties) };\n case 'schedule':\n return { type: 'appointment_scheduled', data: customerActionData(properties) };\n case 'subscribe':\n return { type: 'subscription_created', data: planEnrollmentData(properties) };\n case 'trial_begin':\n return { type: 'trial_started', data: planEnrollmentData(properties) };\n default: {\n const currency = readCurrency(properties);\n return {\n type: 'custom',\n data: {\n type: 'custom',\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n contents: mapContents(readItems(properties), currency),\n },\n };\n }\n }\n}\n"],"mappings":";AAGA,MAAa,gBAAgB;CAE3B;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;AACF;;;;;;AAyEA,MAAa,aAAuC,CAAC,iBAAiB,YAAY;AAElF,MAAM,kBAAqC;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;AAUA,SAAgB,mBAAmB,MAAkC;CACnE,MAAM,YAAY,KACf,YAAY,CAAC,CACb,QAAQ,iBAAiB,GAAG,CAAC,CAC7B,MAAM,GAAG,EAAE,CAAC,CACZ,QAAQ,kBAAkB,EAAE;CAC/B,IAAI,CAAC,aAAa,gBAAgB,SAAS,SAAS,GAAG,OAAO,KAAA;CAC9D,OAAO;AACT;;;;;AA4BA,SAAgB,kBAAkB,OAAmC;CACnE,MAAM,SAAS,MACZ,QAAQ,aAAa,EAAE,CAAC,CACxB,QAAQ,OAAO,EAAE,CAAC,CAClB,QAAQ,OAAO,EAAE;CACpB,OAAO,aAAa,KAAK,MAAM,IAAI,SAAS,KAAA;AAC9C;;AAGA,SAAgB,iBAAiB,MAA8C;CAC7E,OAAO,MAAM,YAAY,CAAC,CAAC,QAAQ,qBAAqB,EAAE,KAAK,KAAA;AACjE;;;;;;;AA4CA,MAAM,0CAA0B,IAAI,IAAI;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,2CAA2B,IAAI,IAAI;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;AAAK,CAAC;;;;;;AAO1F,SAAgB,aAAa,OAAuB,UAAuC;CACzF,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,OAAO,MAAM,KAA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,KAAK,eACH,OAAO;GAAE,MAAM;GAAiB,MAAM,mBAAmB,UAAU;EAAE;EACvE,SAAS;GACP,MAAM,WAAW,aAAa,UAAU;GACxC,OAAO;IACL,MAAM;IACN,MAAM;KACJ,MAAM;KACN,QAAQ,aAAa,UAAU,UAAU,GAAG,QAAQ;KACpD,UAAU,UAAU,YAAY;KAChC,UAAU,YAAY,UAAU,UAAU,GAAG,QAAQ;IACvD;GACF;EACF;CACF;AACF"}
1
+ {"version":3,"file":"oaiq.mjs","names":[],"sources":["../../src/track/oaiq.ts"],"sourcesContent":["import type { Item } from './gtag';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\nexport const NON_AD_EVENTS = [\n // metrics\n 'CLS',\n 'FCP',\n 'FID',\n 'INP',\n 'LCP',\n 'TTFB',\n // promotions\n 'view_promotion',\n 'select_promotion',\n];\n\n/**\n * Content item shared by `contents` and `plan_enrollment` events.\n * https://developers.openai.com/ads/supported-events\n */\nexport type ContentItem = {\n id?: string;\n name?: string;\n content_type?: string;\n quantity?: number;\n /** Per-item monetary value in ISO 4217 minor units (e.g., 12,999 = $129.99 USD). */\n amount?: number;\n currency?: string;\n};\n\nexport type ContentsData = {\n type: 'contents';\n /** Monetary value in ISO 4217 minor units (e.g., 12,999 = $129.99 USD). */\n amount?: number;\n currency?: string;\n contents?: ContentItem[];\n};\n\nexport type CustomerActionData = {\n type: 'customer_action';\n amount?: number;\n currency?: string;\n};\n\nexport type PlanEnrollmentData = {\n type: 'plan_enrollment';\n plan_id?: string;\n amount?: number;\n currency?: string;\n contents?: ContentItem[];\n};\n\nexport type CustomEventData = {\n type: 'custom';\n amount?: number;\n currency?: string;\n contents?: ContentItem[];\n};\n\nexport type EventData = ContentsData | CustomerActionData | PlanEnrollmentData | CustomEventData;\n\n/**\n * Standard event names and the `data` shape each one expects.\n * https://developers.openai.com/ads/supported-events\n */\nexport type StandardEvents = {\n app_installed: CustomerActionData;\n app_opened: CustomerActionData;\n appointment_scheduled: CustomerActionData;\n checkout_started: ContentsData;\n contents_viewed: ContentsData;\n items_added: ContentsData;\n lead_created: CustomerActionData;\n order_created: ContentsData;\n page_viewed: ContentsData;\n registration_completed: CustomerActionData;\n subscription_created: PlanEnrollmentData;\n trial_started: PlanEnrollmentData;\n};\n\nexport type StandardEvent = keyof StandardEvents;\n\n/**\n * The app events, which OpenAI takes \"through the Conversions API only\", with `action_source`\n * `mobile_app`: the pixel never sends them, and the server only for an app's events.\n * https://developers.openai.com/ads/supported-events\n */\nexport const APP_EVENTS: readonly StandardEvent[] = ['app_installed', 'app_opened'];\n\nconst STANDARD_EVENTS: readonly string[] = [\n 'app_installed',\n 'app_opened',\n 'appointment_scheduled',\n 'checkout_started',\n 'contents_viewed',\n 'items_added',\n 'lead_created',\n 'order_created',\n 'page_viewed',\n 'registration_completed',\n 'subscription_created',\n 'trial_started',\n] satisfies StandardEvent[];\n\n/**\n * A track name as an OpenAI `custom_event_name`: 1–64 letters, digits, underscores or hyphens,\n * starting and ending with a letter or digit, not a standard event name; the API lowercases it.\n * Anything else becomes an underscore, so `Sign Up.Clicked` is `sign_up_clicked`. Undefined when\n * nothing usable is left — the event is then not sent at all. The pixel and the server both name\n * a custom event through this, so the two still deduplicate.\n * https://developers.openai.com/ads/supported-events\n */\nexport function oaiCustomEventName(name: string): string | undefined {\n const sanitized = name\n .toLowerCase()\n .replace(/[^a-z0-9_-]+/g, '_')\n .slice(0, 64)\n .replace(/^[_-]+|[_-]+$/g, '');\n if (!sanitized || STANDARD_EVENTS.includes(sanitized)) return undefined;\n return sanitized;\n}\n\n/**\n * Identity fields passed to `oaiq(\"init\", ...)` for conversion matching. Identifiers are\n * normalized, then sent as lowercase 64-char SHA-256 hex strings; geographic values are raw.\n * https://developers.openai.com/ads/measurement-pixel#send-user-data\n */\nexport type OAIQUser = {\n email_sha256?: string;\n /** 8–15 digits with the country code, no leading `+` or zeroes (`normalizeOAIPhone`). */\n phone_number_sha256?: string;\n external_id_sha256?: string;\n /** Lowercase, without whitespace or ASCII punctuation (`normalizeOAIName`). */\n first_name_sha256?: string;\n last_name_sha256?: string;\n /** Two-letter ISO 3166-1 country code (e.g. \"US\"). */\n country?: string;\n /** Max 128 characters; OpenAI trims and lowercases it. */\n city?: string;\n /** State, province or region, max 128 characters. */\n region?: string;\n postal_code?: string;\n};\n\n/**\n * A phone number as OpenAI hashes it: whitespace, parentheses, periods and hyphens removed, then\n * the leading `+` and zeroes; 8–15 digits with the country code, else not a usable number.\n */\nexport function normalizeOAIPhone(phone: string): string | undefined {\n const digits = phone\n .replace(/[\\s().-]/g, '')\n .replace(/^\\+/, '')\n .replace(/^0+/, '');\n return /^\\d{8,15}$/.test(digits) ? digits : undefined;\n}\n\n/** A name as OpenAI hashes it: lowercase, no whitespace or ASCII punctuation, accents kept. */\nexport function normalizeOAIName(name: string | undefined): string | undefined {\n return name?.toLowerCase().replace(/[\\s!-/:-@[-`{-~]/g, '') || undefined;\n}\n\nexport type InitConfig = {\n pixelId: string;\n /** Log SDK activity to the browser console. */\n debug?: boolean;\n user?: OAIQUser;\n};\n\n/**\n * Fourth argument of `oaiq(\"measure\", ...)`. Required for custom events (carries\n * `custom_event_name`); optional for standard events.\n */\nexport type MeasureOptions = {\n /** Shared with the Conversions API to deduplicate the same conversion across browser and server. */\n event_id?: string;\n /** Required for custom events; 1-64 chars of letters, numbers, underscores, or dashes. */\n custom_event_name?: string;\n /** When true, opts the event out of user-level personalization. */\n opt_out?: boolean;\n};\n\nexport interface OAIQ {\n oaiq(command: 'init', config: InitConfig): void;\n oaiq<T extends StandardEvent>(\n command: 'measure',\n event: T,\n data: StandardEvents[T],\n options?: MeasureOptions\n ): void;\n oaiq(\n command: 'measure',\n event: 'custom',\n data: CustomEventData,\n options: MeasureOptions & { custom_event_name: string }\n ): void;\n}\n\n/**\n * Currencies whose minor unit has 0 or 3 decimal places; everything else uses 2.\n * Follows Stripe's zero-decimal convention (e.g., MGA is treated as 0, ISK is included),\n * which can differ from strict ISO 4217 exponents.\n * https://docs.stripe.com/currencies#zero-decimal\n */\nconst ZERO_DECIMAL_CURRENCIES = new Set([\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'ISK',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n]);\nconst THREE_DECIMAL_CURRENCIES = new Set(['BHD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND']);\n\n/**\n * Convert a major-unit amount (e.g., 129.99) into ISO 4217 minor units (e.g., 12,999). None\n * without a currency: the minor unit depends on it, and OpenAI requires a `currency` with every\n * `amount` — an amount alone would be invalid, not just imprecise.\n */\nexport function toMinorUnits(value?: number | null, currency?: string): number | undefined {\n if (value === undefined || value === null || Number.isNaN(value)) return undefined;\n const code = currency?.toUpperCase();\n if (!code) return undefined;\n const exponent =\n code && ZERO_DECIMAL_CURRENCIES.has(code)\n ? 0\n : code && THREE_DECIMAL_CURRENCIES.has(code)\n ? 3\n : 2;\n return Math.round(value * 10 ** exponent);\n}\n\nexport function mapContents(items?: Item[], currency?: string): ContentItem[] | undefined {\n if (!items || items.length === 0) return undefined;\n const code = currency?.toUpperCase();\n return items.map((item) => {\n const amount = toMinorUnits(item.price, currency);\n return {\n id: item.item_id,\n name: item.item_name,\n content_type: item.item_category,\n quantity: item.quantity,\n amount,\n currency: amount !== undefined ? code : undefined,\n };\n });\n}\n\n/** Safely read a property off loosely typed track properties without widening to `any`. */\nfunction prop(properties: unknown, key: string): unknown {\n return typeof properties === 'object' && properties !== null\n ? (properties as Record<string, unknown>)[key]\n : undefined;\n}\n\nfunction readValue(properties: unknown): number | undefined {\n const value = prop(properties, 'value');\n return typeof value === 'number' ? value : undefined;\n}\n\nfunction readCurrency(properties: unknown): string | undefined {\n const currency = prop(properties, 'currency');\n return typeof currency === 'string' ? currency : undefined;\n}\n\nfunction readItems(properties: unknown): Item[] | undefined {\n const items = prop(properties, 'items');\n return Array.isArray(items) ? (items as Item[]) : undefined;\n}\n\nfunction contentsData(properties: unknown): ContentsData {\n const currency = readCurrency(properties);\n return {\n type: 'contents',\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n contents: mapContents(readItems(properties), currency),\n };\n}\n\nfunction customerActionData(properties: unknown): CustomerActionData {\n const currency = readCurrency(properties);\n return {\n type: 'customer_action',\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n };\n}\n\nfunction planEnrollmentData(properties: unknown): PlanEnrollmentData {\n const currency = readCurrency(properties);\n const items = readItems(properties);\n return {\n type: 'plan_enrollment',\n plan_id: items?.[0]?.item_id,\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n contents: mapContents(items, currency),\n };\n}\n\nexport type MappedOAIEvent = {\n type: StandardEvent | 'custom';\n data: EventData;\n};\n\n/** Map an internal track event onto an OpenAI standard (or custom) conversion event. */\nexport function mapOAIEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n): MappedOAIEvent {\n switch (name) {\n // The app's first launch, recorded once by the app hook: the closest thing to an install.\n case 'first_open':\n return { type: 'app_installed', data: customerActionData(properties) };\n case 'app_open':\n return { type: 'app_opened', data: customerActionData(properties) };\n case 'page_view':\n return { type: 'page_viewed', data: contentsData(properties) };\n case 'view_item':\n case 'view_item_list':\n return { type: 'contents_viewed', data: contentsData(properties) };\n case 'begin_checkout':\n return { type: 'checkout_started', data: contentsData(properties) };\n case 'add_to_cart':\n return { type: 'items_added', data: contentsData(properties) };\n case 'purchase':\n return { type: 'order_created', data: contentsData(properties) };\n case 'generate_lead':\n case 'qualify_lead':\n return { type: 'lead_created', data: customerActionData(properties) };\n case 'sign_up':\n case 'login':\n return { type: 'registration_completed', data: customerActionData(properties) };\n case 'schedule':\n return { type: 'appointment_scheduled', data: customerActionData(properties) };\n case 'subscribe':\n return { type: 'subscription_created', data: planEnrollmentData(properties) };\n case 'trial_begin':\n return { type: 'trial_started', data: planEnrollmentData(properties) };\n default: {\n const currency = readCurrency(properties);\n return {\n type: 'custom',\n data: {\n type: 'custom',\n amount: toMinorUnits(readValue(properties), currency),\n currency: currency?.toUpperCase(),\n contents: mapContents(readItems(properties), currency),\n },\n };\n }\n }\n}\n\n/** Whether `mapOAIEvent` turns the event into an OpenAI standard event rather than `custom`. */\nexport function isStandardOAIEvent(name: string): boolean {\n return mapOAIEvent(name as TrackName).type !== 'custom';\n}\n"],"mappings":";AAGA,MAAa,gBAAgB;CAE3B;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;AACF;;;;;;AAyEA,MAAa,aAAuC,CAAC,iBAAiB,YAAY;AAElF,MAAM,kBAAqC;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;AAUA,SAAgB,mBAAmB,MAAkC;CACnE,MAAM,YAAY,KACf,YAAY,CAAC,CACb,QAAQ,iBAAiB,GAAG,CAAC,CAC7B,MAAM,GAAG,EAAE,CAAC,CACZ,QAAQ,kBAAkB,EAAE;CAC/B,IAAI,CAAC,aAAa,gBAAgB,SAAS,SAAS,GAAG,OAAO,KAAA;CAC9D,OAAO;AACT;;;;;AA4BA,SAAgB,kBAAkB,OAAmC;CACnE,MAAM,SAAS,MACZ,QAAQ,aAAa,EAAE,CAAC,CACxB,QAAQ,OAAO,EAAE,CAAC,CAClB,QAAQ,OAAO,EAAE;CACpB,OAAO,aAAa,KAAK,MAAM,IAAI,SAAS,KAAA;AAC9C;;AAGA,SAAgB,iBAAiB,MAA8C;CAC7E,OAAO,MAAM,YAAY,CAAC,CAAC,QAAQ,qBAAqB,EAAE,KAAK,KAAA;AACjE;;;;;;;AA4CA,MAAM,0CAA0B,IAAI,IAAI;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,2CAA2B,IAAI,IAAI;CAAC;CAAO;CAAO;CA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,YACH,OAAO;GAAE,MAAM;GAAyB,MAAM,mBAAmB,UAAU;EAAE;EAC/E,KAAK,aACH,OAAO;GAAE,MAAM;GAAwB,MAAM,mBAAmB,UAAU;EAAE;EAC9E,KAAK,eACH,OAAO;GAAE,MAAM;GAAiB,MAAM,mBAAmB,UAAU;EAAE;EACvE,SAAS;GACP,MAAM,WAAW,aAAa,UAAU;GACxC,OAAO;IACL,MAAM;IACN,MAAM;KACJ,MAAM;KACN,QAAQ,aAAa,UAAU,UAAU,GAAG,QAAQ;KACpD,UAAU,UAAU,YAAY;KAChC,UAAU,YAAY,UAAU,UAAU,GAAG,QAAQ;IACvD;GACF;EACF;CACF;AACF;;AAGA,SAAgB,mBAAmB,MAAuB;CACxD,OAAO,YAAY,IAAiB,CAAC,CAAC,SAAS;AACjD"}
@@ -65,6 +65,11 @@ function mapServerStandardEvent(name) {
65
65
  if (name === "Lead") return "LEAD";
66
66
  return "SIGN_UP";
67
67
  }
68
+ /** Whether `mapRDTEvent` turns the event into a Reddit standard event rather than `Custom`. */
69
+ function isStandardRDTEvent(name) {
70
+ return mapRDTEvent(name)[0] !== "Custom";
71
+ }
72
+ exports.isStandardRDTEvent = isStandardRDTEvent;
68
73
  exports.mapItems = mapItems;
69
74
  exports.mapRDTEvent = mapRDTEvent;
70
75
  exports.mapServerStandardEvent = mapServerStandardEvent;
@@ -1 +1 @@
1
- {"version":3,"file":"rdt.cjs","names":["itemKey"],"sources":["../../src/track/rdt.ts"],"sourcesContent":["import { type Item, itemKey } from './gtag';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\n/** https://business.reddithelp.com/s/article/about-event-metadata */\nexport type Product = {\n /**\n * (Required) Product ID: Either the SKU or GTIN, which represents the variant ID, not the\n * parent ID. If there are no variants, pass the assigned ID for that item.\n */\n id: string;\n\n /** (Optional) Product Category: The group the product belongs to. */\n name?: string;\n\n /** (Optional) Product Name: The title of the product. */\n category?: string;\n};\n\n/**\n * https://business.reddithelp.com/s/article/supported-conversion-events#supported-conversion-events\n * https://business.reddithelp.com/s/article/about-event-metadata\n * https://business.reddithelp.com/s/article/map-a-catalog-to-a-signal-source\n */\nexport type StandardEvents = {\n PageVisit: {\n conversionId?: string;\n products?: Product[];\n };\n ViewContent: {\n conversionId?: string;\n products?: Product[];\n };\n Search: {\n conversionId?: string;\n products?: Product[];\n };\n AddToCart: {\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n };\n AddToWishlist: {\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n };\n Purchase: {\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n };\n Lead: {\n value?: number;\n currency?: string;\n conversionId?: string;\n products?: Product[];\n };\n SignUp: {\n value?: number;\n currency?: string;\n conversionId?: string;\n products?: Product[];\n };\n};\n\nexport type PixelId = `a2_${string}`;\n\nexport type MatchKeys = {\n email?: string;\n phoneNumber?: string;\n externalId?: string;\n idfa?: string;\n aaid?: string;\n};\n\nexport type CustomEventParams<T extends string = string> = {\n customEventName: T;\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n};\n\nexport interface RDT {\n rdt(event: 'init', pixelId: PixelId, matchKeys?: MatchKeys): void;\n\n rdt<T extends keyof StandardEvents>(event: 'track', type: T, params?: StandardEvents[T]): void;\n\n rdt(event: 'track', type: 'Custom', params: CustomEventParams): void;\n}\n\ntype Mapped<F extends keyof StandardEvents> = [F, StandardEvents[F]];\ntype Missed<F extends string> = ['Custom', CustomEventParams<F>];\n\nexport function mapItems(items?: Item[]): undefined | Product[] {\n if (!items || items.length === 0) return undefined;\n return items.map((item) => ({\n id: itemKey(item),\n name: item.item_name,\n category: item.item_category,\n }));\n}\n\nexport function mapRDTEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n): Mapped<keyof StandardEvents> | Missed<TrackName<T>> {\n // standard events\n if (name === 'page_view') {\n return ['PageVisit', { conversionId: eventId }];\n } else if (name === 'view_item') {\n return ['ViewContent', { conversionId: eventId }];\n } else if (name === 'search') {\n return ['Search', { conversionId: eventId }];\n } else if (name === 'add_to_cart') {\n const p = properties as TrackProperties<'add_to_cart'> | undefined;\n return [\n 'AddToCart',\n {\n conversionId: eventId,\n value: p?.value,\n currency: p?.currency.toUpperCase(),\n itemCount: p?.items.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n products: mapItems(p?.items),\n },\n ];\n } else if (name === 'add_to_wishlist') {\n const p = properties as TrackProperties<'add_to_wishlist'> | undefined;\n return [\n 'AddToWishlist',\n {\n conversionId: eventId,\n value: p?.value,\n currency: p?.currency.toUpperCase(),\n itemCount: p?.items.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n products: mapItems(p?.items),\n },\n ];\n } else if (name === 'purchase') {\n const p = properties as TrackProperties<'purchase'> | undefined;\n return [\n 'Purchase',\n {\n conversionId: eventId,\n value: p?.value,\n currency: p?.currency.toUpperCase(),\n itemCount: p?.items?.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n products: mapItems(p?.items),\n },\n ];\n } else if (name === 'generate_lead') {\n const p = properties as TrackProperties<'generate_lead'> | undefined;\n return [\n 'Lead',\n { conversionId: eventId, value: p?.value, currency: p?.currency.toUpperCase() },\n ];\n } else if (name === 'sign_up' || name === 'login') {\n return ['SignUp', { conversionId: eventId }];\n } else {\n // custom event\n return [\n 'Custom',\n {\n customEventName: name,\n conversionId: eventId,\n value:\n properties && 'value' in properties && typeof properties.value === 'number'\n ? properties.value\n : undefined,\n currency:\n properties && 'currency' in properties && typeof properties.currency === 'string'\n ? properties.currency.toUpperCase()\n : undefined,\n },\n ];\n }\n}\n\nexport type ServerStandardEvent =\n | 'PAGE_VISIT'\n | 'VIEW_CONTENT'\n | 'SEARCH'\n | 'ADD_TO_CART'\n | 'ADD_TO_WISHLIST'\n | 'PURCHASE'\n | 'LEAD'\n | 'SIGN_UP';\n\nexport function mapServerStandardEvent(name: keyof StandardEvents): ServerStandardEvent {\n if (name === 'PageVisit') return 'PAGE_VISIT';\n if (name === 'ViewContent') return 'VIEW_CONTENT';\n if (name === 'Search') return 'SEARCH';\n if (name === 'AddToCart') return 'ADD_TO_CART';\n if (name === 'AddToWishlist') return 'ADD_TO_WISHLIST';\n if (name === 'Purchase') return 'PURCHASE';\n if (name === 'Lead') return 'LEAD';\n // `name` is narrowed to 'SignUp' here, so the mapping is exhaustive\n return 'SIGN_UP';\n}\n"],"mappings":";;;AAqGA,SAAgB,SAAS,OAAuC;CAC9D,IAAI,CAAC,SAAS,MAAM,WAAW,GAAG,OAAO,KAAA;CACzC,OAAO,MAAM,KAAK,UAAU;EAC1B,IAAIA,mBAAAA,QAAQ,IAAI;EAChB,MAAM,KAAK;EACX,UAAU,KAAK;CACjB,EAAE;AACJ;AAEA,SAAgB,YACd,MACA,YACA,SACqD;CAErD,IAAI,SAAS,aACX,OAAO,CAAC,aAAa,EAAE,cAAc,QAAQ,CAAC;MACzC,IAAI,SAAS,aAClB,OAAO,CAAC,eAAe,EAAE,cAAc,QAAQ,CAAC;MAC3C,IAAI,SAAS,UAClB,OAAO,CAAC,UAAU,EAAE,cAAc,QAAQ,CAAC;MACtC,IAAI,SAAS,eAAe;EACjC,MAAM,IAAI;EACV,OAAO,CACL,aACA;GACE,cAAc;GACd,OAAO,GAAG;GACV,UAAU,GAAG,SAAS,YAAY;GAClC,WAAW,GAAG,MAAM,QAAQ,KAAK,MAAM,OAAO,EAAE,YAAY,IAAI,CAAC;GACjE,UAAU,SAAS,GAAG,KAAK;EAC7B,CACF;CACF,OAAO,IAAI,SAAS,mBAAmB;EACrC,MAAM,IAAI;EACV,OAAO,CACL,iBACA;GACE,cAAc;GACd,OAAO,GAAG;GACV,UAAU,GAAG,SAAS,YAAY;GAClC,WAAW,GAAG,MAAM,QAAQ,KAAK,MAAM,OAAO,EAAE,YAAY,IAAI,CAAC;GACjE,UAAU,SAAS,GAAG,KAAK;EAC7B,CACF;CACF,OAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,IAAI;EACV,OAAO,CACL,YACA;GACE,cAAc;GACd,OAAO,GAAG;GACV,UAAU,GAAG,SAAS,YAAY;GAClC,WAAW,GAAG,OAAO,QAAQ,KAAK,MAAM,OAAO,EAAE,YAAY,IAAI,CAAC;GAClE,UAAU,SAAS,GAAG,KAAK;EAC7B,CACF;CACF,OAAO,IAAI,SAAS,iBAAiB;EACnC,MAAM,IAAI;EACV,OAAO,CACL,QACA;GAAE,cAAc;GAAS,OAAO,GAAG;GAAO,UAAU,GAAG,SAAS,YAAY;EAAE,CAChF;CACF,OAAO,IAAI,SAAS,aAAa,SAAS,SACxC,OAAO,CAAC,UAAU,EAAE,cAAc,QAAQ,CAAC;MAG3C,OAAO,CACL,UACA;EACE,iBAAiB;EACjB,cAAc;EACd,OACE,cAAc,WAAW,cAAc,OAAO,WAAW,UAAU,WAC/D,WAAW,QACX,KAAA;EACN,UACE,cAAc,cAAc,cAAc,OAAO,WAAW,aAAa,WACrE,WAAW,SAAS,YAAY,IAChC,KAAA;CACR,CACF;AAEJ;AAYA,SAAgB,uBAAuB,MAAiD;CACtF,IAAI,SAAS,aAAa,OAAO;CACjC,IAAI,SAAS,eAAe,OAAO;CACnC,IAAI,SAAS,UAAU,OAAO;CAC9B,IAAI,SAAS,aAAa,OAAO;CACjC,IAAI,SAAS,iBAAiB,OAAO;CACrC,IAAI,SAAS,YAAY,OAAO;CAChC,IAAI,SAAS,QAAQ,OAAO;CAE5B,OAAO;AACT"}
1
+ {"version":3,"file":"rdt.cjs","names":["itemKey"],"sources":["../../src/track/rdt.ts"],"sourcesContent":["import { type Item, itemKey } from './gtag';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\n/** https://business.reddithelp.com/s/article/about-event-metadata */\nexport type Product = {\n /**\n * (Required) Product ID: Either the SKU or GTIN, which represents the variant ID, not the\n * parent ID. If there are no variants, pass the assigned ID for that item.\n */\n id: string;\n\n /** (Optional) Product Category: The group the product belongs to. */\n name?: string;\n\n /** (Optional) Product Name: The title of the product. */\n category?: string;\n};\n\n/**\n * https://business.reddithelp.com/s/article/supported-conversion-events#supported-conversion-events\n * https://business.reddithelp.com/s/article/about-event-metadata\n * https://business.reddithelp.com/s/article/map-a-catalog-to-a-signal-source\n */\nexport type StandardEvents = {\n PageVisit: {\n conversionId?: string;\n products?: Product[];\n };\n ViewContent: {\n conversionId?: string;\n products?: Product[];\n };\n Search: {\n conversionId?: string;\n products?: Product[];\n };\n AddToCart: {\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n };\n AddToWishlist: {\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n };\n Purchase: {\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n };\n Lead: {\n value?: number;\n currency?: string;\n conversionId?: string;\n products?: Product[];\n };\n SignUp: {\n value?: number;\n currency?: string;\n conversionId?: string;\n products?: Product[];\n };\n};\n\nexport type PixelId = `a2_${string}`;\n\nexport type MatchKeys = {\n email?: string;\n phoneNumber?: string;\n externalId?: string;\n idfa?: string;\n aaid?: string;\n};\n\nexport type CustomEventParams<T extends string = string> = {\n customEventName: T;\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n};\n\nexport interface RDT {\n rdt(event: 'init', pixelId: PixelId, matchKeys?: MatchKeys): void;\n\n rdt<T extends keyof StandardEvents>(event: 'track', type: T, params?: StandardEvents[T]): void;\n\n rdt(event: 'track', type: 'Custom', params: CustomEventParams): void;\n}\n\ntype Mapped<F extends keyof StandardEvents> = [F, StandardEvents[F]];\ntype Missed<F extends string> = ['Custom', CustomEventParams<F>];\n\nexport function mapItems(items?: Item[]): undefined | Product[] {\n if (!items || items.length === 0) return undefined;\n return items.map((item) => ({\n id: itemKey(item),\n name: item.item_name,\n category: item.item_category,\n }));\n}\n\nexport function mapRDTEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n): Mapped<keyof StandardEvents> | Missed<TrackName<T>> {\n // standard events\n if (name === 'page_view') {\n return ['PageVisit', { conversionId: eventId }];\n } else if (name === 'view_item') {\n return ['ViewContent', { conversionId: eventId }];\n } else if (name === 'search') {\n return ['Search', { conversionId: eventId }];\n } else if (name === 'add_to_cart') {\n const p = properties as TrackProperties<'add_to_cart'> | undefined;\n return [\n 'AddToCart',\n {\n conversionId: eventId,\n value: p?.value,\n currency: p?.currency.toUpperCase(),\n itemCount: p?.items.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n products: mapItems(p?.items),\n },\n ];\n } else if (name === 'add_to_wishlist') {\n const p = properties as TrackProperties<'add_to_wishlist'> | undefined;\n return [\n 'AddToWishlist',\n {\n conversionId: eventId,\n value: p?.value,\n currency: p?.currency.toUpperCase(),\n itemCount: p?.items.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n products: mapItems(p?.items),\n },\n ];\n } else if (name === 'purchase') {\n const p = properties as TrackProperties<'purchase'> | undefined;\n return [\n 'Purchase',\n {\n conversionId: eventId,\n value: p?.value,\n currency: p?.currency.toUpperCase(),\n itemCount: p?.items?.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n products: mapItems(p?.items),\n },\n ];\n } else if (name === 'generate_lead') {\n const p = properties as TrackProperties<'generate_lead'> | undefined;\n return [\n 'Lead',\n { conversionId: eventId, value: p?.value, currency: p?.currency.toUpperCase() },\n ];\n } else if (name === 'sign_up' || name === 'login') {\n return ['SignUp', { conversionId: eventId }];\n } else {\n // custom event\n return [\n 'Custom',\n {\n customEventName: name,\n conversionId: eventId,\n value:\n properties && 'value' in properties && typeof properties.value === 'number'\n ? properties.value\n : undefined,\n currency:\n properties && 'currency' in properties && typeof properties.currency === 'string'\n ? properties.currency.toUpperCase()\n : undefined,\n },\n ];\n }\n}\n\nexport type ServerStandardEvent =\n | 'PAGE_VISIT'\n | 'VIEW_CONTENT'\n | 'SEARCH'\n | 'ADD_TO_CART'\n | 'ADD_TO_WISHLIST'\n | 'PURCHASE'\n | 'LEAD'\n | 'SIGN_UP';\n\nexport function mapServerStandardEvent(name: keyof StandardEvents): ServerStandardEvent {\n if (name === 'PageVisit') return 'PAGE_VISIT';\n if (name === 'ViewContent') return 'VIEW_CONTENT';\n if (name === 'Search') return 'SEARCH';\n if (name === 'AddToCart') return 'ADD_TO_CART';\n if (name === 'AddToWishlist') return 'ADD_TO_WISHLIST';\n if (name === 'Purchase') return 'PURCHASE';\n if (name === 'Lead') return 'LEAD';\n // `name` is narrowed to 'SignUp' here, so the mapping is exhaustive\n return 'SIGN_UP';\n}\n\n/** Whether `mapRDTEvent` turns the event into a Reddit standard event rather than `Custom`. */\nexport function isStandardRDTEvent(name: string): boolean {\n return mapRDTEvent(name as TrackName)[0] !== 'Custom';\n}\n"],"mappings":";;;AAqGA,SAAgB,SAAS,OAAuC;CAC9D,IAAI,CAAC,SAAS,MAAM,WAAW,GAAG,OAAO,KAAA;CACzC,OAAO,MAAM,KAAK,UAAU;EAC1B,IAAIA,mBAAAA,QAAQ,IAAI;EAChB,MAAM,KAAK;EACX,UAAU,KAAK;CACjB,EAAE;AACJ;AAEA,SAAgB,YACd,MACA,YACA,SACqD;CAErD,IAAI,SAAS,aACX,OAAO,CAAC,aAAa,EAAE,cAAc,QAAQ,CAAC;MACzC,IAAI,SAAS,aAClB,OAAO,CAAC,eAAe,EAAE,cAAc,QAAQ,CAAC;MAC3C,IAAI,SAAS,UAClB,OAAO,CAAC,UAAU,EAAE,cAAc,QAAQ,CAAC;MACtC,IAAI,SAAS,eAAe;EACjC,MAAM,IAAI;EACV,OAAO,CACL,aACA;GACE,cAAc;GACd,OAAO,GAAG;GACV,UAAU,GAAG,SAAS,YAAY;GAClC,WAAW,GAAG,MAAM,QAAQ,KAAK,MAAM,OAAO,EAAE,YAAY,IAAI,CAAC;GACjE,UAAU,SAAS,GAAG,KAAK;EAC7B,CACF;CACF,OAAO,IAAI,SAAS,mBAAmB;EACrC,MAAM,IAAI;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+91,7 @@ export declare function mapItems(items?: Item[]): undefined | Product[];
91
91
  export declare function mapRDTEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, eventId?: string): Mapped<keyof StandardEvents> | Missed<TrackName<T>>;
92
92
  export type ServerStandardEvent = 'PAGE_VISIT' | 'VIEW_CONTENT' | 'SEARCH' | 'ADD_TO_CART' | 'ADD_TO_WISHLIST' | 'PURCHASE' | 'LEAD' | 'SIGN_UP';
93
93
  export declare function mapServerStandardEvent(name: keyof StandardEvents): ServerStandardEvent;
94
+ /** Whether `mapRDTEvent` turns the event into a Reddit standard event rather than `Custom`. */
95
+ export declare function isStandardRDTEvent(name: string): boolean;
94
96
  export {};
95
97
  //# sourceMappingURL=rdt.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rdt.d.cts","names":[],"sources":["../../src/track/rdt.ts"],"mappings":";;;YAIY;;;;;EAKV;;EAGA;;EAGA;;;;;;;YAQU;EACV;IACE;IACA,WAAW;;EAEb;IACE;IACA,WAAW;;EAEb;IACE;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA,WAAW;;;YAIH;YAEA;EACV;EACA;EACA;EACA;EACA;;YAGU,kBAAkB;EAC5B,iBAAiB;EACjB;EACA;EACA;EACA;EACA,WAAW;;iBAGI;EACf,IAAI,eAAe,SAAS,SAAS,YAAY;EAEjD,IAAI,gBAAgB,gBAAgB,gBAAgB,MAAM,GAAG,SAAS,eAAe;EAErF,IAAI,gBAAgB,gBAAgB,QAAQ;;KAGzC,OAAO,gBAAgB,mBAAmB,GAAG,eAAe;KAC5D,OAAO,+BAA+B,kBAAkB;wBAE7C,SAAS,QAAQ,qBAAqB;wBAStC,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B,mBACC,aAAa,kBAAkB,OAAO,UAAU;YAwEvC;wBAUI,uBAAuB,YAAY,iBAAiB"}
1
+ {"version":3,"file":"rdt.d.cts","names":[],"sources":["../../src/track/rdt.ts"],"mappings":";;;YAIY;;;;;EAKV;;EAGA;;EAGA;;;;;;;YAQU;EACV;IACE;IACA,WAAW;;EAEb;IACE;IACA,WAAW;;EAEb;IACE;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA,WAAW;;;YAIH;YAEA;EACV;EACA;EACA;EACA;EACA;;YAGU,kBAAkB;EAC5B,iBAAiB;EACjB;EACA;EACA;EACA;EACA,WAAW;;iBAGI;EACf,IAAI,eAAe,SAAS,SAAS,YAAY;EAEjD,IAAI,gBAAgB,gBAAgB,gBAAgB,MAAM,GAAG,SAAS,eAAe;EAErF,IAAI,gBAAgB,gBAAgB,QAAQ;;KAGzC,OAAO,gBAAgB,mBAAmB,GAAG,eAAe;KAC5D,OAAO,+BAA+B,kBAAkB;wBAE7C,SAAS,QAAQ,qBAAqB;wBAStC,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B,mBACC,aAAa,kBAAkB,OAAO,UAAU;YAwEvC;wBAUI,uBAAuB,YAAY,iBAAiB;;wBAapD,mBAAmB"}
@@ -91,5 +91,7 @@ export declare function mapItems(items?: Item[]): undefined | Product[];
91
91
  export declare function mapRDTEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, eventId?: string): Mapped<keyof StandardEvents> | Missed<TrackName<T>>;
92
92
  export type ServerStandardEvent = 'PAGE_VISIT' | 'VIEW_CONTENT' | 'SEARCH' | 'ADD_TO_CART' | 'ADD_TO_WISHLIST' | 'PURCHASE' | 'LEAD' | 'SIGN_UP';
93
93
  export declare function mapServerStandardEvent(name: keyof StandardEvents): ServerStandardEvent;
94
+ /** Whether `mapRDTEvent` turns the event into a Reddit standard event rather than `Custom`. */
95
+ export declare function isStandardRDTEvent(name: string): boolean;
94
96
  export {};
95
97
  //# sourceMappingURL=rdt.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rdt.d.mts","names":[],"sources":["../../src/track/rdt.ts"],"mappings":";;;YAIY;;;;;EAKV;;EAGA;;EAGA;;;;;;;YAQU;EACV;IACE;IACA,WAAW;;EAEb;IACE;IACA,WAAW;;EAEb;IACE;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA,WAAW;;;YAIH;YAEA;EACV;EACA;EACA;EACA;EACA;;YAGU,kBAAkB;EAC5B,iBAAiB;EACjB;EACA;EACA;EACA;EACA,WAAW;;iBAGI;EACf,IAAI,eAAe,SAAS,SAAS,YAAY;EAEjD,IAAI,gBAAgB,gBAAgB,gBAAgB,MAAM,GAAG,SAAS,eAAe;EAErF,IAAI,gBAAgB,gBAAgB,QAAQ;;KAGzC,OAAO,gBAAgB,mBAAmB,GAAG,eAAe;KAC5D,OAAO,+BAA+B,kBAAkB;wBAE7C,SAAS,QAAQ,qBAAqB;wBAStC,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B,mBACC,aAAa,kBAAkB,OAAO,UAAU;YAwEvC;wBAUI,uBAAuB,YAAY,iBAAiB"}
1
+ {"version":3,"file":"rdt.d.mts","names":[],"sources":["../../src/track/rdt.ts"],"mappings":";;;YAIY;;;;;EAKV;;EAGA;;EAGA;;;;;;;YAQU;EACV;IACE;IACA,WAAW;;EAEb;IACE;IACA,WAAW;;EAEb;IACE;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA,WAAW;;EAEb;IACE;IACA;IACA;IACA,WAAW;;;YAIH;YAEA;EACV;EACA;EACA;EACA;EACA;;YAGU,kBAAkB;EAC5B,iBAAiB;EACjB;EACA;EACA;EACA;EACA,WAAW;;iBAGI;EACf,IAAI,eAAe,SAAS,SAAS,YAAY;EAEjD,IAAI,gBAAgB,gBAAgB,gBAAgB,MAAM,GAAG,SAAS,eAAe;EAErF,IAAI,gBAAgB,gBAAgB,QAAQ;;KAGzC,OAAO,gBAAgB,mBAAmB,GAAG,eAAe;KAC5D,OAAO,+BAA+B,kBAAkB;wBAE7C,SAAS,QAAQ,qBAAqB;wBAStC,YAAY,UAAU,WACpC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B,mBACC,aAAa,kBAAkB,OAAO,UAAU;YAwEvC;wBAUI,uBAAuB,YAAY,iBAAiB;;wBAapD,mBAAmB"}
@@ -64,6 +64,10 @@ function mapServerStandardEvent(name) {
64
64
  if (name === "Lead") return "LEAD";
65
65
  return "SIGN_UP";
66
66
  }
67
- export { mapItems, mapRDTEvent, mapServerStandardEvent };
67
+ /** Whether `mapRDTEvent` turns the event into a Reddit standard event rather than `Custom`. */
68
+ function isStandardRDTEvent(name) {
69
+ return mapRDTEvent(name)[0] !== "Custom";
70
+ }
71
+ export { isStandardRDTEvent, mapItems, mapRDTEvent, mapServerStandardEvent };
68
72
 
69
73
  //# sourceMappingURL=rdt.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"rdt.mjs","names":[],"sources":["../../src/track/rdt.ts"],"sourcesContent":["import { type Item, itemKey } from './gtag';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\n/** https://business.reddithelp.com/s/article/about-event-metadata */\nexport type Product = {\n /**\n * (Required) Product ID: Either the SKU or GTIN, which represents the variant ID, not the\n * parent ID. If there are no variants, pass the assigned ID for that item.\n */\n id: string;\n\n /** (Optional) Product Category: The group the product belongs to. */\n name?: string;\n\n /** (Optional) Product Name: The title of the product. */\n category?: string;\n};\n\n/**\n * https://business.reddithelp.com/s/article/supported-conversion-events#supported-conversion-events\n * https://business.reddithelp.com/s/article/about-event-metadata\n * https://business.reddithelp.com/s/article/map-a-catalog-to-a-signal-source\n */\nexport type StandardEvents = {\n PageVisit: {\n conversionId?: string;\n products?: Product[];\n };\n ViewContent: {\n conversionId?: string;\n products?: Product[];\n };\n Search: {\n conversionId?: string;\n products?: Product[];\n };\n AddToCart: {\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n };\n AddToWishlist: {\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n };\n Purchase: {\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n };\n Lead: {\n value?: number;\n currency?: string;\n conversionId?: string;\n products?: Product[];\n };\n SignUp: {\n value?: number;\n currency?: string;\n conversionId?: string;\n products?: Product[];\n };\n};\n\nexport type PixelId = `a2_${string}`;\n\nexport type MatchKeys = {\n email?: string;\n phoneNumber?: string;\n externalId?: string;\n idfa?: string;\n aaid?: string;\n};\n\nexport type CustomEventParams<T extends string = string> = {\n customEventName: T;\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n};\n\nexport interface RDT {\n rdt(event: 'init', pixelId: PixelId, matchKeys?: MatchKeys): void;\n\n rdt<T extends keyof StandardEvents>(event: 'track', type: T, params?: StandardEvents[T]): void;\n\n rdt(event: 'track', type: 'Custom', params: CustomEventParams): void;\n}\n\ntype Mapped<F extends keyof StandardEvents> = [F, StandardEvents[F]];\ntype Missed<F extends string> = ['Custom', CustomEventParams<F>];\n\nexport function mapItems(items?: Item[]): undefined | Product[] {\n if (!items || items.length === 0) return undefined;\n return items.map((item) => ({\n id: itemKey(item),\n name: item.item_name,\n category: item.item_category,\n }));\n}\n\nexport function mapRDTEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n): Mapped<keyof StandardEvents> | Missed<TrackName<T>> {\n // standard events\n if (name === 'page_view') {\n return ['PageVisit', { conversionId: eventId }];\n } else if (name === 'view_item') {\n return ['ViewContent', { conversionId: eventId }];\n } else if (name === 'search') {\n return ['Search', { conversionId: eventId }];\n } else if (name === 'add_to_cart') {\n const p = properties as TrackProperties<'add_to_cart'> | undefined;\n return [\n 'AddToCart',\n {\n conversionId: eventId,\n value: p?.value,\n currency: p?.currency.toUpperCase(),\n itemCount: p?.items.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n products: mapItems(p?.items),\n },\n ];\n } else if (name === 'add_to_wishlist') {\n const p = properties as TrackProperties<'add_to_wishlist'> | undefined;\n return [\n 'AddToWishlist',\n {\n conversionId: eventId,\n value: p?.value,\n currency: p?.currency.toUpperCase(),\n itemCount: p?.items.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n products: mapItems(p?.items),\n },\n ];\n } else if (name === 'purchase') {\n const p = properties as TrackProperties<'purchase'> | undefined;\n return [\n 'Purchase',\n {\n conversionId: eventId,\n value: p?.value,\n currency: p?.currency.toUpperCase(),\n itemCount: p?.items?.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n products: mapItems(p?.items),\n },\n ];\n } else if (name === 'generate_lead') {\n const p = properties as TrackProperties<'generate_lead'> | undefined;\n return [\n 'Lead',\n { conversionId: eventId, value: p?.value, currency: p?.currency.toUpperCase() },\n ];\n } else if (name === 'sign_up' || name === 'login') {\n return ['SignUp', { conversionId: eventId }];\n } else {\n // custom event\n return [\n 'Custom',\n {\n customEventName: name,\n conversionId: eventId,\n value:\n properties && 'value' in properties && typeof properties.value === 'number'\n ? properties.value\n : undefined,\n currency:\n properties && 'currency' in properties && typeof properties.currency === 'string'\n ? properties.currency.toUpperCase()\n : undefined,\n },\n ];\n }\n}\n\nexport type ServerStandardEvent =\n | 'PAGE_VISIT'\n | 'VIEW_CONTENT'\n | 'SEARCH'\n | 'ADD_TO_CART'\n | 'ADD_TO_WISHLIST'\n | 'PURCHASE'\n | 'LEAD'\n | 'SIGN_UP';\n\nexport function mapServerStandardEvent(name: keyof StandardEvents): ServerStandardEvent {\n if (name === 'PageVisit') return 'PAGE_VISIT';\n if (name === 'ViewContent') return 'VIEW_CONTENT';\n if (name === 'Search') return 'SEARCH';\n if (name === 'AddToCart') return 'ADD_TO_CART';\n if (name === 'AddToWishlist') return 'ADD_TO_WISHLIST';\n if (name === 'Purchase') return 'PURCHASE';\n if (name === 'Lead') return 'LEAD';\n // `name` is narrowed to 'SignUp' here, so the mapping is exhaustive\n return 'SIGN_UP';\n}\n"],"mappings":";;AAqGA,SAAgB,SAAS,OAAuC;CAC9D,IAAI,CAAC,SAAS,MAAM,WAAW,GAAG,OAAO,KAAA;CACzC,OAAO,MAAM,KAAK,UAAU;EAC1B,IAAI,QAAQ,IAAI;EAChB,MAAM,KAAK;EACX,UAAU,KAAK;CACjB,EAAE;AACJ;AAEA,SAAgB,YACd,MACA,YACA,SACqD;CAErD,IAAI,SAAS,aACX,OAAO,CAAC,aAAa,EAAE,cAAc,QAAQ,CAAC;MACzC,IAAI,SAAS,aAClB,OAAO,CAAC,eAAe,EAAE,cAAc,QAAQ,CAAC;MAC3C,IAAI,SAAS,UAClB,OAAO,CAAC,UAAU,EAAE,cAAc,QAAQ,CAAC;MACtC,IAAI,SAAS,eAAe;EACjC,MAAM,IAAI;EACV,OAAO,CACL,aACA;GACE,cAAc;GACd,OAAO,GAAG;GACV,UAAU,GAAG,SAAS,YAAY;GAClC,WAAW,GAAG,MAAM,QAAQ,KAAK,MAAM,OAAO,EAAE,YAAY,IAAI,CAAC;GACjE,UAAU,SAAS,GAAG,KAAK;EAC7B,CACF;CACF,OAAO,IAAI,SAAS,mBAAmB;EACrC,MAAM,IAAI;EACV,OAAO,CACL,iBACA;GACE,cAAc;GACd,OAAO,GAAG;GACV,UAAU,GAAG,SAAS,YAAY;GAClC,WAAW,GAAG,MAAM,QAAQ,KAAK,MAAM,OAAO,EAAE,YAAY,IAAI,CAAC;GACjE,UAAU,SAAS,GAAG,KAAK;EAC7B,CACF;CACF,OAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,IAAI;EACV,OAAO,CACL,YACA;GACE,cAAc;GACd,OAAO,GAAG;GACV,UAAU,GAAG,SAAS,YAAY;GAClC,WAAW,GAAG,OAAO,QAAQ,KAAK,MAAM,OAAO,EAAE,YAAY,IAAI,CAAC;GAClE,UAAU,SAAS,GAAG,KAAK;EAC7B,CACF;CACF,OAAO,IAAI,SAAS,iBAAiB;EACnC,MAAM,IAAI;EACV,OAAO,CACL,QACA;GAAE,cAAc;GAAS,OAAO,GAAG;GAAO,UAAU,GAAG,SAAS,YAAY;EAAE,CAChF;CACF,OAAO,IAAI,SAAS,aAAa,SAAS,SACxC,OAAO,CAAC,UAAU,EAAE,cAAc,QAAQ,CAAC;MAG3C,OAAO,CACL,UACA;EACE,iBAAiB;EACjB,cAAc;EACd,OACE,cAAc,WAAW,cAAc,OAAO,WAAW,UAAU,WAC/D,WAAW,QACX,KAAA;EACN,UACE,cAAc,cAAc,cAAc,OAAO,WAAW,aAAa,WACrE,WAAW,SAAS,YAAY,IAChC,KAAA;CACR,CACF;AAEJ;AAYA,SAAgB,uBAAuB,MAAiD;CACtF,IAAI,SAAS,aAAa,OAAO;CACjC,IAAI,SAAS,eAAe,OAAO;CACnC,IAAI,SAAS,UAAU,OAAO;CAC9B,IAAI,SAAS,aAAa,OAAO;CACjC,IAAI,SAAS,iBAAiB,OAAO;CACrC,IAAI,SAAS,YAAY,OAAO;CAChC,IAAI,SAAS,QAAQ,OAAO;CAE5B,OAAO;AACT"}
1
+ {"version":3,"file":"rdt.mjs","names":[],"sources":["../../src/track/rdt.ts"],"sourcesContent":["import { type Item, itemKey } from './gtag';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\n/** https://business.reddithelp.com/s/article/about-event-metadata */\nexport type Product = {\n /**\n * (Required) Product ID: Either the SKU or GTIN, which represents the variant ID, not the\n * parent ID. If there are no variants, pass the assigned ID for that item.\n */\n id: string;\n\n /** (Optional) Product Category: The group the product belongs to. */\n name?: string;\n\n /** (Optional) Product Name: The title of the product. */\n category?: string;\n};\n\n/**\n * https://business.reddithelp.com/s/article/supported-conversion-events#supported-conversion-events\n * https://business.reddithelp.com/s/article/about-event-metadata\n * https://business.reddithelp.com/s/article/map-a-catalog-to-a-signal-source\n */\nexport type StandardEvents = {\n PageVisit: {\n conversionId?: string;\n products?: Product[];\n };\n ViewContent: {\n conversionId?: string;\n products?: Product[];\n };\n Search: {\n conversionId?: string;\n products?: Product[];\n };\n AddToCart: {\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n };\n AddToWishlist: {\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n };\n Purchase: {\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n };\n Lead: {\n value?: number;\n currency?: string;\n conversionId?: string;\n products?: Product[];\n };\n SignUp: {\n value?: number;\n currency?: string;\n conversionId?: string;\n products?: Product[];\n };\n};\n\nexport type PixelId = `a2_${string}`;\n\nexport type MatchKeys = {\n email?: string;\n phoneNumber?: string;\n externalId?: string;\n idfa?: string;\n aaid?: string;\n};\n\nexport type CustomEventParams<T extends string = string> = {\n customEventName: T;\n value?: number;\n currency?: string;\n itemCount?: number;\n conversionId?: string;\n products?: Product[];\n};\n\nexport interface RDT {\n rdt(event: 'init', pixelId: PixelId, matchKeys?: MatchKeys): void;\n\n rdt<T extends keyof StandardEvents>(event: 'track', type: T, params?: StandardEvents[T]): void;\n\n rdt(event: 'track', type: 'Custom', params: CustomEventParams): void;\n}\n\ntype Mapped<F extends keyof StandardEvents> = [F, StandardEvents[F]];\ntype Missed<F extends string> = ['Custom', CustomEventParams<F>];\n\nexport function mapItems(items?: Item[]): undefined | Product[] {\n if (!items || items.length === 0) return undefined;\n return items.map((item) => ({\n id: itemKey(item),\n name: item.item_name,\n category: item.item_category,\n }));\n}\n\nexport function mapRDTEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n): Mapped<keyof StandardEvents> | Missed<TrackName<T>> {\n // standard events\n if (name === 'page_view') {\n return ['PageVisit', { conversionId: eventId }];\n } else if (name === 'view_item') {\n return ['ViewContent', { conversionId: eventId }];\n } else if (name === 'search') {\n return ['Search', { conversionId: eventId }];\n } else if (name === 'add_to_cart') {\n const p = properties as TrackProperties<'add_to_cart'> | undefined;\n return [\n 'AddToCart',\n {\n conversionId: eventId,\n value: p?.value,\n currency: p?.currency.toUpperCase(),\n itemCount: p?.items.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n products: mapItems(p?.items),\n },\n ];\n } else if (name === 'add_to_wishlist') {\n const p = properties as TrackProperties<'add_to_wishlist'> | undefined;\n return [\n 'AddToWishlist',\n {\n conversionId: eventId,\n value: p?.value,\n currency: p?.currency.toUpperCase(),\n itemCount: p?.items.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n products: mapItems(p?.items),\n },\n ];\n } else if (name === 'purchase') {\n const p = properties as TrackProperties<'purchase'> | undefined;\n return [\n 'Purchase',\n {\n conversionId: eventId,\n value: p?.value,\n currency: p?.currency.toUpperCase(),\n itemCount: p?.items?.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n products: mapItems(p?.items),\n },\n ];\n } else if (name === 'generate_lead') {\n const p = properties as TrackProperties<'generate_lead'> | undefined;\n return [\n 'Lead',\n { conversionId: eventId, value: p?.value, currency: p?.currency.toUpperCase() },\n ];\n } else if (name === 'sign_up' || name === 'login') {\n return ['SignUp', { conversionId: eventId }];\n } else {\n // custom event\n return [\n 'Custom',\n {\n customEventName: name,\n conversionId: eventId,\n value:\n properties && 'value' in properties && typeof properties.value === 'number'\n ? properties.value\n : undefined,\n currency:\n properties && 'currency' in properties && typeof properties.currency === 'string'\n ? properties.currency.toUpperCase()\n : undefined,\n },\n ];\n }\n}\n\nexport type ServerStandardEvent =\n | 'PAGE_VISIT'\n | 'VIEW_CONTENT'\n | 'SEARCH'\n | 'ADD_TO_CART'\n | 'ADD_TO_WISHLIST'\n | 'PURCHASE'\n | 'LEAD'\n | 'SIGN_UP';\n\nexport function mapServerStandardEvent(name: keyof StandardEvents): ServerStandardEvent {\n if (name === 'PageVisit') return 'PAGE_VISIT';\n if (name === 'ViewContent') return 'VIEW_CONTENT';\n if (name === 'Search') return 'SEARCH';\n if (name === 'AddToCart') return 'ADD_TO_CART';\n if (name === 'AddToWishlist') return 'ADD_TO_WISHLIST';\n if (name === 'Purchase') return 'PURCHASE';\n if (name === 'Lead') return 'LEAD';\n // `name` is narrowed to 'SignUp' here, so the mapping is exhaustive\n return 'SIGN_UP';\n}\n\n/** Whether `mapRDTEvent` turns the event into a Reddit standard event rather than `Custom`. */\nexport function isStandardRDTEvent(name: string): boolean {\n return mapRDTEvent(name as TrackName)[0] !== 'Custom';\n}\n"],"mappings":";;AAqGA,SAAgB,SAAS,OAAuC;CAC9D,IAAI,CAAC,SAAS,MAAM,WAAW,GAAG,OAAO,KAAA;CACzC,OAAO,MAAM,KAAK,UAAU;EAC1B,IAAI,QAAQ,IAAI;EAChB,MAAM,KAAK;EACX,UAAU,KAAK;CACjB,EAAE;AACJ;AAEA,SAAgB,YACd,MACA,YACA,SACqD;CAErD,IAAI,SAAS,aACX,OAAO,CAAC,aAAa,EAAE,cAAc,QAAQ,CAAC;MACzC,IAAI,SAAS,aAClB,OAAO,CAAC,eAAe,EAAE,cAAc,QAAQ,CAAC;MAC3C,IAAI,SAAS,UAClB,OAAO,CAAC,UAAU,EAAE,cAAc,QAAQ,CAAC;MACtC,IAAI,SAAS,eAAe;EACjC,MAAM,IAAI;EACV,OAAO,CACL,aACA;GACE,cAAc;GACd,OAAO,GAAG;GACV,UAAU,GAAG,SAAS,YAAY;GAClC,WAAW,GAAG,MAAM,QAAQ,KAAK,MAAM,OAAO,EAAE,Y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E5B,OAAO;AACT;;AAGA,SAAgB,mBAAmB,MAAuB;CACxD,OAAO,YAAY,IAAiB,CAAC,CAAC,OAAO;AAC/C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/analytics",
3
- "version": "16.0.0",
3
+ "version": "16.2.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -130,16 +130,6 @@
130
130
  "types": "./dist/server/index.d.cts",
131
131
  "default": "./dist/server/index.cjs"
132
132
  }
133
- },
134
- "./server/legacy": {
135
- "import": {
136
- "types": "./dist/server/legacy.d.mts",
137
- "default": "./dist/server/legacy.mjs"
138
- },
139
- "require": {
140
- "types": "./dist/server/legacy.d.cts",
141
- "default": "./dist/server/legacy.cjs"
142
- }
143
133
  }
144
134
  },
145
135
  "publishConfig": {
@@ -157,7 +147,6 @@
157
147
  "@repo/typescript-config": "0.0.0",
158
148
  "@testing-library/react": "^16.3.3",
159
149
  "@types/babel__core": "7.20.5",
160
- "@types/facebook-nodejs-business-sdk": "^24.0.0",
161
150
  "@types/node": "^26.6.5",
162
151
  "@types/react": "^19.3.0",
163
152
  "@types/react-dom": "^19.3.0",
@@ -180,7 +169,6 @@
180
169
  "expo-localization": "^57.0.2 || ^58.0.0",
181
170
  "expo-sqlite": "^57.0.3 || ^58.0.0",
182
171
  "expo-tracking-transparency": "^57.0.2 || ^58.0.0",
183
- "facebook-nodejs-business-sdk": "^24.0.1",
184
172
  "next": "^16.4.3",
185
173
  "posthog-js": "^1.438.21",
186
174
  "react": "^19.3.1",
@@ -217,9 +205,6 @@
217
205
  "expo-tracking-transparency": {
218
206
  "optional": true
219
207
  },
220
- "facebook-nodejs-business-sdk": {
221
- "optional": true
222
- },
223
208
  "next": {
224
209
  "optional": true
225
210
  },
@@ -1,23 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_third_parties_posthog = require("../third-parties/posthog.cjs");
3
- let react = require("react");
4
- // src/react/use-feature-flag.ts
5
- const noop = () => {};
6
- /** Subscribes to flag (re)loads; on the stub the subscription is queued and has no unsubscribe. */
7
- function subscribe(onChange) {
8
- return require_third_parties_posthog.getPosthog()?.onFeatureFlags(onChange) ?? noop;
9
- }
10
- /**
11
- * A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`
12
- * until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).
13
- * `undefined` on the server and through hydration, so the server markup always matches.
14
- *
15
- * Renders the default first and the variant once flags arrive. To wait for them instead, call
16
- * `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.
17
- */
18
- function useFeatureFlag(key) {
19
- return (0, react.useSyncExternalStore)(subscribe, () => require_third_parties_posthog.getLoadedPosthog()?.getFeatureFlag(key), () => void 0);
20
- }
21
- exports.useFeatureFlag = useFeatureFlag;
22
-
23
- //# sourceMappingURL=use-feature-flag.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-feature-flag.cjs","names":["getPosthog","useSyncExternalStore","getLoadedPosthog"],"sources":["../../src/react/use-feature-flag.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport { getLoadedPosthog, getPosthog } from '../third-parties/posthog';\n\nconst noop = () => {};\n\n/** Subscribes to flag (re)loads; on the stub the subscription is queued and has no unsubscribe. */\nfunction subscribe(onChange: () => void): () => void {\n const unsubscribe: (() => void) | undefined = getPosthog()?.onFeatureFlags(onChange);\n return unsubscribe ?? noop;\n}\n\n/**\n * A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`\n * until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).\n * `undefined` on the server and through hydration, so the server markup always matches.\n *\n * Renders the default first and the variant once flags arrive. To wait for them instead, call\n * `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.\n */\nexport function useFeatureFlag(key: string): string | boolean | undefined {\n return useSyncExternalStore(\n subscribe,\n () => getLoadedPosthog()?.getFeatureFlag(key),\n () => undefined\n );\n}\n"],"mappings":";;;;AAGA,MAAM,aAAa,CAAC;;AAGpB,SAAS,UAAU,UAAkC;CAEnD,OAD8CA,8BAAAA,WAAW,CAAC,EAAE,eAAe,QAAQ,KAC7D;AACxB;;;;;;;;;AAUA,SAAgB,eAAe,KAA2C;CACxE,QAAA,GAAOC,MAAAA,qBAAAA,CACL,iBACMC,8BAAAA,iBAAiB,CAAC,EAAE,eAAe,GAAG,SACtC,KAAA,CACR;AACF"}
@@ -1,10 +0,0 @@
1
- /**
2
- * A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`
3
- * until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).
4
- * `undefined` on the server and through hydration, so the server markup always matches.
5
- *
6
- * Renders the default first and the variant once flags arrive. To wait for them instead, call
7
- * `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.
8
- */
9
- export declare function useFeatureFlag(key: string): string | boolean | undefined;
10
- //# sourceMappingURL=use-feature-flag.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-feature-flag.d.cts","names":[],"sources":["../../src/react/use-feature-flag.ts"],"mappings":";;;;;;;;wBAmBgB,eAAe"}
@@ -1,10 +0,0 @@
1
- /**
2
- * A PostHog feature flag's value — `true`/`false`, a multivariate flag's variant, or `undefined`
3
- * until PostHog has loaded its flags — re-rendering when they reload (e.g. after `identify`).
4
- * `undefined` on the server and through hydration, so the server markup always matches.
5
- *
6
- * Renders the default first and the variant once flags arrive. To wait for them instead, call
7
- * `use(browser())` and `use(posthogFlagsReady())` above it, under a `<Suspense>`.
8
- */
9
- export declare function useFeatureFlag(key: string): string | boolean | undefined;
10
- //# sourceMappingURL=use-feature-flag.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-feature-flag.d.mts","names":[],"sources":["../../src/react/use-feature-flag.ts"],"mappings":";;;;;;;;wBAmBgB,eAAe"}