@shware/analytics 0.1.17 → 0.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 (80) hide show
  1. package/dist/index.cjs.map +1 -1
  2. package/dist/index.d.cts +3 -1
  3. package/dist/index.d.ts +3 -1
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/next/index.cjs +109 -5
  6. package/dist/next/index.cjs.map +1 -1
  7. package/dist/next/index.d.cts +21 -2
  8. package/dist/next/index.d.ts +21 -2
  9. package/dist/next/index.mjs +96 -4
  10. package/dist/next/index.mjs.map +1 -1
  11. package/dist/react-router/index.cjs +98 -4
  12. package/dist/react-router/index.cjs.map +1 -1
  13. package/dist/react-router/index.d.cts +21 -2
  14. package/dist/react-router/index.d.ts +21 -2
  15. package/dist/react-router/index.mjs +95 -3
  16. package/dist/react-router/index.mjs.map +1 -1
  17. package/dist/schema/index.cjs +1 -0
  18. package/dist/schema/index.cjs.map +1 -1
  19. package/dist/schema/index.d.cts +17 -12
  20. package/dist/schema/index.d.ts +17 -12
  21. package/dist/schema/index.mjs +1 -0
  22. package/dist/schema/index.mjs.map +1 -1
  23. package/dist/server/conversions-api.cjs +246 -0
  24. package/dist/server/conversions-api.cjs.map +1 -0
  25. package/dist/server/conversions-api.d.cts +15 -0
  26. package/dist/server/conversions-api.d.ts +15 -0
  27. package/dist/server/conversions-api.mjs +227 -0
  28. package/dist/server/conversions-api.mjs.map +1 -0
  29. package/dist/setup/index.cjs.map +1 -1
  30. package/dist/setup/index.d.cts +3 -1
  31. package/dist/setup/index.d.ts +3 -1
  32. package/dist/setup/index.mjs.map +1 -1
  33. package/dist/track/fbq.cjs +142 -0
  34. package/dist/track/fbq.cjs.map +1 -0
  35. package/dist/track/fbq.d.cts +279 -0
  36. package/dist/track/fbq.d.ts +279 -0
  37. package/dist/track/fbq.mjs +115 -0
  38. package/dist/track/fbq.mjs.map +1 -0
  39. package/dist/track/{ga.cjs → gtag.cjs} +38 -51
  40. package/dist/track/gtag.cjs.map +1 -0
  41. package/dist/track/gtag.d.cts +525 -0
  42. package/dist/track/gtag.d.ts +525 -0
  43. package/dist/track/gtag.mjs +64 -0
  44. package/dist/track/gtag.mjs.map +1 -0
  45. package/dist/track/index.cjs.map +1 -1
  46. package/dist/track/index.d.cts +3 -2
  47. package/dist/track/index.d.ts +3 -2
  48. package/dist/track/index.mjs.map +1 -1
  49. package/dist/{types/index.cjs → track/types.cjs} +2 -2
  50. package/dist/track/types.cjs.map +1 -0
  51. package/dist/track/types.d.cts +116 -0
  52. package/dist/track/types.d.ts +116 -0
  53. package/dist/track/types.mjs +1 -0
  54. package/dist/visitor/index.cjs.map +1 -1
  55. package/dist/visitor/index.d.cts +1 -1
  56. package/dist/visitor/index.d.ts +1 -1
  57. package/dist/visitor/index.mjs.map +1 -1
  58. package/dist/visitor/types.cjs +19 -0
  59. package/dist/visitor/types.cjs.map +1 -0
  60. package/dist/visitor/types.d.cts +16 -0
  61. package/dist/visitor/types.d.ts +16 -0
  62. package/dist/visitor/types.mjs +1 -0
  63. package/dist/visitor/types.mjs.map +1 -0
  64. package/dist/web/index.cjs +4 -0
  65. package/dist/web/index.cjs.map +1 -1
  66. package/dist/web/index.d.cts +2 -1
  67. package/dist/web/index.d.ts +2 -1
  68. package/dist/web/index.mjs +4 -0
  69. package/dist/web/index.mjs.map +1 -1
  70. package/package.json +11 -1
  71. package/dist/track/ga.cjs.map +0 -1
  72. package/dist/track/ga.d.cts +0 -4
  73. package/dist/track/ga.d.ts +0 -4
  74. package/dist/track/ga.mjs +0 -76
  75. package/dist/track/ga.mjs.map +0 -1
  76. package/dist/types/index.cjs.map +0 -1
  77. package/dist/types/index.d.cts +0 -327
  78. package/dist/types/index.d.ts +0 -327
  79. package/dist/types/index.mjs +0 -1
  80. /package/dist/{types/index.mjs.map → track/types.mjs.map} +0 -0
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/track/fbq.ts
21
+ var fbq_exports = {};
22
+ __export(fbq_exports, {
23
+ mapFBEvent: () => mapFBEvent,
24
+ mapItems: () => mapItems,
25
+ normalize: () => normalize
26
+ });
27
+ module.exports = __toCommonJS(fbq_exports);
28
+ function normalize(parameters) {
29
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
30
+ return {
31
+ ...parameters,
32
+ em: (_a = parameters.em) == null ? void 0 : _a.toLowerCase().trim(),
33
+ ph: (_b = parameters.ph) == null ? void 0 : _b.replace(/[\+\-\(\)\s]/g, "").replace(/^0+/, ""),
34
+ zp: (_d = (_c = parameters.zp) == null ? void 0 : _c.split("-").at(0)) == null ? void 0 : _d.trim(),
35
+ fn: (_e = parameters.fn) == null ? void 0 : _e.toLowerCase().trim(),
36
+ ln: (_f = parameters.ln) == null ? void 0 : _f.toLowerCase().trim(),
37
+ ct: (_g = parameters.ct) == null ? void 0 : _g.toLowerCase().replace(/[s/-]/g, "").trim(),
38
+ st: (_h = parameters.st) == null ? void 0 : _h.toLowerCase().replace(/[s/-/,.]/g, "").trim(),
39
+ country: (_i = parameters.country) == null ? void 0 : _i.toLowerCase().replace(/[s/-]/g, "").trim()
40
+ };
41
+ }
42
+ function mapItems(items) {
43
+ if (!items) return {};
44
+ const categories = Array.from(new Set(items.map((i) => i.item_category).filter(Boolean)));
45
+ const contents = items.map(
46
+ ({ item_id, quantity, price, item_name, item_brand, item_category, ...others }) => ({
47
+ id: item_id,
48
+ quantity: quantity ?? 1,
49
+ item_price: price,
50
+ title: item_name,
51
+ brand: item_brand,
52
+ category: item_category
53
+ })
54
+ );
55
+ return {
56
+ content_category: categories.length === 1 ? categories.at(0) : void 0,
57
+ contents,
58
+ content_ids: contents.map((c) => c.id),
59
+ num_items: items.reduce((acc, i) => acc + (i.quantity ?? 1), 0)
60
+ };
61
+ }
62
+ function mapFBEvent(name, properties) {
63
+ if (name === "add_payment_info") {
64
+ const p = properties;
65
+ return [
66
+ "track",
67
+ "AddPaymentInfo",
68
+ { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
69
+ ];
70
+ } else if (name === "add_to_cart") {
71
+ const p = properties;
72
+ return [
73
+ "track",
74
+ "AddToCart",
75
+ { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
76
+ ];
77
+ } else if (name === "add_to_wishlist") {
78
+ const p = properties;
79
+ return [
80
+ "track",
81
+ "AddToWishlist",
82
+ { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
83
+ ];
84
+ } else if (name === "login") {
85
+ const p = properties;
86
+ return ["track", "CompleteRegistration", { method: p == null ? void 0 : p.method }];
87
+ } else if (name === "contact") {
88
+ return ["track", "Contact", {}];
89
+ } else if (name === "customize_product") {
90
+ return ["track", "CustomizeProduct", {}];
91
+ } else if (name === "donate") {
92
+ return ["track", "Donate", {}];
93
+ } else if (name === "find_location") {
94
+ return ["track", "FindLocation", {}];
95
+ } else if (name === "begin_checkout") {
96
+ const p = properties;
97
+ return [
98
+ "track",
99
+ "InitiateCheckout",
100
+ { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
101
+ ];
102
+ } else if (name === "generate_lead") {
103
+ const p = properties;
104
+ return ["track", "Lead", { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value }];
105
+ } else if (name === "purchase") {
106
+ const p = properties;
107
+ return [
108
+ "track",
109
+ "Purchase",
110
+ { currency: (p == null ? void 0 : p.currency) ?? "usd", value: (p == null ? void 0 : p.value) ?? 0, ...mapItems(p == null ? void 0 : p.items) }
111
+ ];
112
+ } else if (name === "schedule") {
113
+ return ["track", "Schedule", {}];
114
+ } else if (name === "search") {
115
+ const p = properties;
116
+ return ["track", "Search", { search_string: p == null ? void 0 : p.search_term }];
117
+ } else if (name === "trial_begin") {
118
+ const p = properties;
119
+ return ["track", "StartTrial", { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value }];
120
+ } else if (name === "submit_application") {
121
+ return ["track", "SubmitApplication", {}];
122
+ } else if (name === "subscribe") {
123
+ const p = properties;
124
+ return ["track", "Subscribe", { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value }];
125
+ } else if (name === "view_item") {
126
+ const p = properties;
127
+ return [
128
+ "track",
129
+ "ViewContent",
130
+ { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
131
+ ];
132
+ } else {
133
+ return ["trackCustom", name, properties ?? {}];
134
+ }
135
+ }
136
+ // Annotate the CommonJS export names for ESM import in node:
137
+ 0 && (module.exports = {
138
+ mapFBEvent,
139
+ mapItems,
140
+ normalize
141
+ });
142
+ //# sourceMappingURL=fbq.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/track/fbq.ts"],"sourcesContent":["import type { Item } 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 Pixel {\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, '').trim(),\n st: parameters.st\n ?.toLowerCase()\n .replace(/[s/-/,.]/g, '')\n .trim(),\n country: parameters.country?.toLowerCase().replace(/[s/-]/g, '').trim(),\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(\n ({ item_id, quantity, price, item_name, item_brand, item_category, ...others }) => ({\n id: item_id!,\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 === 'login') {\n const p = properties as TrackProperties<'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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8UO,SAAS,UAAU,YAAoD;AA9U9E;AA+UE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,KAAI,gBAAW,OAAX,mBAAe,cAAc;AAAA,IACjC,KAAI,gBAAW,OAAX,mBAAe,QAAQ,iBAAiB,IAAI,QAAQ,OAAO;AAAA,IAC/D,KAAI,sBAAW,OAAX,mBAAe,MAAM,KAAK,GAAG,OAA7B,mBAAiC;AAAA,IACrC,KAAI,gBAAW,OAAX,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,EACjC,WAAW,SAAS,UAAU;AAC5B,UAAM,IAAI;AACV,WAAO,CAAC,SAAS,UAAU,EAAE,eAAe,uBAAG,YAAY,CAAC;AAAA,EAC9D,WAAW,SAAS,eAAe;AACjC,UAAM,IAAI;AACV,WAAO,CAAC,SAAS,cAAc,EAAE,UAAU,uBAAG,UAAU,OAAO,uBAAG,MAAM,CAAC;AAAA,EAC3E,WAAW,SAAS,sBAAsB;AACxC,WAAO,CAAC,SAAS,qBAAqB,CAAC,CAAC;AAAA,EAC1C,WAAW,SAAS,aAAa;AAC/B,UAAM,IAAI;AACV,WAAO,CAAC,SAAS,aAAa,EAAE,UAAU,uBAAG,UAAU,OAAO,uBAAG,MAAM,CAAC;AAAA,EAC1E,WAAW,SAAS,aAAa;AAC/B,UAAM,IAAI;AACV,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,EAAE,UAAU,uBAAG,UAAU,OAAO,uBAAG,OAAO,GAAG,SAAS,uBAAG,KAAK,EAAE;AAAA,IAClE;AAAA,EACF,OAAO;AACL,WAAO,CAAC,eAAe,MAAM,cAAc,CAAC,CAAC;AAAA,EAC/C;AACF;","names":[]}
@@ -0,0 +1,279 @@
1
+ import { Item } from './gtag.cjs';
2
+ import { EventName, TrackName, TrackProperties } from './types.cjs';
3
+
4
+ type Content = {
5
+ id: string;
6
+ quantity: number;
7
+ item_price?: number;
8
+ title?: string;
9
+ description?: string;
10
+ brand?: string;
11
+ category?: string;
12
+ delivery_category?: string;
13
+ };
14
+ /**
15
+ * reference: https://developers.facebook.com/docs/meta-pixel/advanced/advanced-matching
16
+ * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters
17
+ */
18
+ type MatchingParameters = {
19
+ /** Email: Unhashed lowercase or hashed SHA-256 */
20
+ em?: string;
21
+ /** First Name: Lowercase letters */
22
+ fn?: string;
23
+ /** Last Name: Lowercase letters */
24
+ ln?: string;
25
+ /** Phone Number: Digits only including country code and area code */
26
+ ph?: string;
27
+ /**
28
+ * External ID: Any unique ID from the advertiser, such as loyalty membership ID, user ID, and
29
+ * external cookie ID.
30
+ */
31
+ external_id?: string;
32
+ /** Gender: Single lowercase letter, f or m, if unknown, leave blank */
33
+ ge?: 'f' | 'm' | '';
34
+ /** Birthdate: Digits only with birth year, month, then day, YYYYMMDD */
35
+ db?: number;
36
+ /** City: Lowercase with any spaces removed, e.g. "menlopark" */
37
+ ct?: string;
38
+ /** State or Province: Lowercase two-letter state or province code, e.g. "ca" */
39
+ st?: string;
40
+ /** Zip or Postal Code: String */
41
+ zp?: string;
42
+ /** Country: Lowercase two-letter country code, e.g. "us" */
43
+ country?: string;
44
+ /** Client IP Address: Do not hash. */
45
+ client_ip_address?: string;
46
+ /** Client User Agent: Do not hash. */
47
+ client_user_agent?: string;
48
+ /**
49
+ * Click ID: Do not hash.
50
+ * The Facebook click ID value is stored in the _fbc browser cookie under your domain. See
51
+ * Managing fbc and fbp Parameters for how to get this value or generate this value from a fbclid
52
+ * query parameter.
53
+ *
54
+ * The format is fb.${subdomain_index}.${creation_time}.${fbclid}.
55
+ */
56
+ fbc?: string;
57
+ /**
58
+ * Browser ID: Do not hash.
59
+ * The Facebook browser ID value is stored in the _fbp browser cookie under your domain. See
60
+ * Managing fbc and fbp Parameters for how to get this value.
61
+ *
62
+ * The format is fb.${subdomain_index}.${creation_time}.${random_number}.
63
+ */
64
+ fbp?: string;
65
+ /**
66
+ * Subscription ID: Do not hash.
67
+ * The subscription ID for the user in this transaction; it is similar to the order ID for an
68
+ * individual product.
69
+ */
70
+ subscription_id?: string;
71
+ /**
72
+ * Facebook Login ID: Do not hash.
73
+ * The ID issued by Meta when a person first logs into an instance of an app. This is also known
74
+ * as App-Scoped ID.
75
+ */
76
+ fb_login_id?: number;
77
+ /**
78
+ * Lead ID: Do not hash.
79
+ * The ID associated with a lead generated by [Meta's Lead Ads](https://developers.facebook.com/docs/marketing-api/guides/lead-ads).
80
+ */
81
+ lead_id?: number;
82
+ /**
83
+ * Install ID: Do not hash.
84
+ * Your install ID. This field represents unique application installation instances.
85
+ * Note: This parameter is for app events only.
86
+ */
87
+ anon_id?: string;
88
+ /**
89
+ * Your mobile advertiser ID, the advertising ID from an Android device or the Advertising
90
+ * Identifier (IDFA) from an Apple device.
91
+ */
92
+ madid?: string;
93
+ /**
94
+ * Page ID: Do not hash.
95
+ * Your Page ID. Specifies the page ID associated with the event. Use the Facebook page ID of the
96
+ * page associated with the bot.
97
+ */
98
+ page_id?: string;
99
+ /**
100
+ * Page Scoped User ID: Do not hash.
101
+ * Specifies the page-scoped user ID associated with the messenger bot that logs the event. Use
102
+ * the page-scoped user ID provided to your webhook.
103
+ */
104
+ page_scoped_user_id?: string;
105
+ /**
106
+ * Do not hash.
107
+ * Click ID generated by Meta for ads that click to WhatsApp.
108
+ */
109
+ ctwa_clid?: string;
110
+ /**
111
+ * Do not hash.
112
+ * Instagram Account ID that is associated with the business.
113
+ */
114
+ ig_account_id?: string;
115
+ /**
116
+ * Do not hash.
117
+ * Users who interact with Instagram are identified by Instagram-Scoped User IDs (IGSID). IGSID
118
+ * can be obtained from this webhook.
119
+ */
120
+ ig_sid?: string;
121
+ };
122
+ /**
123
+ * You can include the following predefined object properties with any custom events, and any
124
+ * standard events that support them. Format your parameter object data using JSON. Learn more about
125
+ * event parameters with Blueprint.
126
+ */
127
+ type ObjectProperties = {
128
+ content_category?: string;
129
+ content_ids?: string[];
130
+ content_name?: string;
131
+ /**
132
+ * Either product or product_group based on the content_ids or contents being passed. If the IDs
133
+ * being passed in content_ids or contents parameter are IDs of products, then the value should be
134
+ * product. If product group IDs are being passed, then the value should be product_group.
135
+ *
136
+ * If no content_type is provided, Meta will match the event to every item that has the same ID,
137
+ * independent of its type.
138
+ */
139
+ content_type?: 'product' | 'product_group' | (string & {});
140
+ contents?: Content[];
141
+ delivery_category?: 'in_store' | 'curbside' | 'home_delivery';
142
+ currency?: string;
143
+ num_items?: number;
144
+ predicted_ltv?: number;
145
+ search_string?: string;
146
+ /** Used with the CompleteRegistration event, to show the status of the registration. */
147
+ status?: boolean;
148
+ value?: number;
149
+ };
150
+ /**
151
+ * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/payload-helper
152
+ */
153
+ type StandardEvents = {
154
+ AddPaymentInfo: {
155
+ content_ids?: string[];
156
+ contents?: Content[];
157
+ currency?: string;
158
+ value?: number;
159
+ };
160
+ AddToCart: {
161
+ content_ids?: string[];
162
+ content_type?: string;
163
+ contents?: Content[];
164
+ currency?: string;
165
+ value?: number;
166
+ };
167
+ AddToWishlist: {
168
+ content_ids?: string[];
169
+ contents?: Content[];
170
+ currency?: string;
171
+ value?: number;
172
+ };
173
+ CompleteRegistration: {
174
+ currency?: string;
175
+ value?: number;
176
+ method?: string;
177
+ };
178
+ Contact: {};
179
+ CustomizeProduct: {};
180
+ Donate: {};
181
+ FindLocation: {};
182
+ InitiateCheckout: {
183
+ content_ids?: string[];
184
+ contents?: Content[];
185
+ currency?: string;
186
+ num_items?: number;
187
+ value?: number;
188
+ };
189
+ Lead: {
190
+ currency?: string;
191
+ value?: number;
192
+ };
193
+ Purchase: {
194
+ content_ids?: string[];
195
+ content_type?: string;
196
+ contents?: Content[];
197
+ currency: string;
198
+ num_items?: number;
199
+ value: number;
200
+ };
201
+ Schedule: {};
202
+ Search: {
203
+ content_ids?: string[];
204
+ content_type?: string;
205
+ contents?: Content[];
206
+ currency?: string;
207
+ search_string?: string;
208
+ value?: number;
209
+ };
210
+ StartTrial: {
211
+ currency?: string;
212
+ predicted_ltv?: number;
213
+ value?: number;
214
+ };
215
+ SubmitApplication: {};
216
+ Subscribe: {
217
+ currency?: string;
218
+ predicted_ltv?: number;
219
+ value?: number;
220
+ };
221
+ ViewContent: {
222
+ content_ids?: string[];
223
+ content_type?: string;
224
+ contents?: Content[];
225
+ currency?: string;
226
+ value?: number;
227
+ };
228
+ };
229
+ type JSONValue = null | string | number | boolean | Array<JSONValue> | {
230
+ [value: string]: JSONValue;
231
+ };
232
+ type PixelId = `${number}`;
233
+ type Options = {
234
+ eventID?: string;
235
+ };
236
+ /**
237
+ * reference: https://developers.facebook.com/docs/meta-pixel/reference#standard-events
238
+ *
239
+ * We determine if events are identical based on their ID and name. So, for an event to be deduplicated:
240
+ * - In corresponding events, a Meta Pixel's eventID must match the Conversion API's event_id.
241
+ * - In corresponding events, a Meta Pixel's event must match the Conversion API's event_name.
242
+ *
243
+ * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters
244
+ */
245
+ interface Pixel {
246
+ /**
247
+ * reference: https://stackoverflow.com/questions/62304291/sending-user-data-parameters-via-pixel
248
+ *
249
+ * Call init the normal default way first:
250
+ * `fbq('init', 'XXXXX')`
251
+ *
252
+ * And at a later point in time, when you have obtained additional user data, you can call init
253
+ * again basically enriching the already running fbq instance with additional data:
254
+ * `fbq('init', 'XXXXX', { external_id: 1234, em: 'abc@abc.com' } )`
255
+ *
256
+ * Only caveat is that you have to send an event after this additional init call, otherwise the
257
+ * provided data will not be sent to Facebook.
258
+ */
259
+ fbq(type: 'init', pixelId: PixelId, parameters?: MatchingParameters): void;
260
+ /** Enable Manual Only mode. (value = false) */
261
+ fbq(type: 'set', key: 'autoConfig', value: boolean, pixelId: PixelId): void;
262
+ fbq<T extends keyof StandardEvents>(type: 'track', event: T, properties?: StandardEvents[T] & ObjectProperties, options?: Options): void;
263
+ fbq(type: 'trackCustom', event: string, properties?: Record<string, JSONValue> & ObjectProperties, options?: Options): void;
264
+ /** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */
265
+ fbq<T extends keyof StandardEvents>(type: 'trackSingle', pixelId: PixelId, event: T, properties?: StandardEvents[T] & ObjectProperties, options?: Options): void;
266
+ /** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */
267
+ fbq(type: 'trackSingleCustom', pixelId: PixelId, event: string, properties?: Record<string, JSONValue> & ObjectProperties, options?: Options): void;
268
+ }
269
+ /**
270
+ * Please download this CSV filefor examples of properly normalized and hashed data for the
271
+ * parameters below.
272
+ */
273
+ declare function normalize(parameters: MatchingParameters): MatchingParameters;
274
+ declare function mapItems(items?: Item[]): ObjectProperties;
275
+ type Mapped<F extends keyof StandardEvents> = ['track', F, StandardEvents[F] & ObjectProperties];
276
+ type Missed<F extends string> = ['trackCustom', F, Record<string, JSONValue> & ObjectProperties];
277
+ declare function mapFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): Mapped<keyof StandardEvents> | Missed<TrackName<T>>;
278
+
279
+ export { type Content, type MatchingParameters, type ObjectProperties, type Options, type Pixel, type PixelId, type StandardEvents, mapFBEvent, mapItems, normalize };