@shware/analytics 0.1.18 → 0.2.1
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.
- package/dist/next/index.cjs +8 -1
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +2 -2
- package/dist/next/index.d.ts +2 -2
- package/dist/next/index.mjs +9 -2
- package/dist/next/index.mjs.map +1 -1
- package/dist/react-router/index.cjs +8 -1
- package/dist/react-router/index.cjs.map +1 -1
- package/dist/react-router/index.d.cts +2 -2
- package/dist/react-router/index.d.ts +2 -2
- package/dist/react-router/index.mjs +9 -2
- package/dist/react-router/index.mjs.map +1 -1
- package/dist/schema/index.cjs +1 -0
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +9 -4
- package/dist/schema/index.d.ts +9 -4
- package/dist/schema/index.mjs +1 -0
- package/dist/schema/index.mjs.map +1 -1
- package/dist/server/conversions-api.cjs +246 -0
- package/dist/server/conversions-api.cjs.map +1 -0
- package/dist/server/conversions-api.d.cts +15 -0
- package/dist/server/conversions-api.d.ts +15 -0
- package/dist/server/conversions-api.mjs +227 -0
- package/dist/server/conversions-api.mjs.map +1 -0
- package/dist/track/fbq.cjs +45 -46
- package/dist/track/fbq.cjs.map +1 -1
- package/dist/track/fbq.d.cts +20 -19
- package/dist/track/fbq.d.ts +20 -19
- package/dist/track/fbq.mjs +43 -45
- package/dist/track/fbq.mjs.map +1 -1
- package/dist/track/gtag.cjs +33 -46
- package/dist/track/gtag.cjs.map +1 -1
- package/dist/track/gtag.d.cts +67 -5
- package/dist/track/gtag.d.ts +67 -5
- package/dist/track/gtag.mjs +32 -44
- package/dist/track/gtag.mjs.map +1 -1
- package/dist/track/types.cjs.map +1 -1
- package/dist/track/types.d.cts +38 -9
- package/dist/track/types.d.ts +38 -9
- package/dist/web/index.cjs +4 -0
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.mjs +4 -0
- package/dist/web/index.mjs.map +1 -1
- package/package.json +11 -1
package/dist/track/fbq.cjs
CHANGED
|
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/track/fbq.ts
|
|
21
21
|
var fbq_exports = {};
|
|
22
22
|
__export(fbq_exports, {
|
|
23
|
-
|
|
23
|
+
mapFBEvent: () => mapFBEvent,
|
|
24
|
+
mapItems: () => mapItems,
|
|
24
25
|
normalize: () => normalize
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(fbq_exports);
|
|
@@ -41,13 +42,16 @@ function normalize(parameters) {
|
|
|
41
42
|
function mapItems(items) {
|
|
42
43
|
if (!items) return {};
|
|
43
44
|
const categories = Array.from(new Set(items.map((i) => i.item_category).filter(Boolean)));
|
|
44
|
-
const contents = items.map(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
+
);
|
|
51
55
|
return {
|
|
52
56
|
content_category: categories.length === 1 ? categories.at(0) : void 0,
|
|
53
57
|
contents,
|
|
@@ -55,89 +59,84 @@ function mapItems(items) {
|
|
|
55
59
|
num_items: items.reduce((acc, i) => acc + (i.quantity ?? 1), 0)
|
|
56
60
|
};
|
|
57
61
|
}
|
|
58
|
-
function
|
|
62
|
+
function mapFBEvent(name, properties) {
|
|
59
63
|
if (name === "add_payment_info") {
|
|
60
64
|
const p = properties;
|
|
61
|
-
|
|
65
|
+
return [
|
|
62
66
|
"track",
|
|
63
67
|
"AddPaymentInfo",
|
|
64
|
-
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
65
|
-
|
|
66
|
-
);
|
|
68
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
69
|
+
];
|
|
67
70
|
} else if (name === "add_to_cart") {
|
|
68
71
|
const p = properties;
|
|
69
|
-
|
|
72
|
+
return [
|
|
70
73
|
"track",
|
|
71
74
|
"AddToCart",
|
|
72
|
-
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
73
|
-
|
|
74
|
-
);
|
|
75
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
76
|
+
];
|
|
75
77
|
} else if (name === "add_to_wishlist") {
|
|
76
78
|
const p = properties;
|
|
77
|
-
|
|
79
|
+
return [
|
|
78
80
|
"track",
|
|
79
81
|
"AddToWishlist",
|
|
80
|
-
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
81
|
-
|
|
82
|
-
);
|
|
82
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
83
|
+
];
|
|
83
84
|
} else if (name === "login") {
|
|
84
85
|
const p = properties;
|
|
85
|
-
|
|
86
|
+
return ["track", "CompleteRegistration", { method: p == null ? void 0 : p.method }];
|
|
86
87
|
} else if (name === "contact") {
|
|
87
|
-
|
|
88
|
+
return ["track", "Contact", {}];
|
|
88
89
|
} else if (name === "customize_product") {
|
|
89
|
-
|
|
90
|
+
return ["track", "CustomizeProduct", {}];
|
|
90
91
|
} else if (name === "donate") {
|
|
91
|
-
|
|
92
|
+
return ["track", "Donate", {}];
|
|
92
93
|
} else if (name === "find_location") {
|
|
93
|
-
|
|
94
|
+
return ["track", "FindLocation", {}];
|
|
94
95
|
} else if (name === "begin_checkout") {
|
|
95
96
|
const p = properties;
|
|
96
|
-
|
|
97
|
+
return [
|
|
97
98
|
"track",
|
|
98
99
|
"InitiateCheckout",
|
|
99
|
-
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
100
|
-
|
|
101
|
-
);
|
|
100
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
101
|
+
];
|
|
102
102
|
} else if (name === "generate_lead") {
|
|
103
103
|
const p = properties;
|
|
104
|
-
|
|
104
|
+
return ["track", "Lead", { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value }];
|
|
105
105
|
} else if (name === "purchase") {
|
|
106
106
|
const p = properties;
|
|
107
|
-
|
|
107
|
+
return [
|
|
108
108
|
"track",
|
|
109
109
|
"Purchase",
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
);
|
|
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
|
+
];
|
|
113
112
|
} else if (name === "schedule") {
|
|
114
|
-
|
|
113
|
+
return ["track", "Schedule", {}];
|
|
115
114
|
} else if (name === "search") {
|
|
116
115
|
const p = properties;
|
|
117
|
-
|
|
116
|
+
return ["track", "Search", { search_string: p == null ? void 0 : p.search_term }];
|
|
118
117
|
} else if (name === "trial_begin") {
|
|
119
118
|
const p = properties;
|
|
120
|
-
|
|
119
|
+
return ["track", "StartTrial", { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value }];
|
|
121
120
|
} else if (name === "submit_application") {
|
|
122
|
-
|
|
121
|
+
return ["track", "SubmitApplication", {}];
|
|
123
122
|
} else if (name === "subscribe") {
|
|
124
123
|
const p = properties;
|
|
125
|
-
|
|
124
|
+
return ["track", "Subscribe", { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value }];
|
|
126
125
|
} else if (name === "view_item") {
|
|
127
126
|
const p = properties;
|
|
128
|
-
|
|
127
|
+
return [
|
|
129
128
|
"track",
|
|
130
129
|
"ViewContent",
|
|
131
|
-
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
132
|
-
|
|
133
|
-
);
|
|
130
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
131
|
+
];
|
|
134
132
|
} else {
|
|
135
|
-
|
|
133
|
+
return ["trackCustom", name, properties ?? {}];
|
|
136
134
|
}
|
|
137
135
|
}
|
|
138
136
|
// Annotate the CommonJS export names for ESM import in node:
|
|
139
137
|
0 && (module.exports = {
|
|
140
|
-
|
|
138
|
+
mapFBEvent,
|
|
139
|
+
mapItems,
|
|
141
140
|
normalize
|
|
142
141
|
});
|
|
143
142
|
//# sourceMappingURL=fbq.cjs.map
|
package/dist/track/fbq.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/track/fbq.ts"],"sourcesContent":["import type { EventName, TrackName, TrackProperties, Item } from './types';\nexport type Content = { id: string; quantity: number; [key: string]: unknown };\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}`;\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?: { eventID?: string }\n ): void;\n\n fbq(\n type: 'trackCustom',\n event: string,\n properties?: Record<string, JSONValue> & ObjectProperties,\n options?: { eventID?: string }\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?: { eventID?: string }\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?: { eventID?: string }\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\nfunction 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 = items.map(({ item_id, quantity, ...others }) => ({\n id: item_id!,\n quantity: quantity ?? 1,\n ...Object.fromEntries(\n Object.entries(others).map(([key, value]) => [key.replace('item_', ''), value])\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\nexport function mapAndSendFbqEvent<T extends EventName>(\n fbq: Fbq['fbq'],\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n options?: { eventID?: string }\n) {\n if (name === 'add_payment_info') {\n const p = properties as TrackProperties<'add_payment_info'> | undefined;\n fbq(\n 'track',\n 'AddPaymentInfo',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else if (name === 'add_to_cart') {\n const p = properties as TrackProperties<'add_to_cart'> | undefined;\n fbq(\n 'track',\n 'AddToCart',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else if (name === 'add_to_wishlist') {\n const p = properties as TrackProperties<'add_to_wishlist'> | undefined;\n fbq(\n 'track',\n 'AddToWishlist',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else if (name === 'login') {\n const p = properties as TrackProperties<'login'> | undefined;\n fbq('track', 'CompleteRegistration', { method: p?.method }, options);\n } else if (name === 'contact') {\n fbq('track', 'Contact', {}, options);\n } else if (name === 'customize_product') {\n fbq('track', 'CustomizeProduct', {}, options);\n } else if (name === 'donate') {\n fbq('track', 'Donate', {}, options);\n } else if (name === 'find_location') {\n fbq('track', 'FindLocation', {}, options);\n } else if (name === 'begin_checkout') {\n const p = properties as TrackProperties<'begin_checkout'> | undefined;\n fbq(\n 'track',\n 'InitiateCheckout',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else if (name === 'generate_lead') {\n const p = properties as TrackProperties<'generate_lead'> | undefined;\n fbq('track', 'Lead', { currency: p?.currency, value: p?.value }, options);\n } else if (name === 'purchase') {\n const p = properties as TrackProperties<'purchase'> | undefined;\n fbq(\n 'track',\n 'Purchase',\n p ? { currency: p?.currency, value: p?.value, ...mapItems(p?.items) } : undefined,\n options\n );\n } else if (name === 'schedule') {\n fbq('track', 'Schedule', {}, options);\n } else if (name === 'search') {\n const p = properties as TrackProperties<'search'> | undefined;\n fbq('track', 'Search', { search_string: p?.search_term }, options);\n } else if (name === 'trial_begin') {\n const p = properties as TrackProperties<'trial_begin'> | undefined;\n fbq('track', 'StartTrial', { currency: p?.currency, value: p?.value }, options);\n } else if (name === 'submit_application') {\n fbq('track', 'SubmitApplication', {}, options);\n } else if (name === 'subscribe') {\n const p = properties as TrackProperties<'subscribe'> | undefined;\n fbq('track', 'Subscribe', { currency: p?.currency, value: p?.value }, options);\n } else if (name === 'view_item') {\n const p = properties as TrackProperties<'view_item'> | undefined;\n fbq(\n 'track',\n 'ViewContent',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else {\n fbq('trackCustom', name, properties, options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkUO,SAAS,UAAU,YAAoD;AAlU9E;AAmUE,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,mBAAe,cAAc;AAAA,IACjC,KAAI,gBAAW,OAAX,mBAAe,cAAc;AAAA,IACjC,KAAI,gBAAW,OAAX,mBAAe,cAAc,QAAQ,UAAU,IAAI;AAAA,IACvD,KAAI,gBAAW,OAAX,mBACA,cACD,QAAQ,aAAa,IACrB;AAAA,IACH,UAAS,gBAAW,YAAX,mBAAoB,cAAc,QAAQ,UAAU,IAAI;AAAA,EACnE;AACF;AAEA,SAAS,SAAS,OAAkC;AAClD,MAAI,CAAC,MAAO,QAAO,CAAC;AACpB,QAAM,aAAa,MAAM,KAAK,IAAI,IAAI,MAAM,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,OAAO,CAAC,CAAC;AACxF,QAAM,WAAW,MAAM,IAAI,CAAC,EAAE,SAAS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uBAAG,UAAU,OAAO,uBAAG,MAAM,GAAG,OAAO;AAAA,EAC/E,WAAW,SAAS,aAAa;AAC/B,UAAM,IAAI;AACV;AAAA,MACE;AAAA,MACA;AAAA,MACA,EAAE,UAAU,uBAAG,UAAU,OAAO,uBAAG,OAAO,GAAG,SAAS,uBAAG,KAAK,EAAE;AAAA,MAChE;AAAA,IACF;AAAA,EACF,OAAO;AACL,QAAI,eAAe,MAAM,YAAY,OAAO;AAAA,EAC9C;AACF;","names":[]}
|
|
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,mBAAe,cAAc;AAAA,IACjC,KAAI,gBAAW,OAAX,mBAAe,cAAc;AAAA,IACjC,KAAI,gBAAW,OAAX,mBAAe,cAAc,QAAQ,UAAU,IAAI;AAAA,IACvD,KAAI,gBAAW,OAAX,mBACA,cACD,QAAQ,aAAa,IACrB;AAAA,IACH,UAAS,gBAAW,YAAX,mBAAoB,cAAc,QAAQ,UAAU,IAAI;AAAA,EACnE;AACF;AAEO,SAAS,SAAS,OAAkC;AACzD,MAAI,CAAC,MAAO,QAAO,CAAC;AACpB,QAAM,aAAa,MAAM,KAAK,IAAI,IAAI,MAAM,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,OAAO,CAAC,CAAC;AACxF,QAAM,WAAsB,MAAM;AAAA,IAChC,CAAC,EAAE,SAAS,UAAU,OAAO,WAAW,YAAY,eAAe,GAAG,OAAO,OAAO;AAAA,MAClF,IAAI;AAAA,MACJ,UAAU,YAAY;AAAA,MACtB,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,OAAO;AAAA,MACP,UAAU;AAAA,IACZ;AAAA,EACF;AA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,CAAC,CAAC;AAAA,EAC/C;AACF;","names":[]}
|
package/dist/track/fbq.d.cts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import { Item } from './gtag.cjs';
|
|
1
2
|
import { EventName, TrackName, TrackProperties } from './types.cjs';
|
|
2
|
-
import './gtag.cjs';
|
|
3
3
|
|
|
4
4
|
type Content = {
|
|
5
5
|
id: string;
|
|
6
6
|
quantity: number;
|
|
7
|
-
|
|
7
|
+
item_price?: number;
|
|
8
|
+
title?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
brand?: string;
|
|
11
|
+
category?: string;
|
|
12
|
+
delivery_category?: string;
|
|
8
13
|
};
|
|
9
14
|
/**
|
|
10
15
|
* reference: https://developers.facebook.com/docs/meta-pixel/advanced/advanced-matching
|
|
@@ -225,6 +230,9 @@ type JSONValue = null | string | number | boolean | Array<JSONValue> | {
|
|
|
225
230
|
[value: string]: JSONValue;
|
|
226
231
|
};
|
|
227
232
|
type PixelId = `${number}`;
|
|
233
|
+
type Options = {
|
|
234
|
+
eventID?: string;
|
|
235
|
+
};
|
|
228
236
|
/**
|
|
229
237
|
* reference: https://developers.facebook.com/docs/meta-pixel/reference#standard-events
|
|
230
238
|
*
|
|
@@ -234,7 +242,7 @@ type PixelId = `${number}`;
|
|
|
234
242
|
*
|
|
235
243
|
* reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters
|
|
236
244
|
*/
|
|
237
|
-
interface
|
|
245
|
+
interface Pixel {
|
|
238
246
|
/**
|
|
239
247
|
* reference: https://stackoverflow.com/questions/62304291/sending-user-data-parameters-via-pixel
|
|
240
248
|
*
|
|
@@ -251,28 +259,21 @@ interface Fbq {
|
|
|
251
259
|
fbq(type: 'init', pixelId: PixelId, parameters?: MatchingParameters): void;
|
|
252
260
|
/** Enable Manual Only mode. (value = false) */
|
|
253
261
|
fbq(type: 'set', key: 'autoConfig', value: boolean, pixelId: PixelId): void;
|
|
254
|
-
fbq<T extends keyof StandardEvents>(type: 'track', event: T, properties?: StandardEvents[T] & ObjectProperties, options?:
|
|
255
|
-
|
|
256
|
-
}): void;
|
|
257
|
-
fbq(type: 'trackCustom', event: string, properties?: Record<string, JSONValue> & ObjectProperties, options?: {
|
|
258
|
-
eventID?: string;
|
|
259
|
-
}): 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;
|
|
260
264
|
/** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */
|
|
261
|
-
fbq<T extends keyof StandardEvents>(type: 'trackSingle', pixelId: PixelId, event: T, properties?: StandardEvents[T] & ObjectProperties, options?:
|
|
262
|
-
eventID?: string;
|
|
263
|
-
}): void;
|
|
265
|
+
fbq<T extends keyof StandardEvents>(type: 'trackSingle', pixelId: PixelId, event: T, properties?: StandardEvents[T] & ObjectProperties, options?: Options): void;
|
|
264
266
|
/** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */
|
|
265
|
-
fbq(type: 'trackSingleCustom', pixelId: PixelId, event: string, properties?: Record<string, JSONValue> & ObjectProperties, options?:
|
|
266
|
-
eventID?: string;
|
|
267
|
-
}): void;
|
|
267
|
+
fbq(type: 'trackSingleCustom', pixelId: PixelId, event: string, properties?: Record<string, JSONValue> & ObjectProperties, options?: Options): void;
|
|
268
268
|
}
|
|
269
269
|
/**
|
|
270
270
|
* Please download this CSV filefor examples of properly normalized and hashed data for the
|
|
271
271
|
* parameters below.
|
|
272
272
|
*/
|
|
273
273
|
declare function normalize(parameters: MatchingParameters): MatchingParameters;
|
|
274
|
-
declare function
|
|
275
|
-
|
|
276
|
-
|
|
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>>;
|
|
277
278
|
|
|
278
|
-
export { type Content, type
|
|
279
|
+
export { type Content, type MatchingParameters, type ObjectProperties, type Options, type Pixel, type PixelId, type StandardEvents, mapFBEvent, mapItems, normalize };
|
package/dist/track/fbq.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import { Item } from './gtag.js';
|
|
1
2
|
import { EventName, TrackName, TrackProperties } from './types.js';
|
|
2
|
-
import './gtag.js';
|
|
3
3
|
|
|
4
4
|
type Content = {
|
|
5
5
|
id: string;
|
|
6
6
|
quantity: number;
|
|
7
|
-
|
|
7
|
+
item_price?: number;
|
|
8
|
+
title?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
brand?: string;
|
|
11
|
+
category?: string;
|
|
12
|
+
delivery_category?: string;
|
|
8
13
|
};
|
|
9
14
|
/**
|
|
10
15
|
* reference: https://developers.facebook.com/docs/meta-pixel/advanced/advanced-matching
|
|
@@ -225,6 +230,9 @@ type JSONValue = null | string | number | boolean | Array<JSONValue> | {
|
|
|
225
230
|
[value: string]: JSONValue;
|
|
226
231
|
};
|
|
227
232
|
type PixelId = `${number}`;
|
|
233
|
+
type Options = {
|
|
234
|
+
eventID?: string;
|
|
235
|
+
};
|
|
228
236
|
/**
|
|
229
237
|
* reference: https://developers.facebook.com/docs/meta-pixel/reference#standard-events
|
|
230
238
|
*
|
|
@@ -234,7 +242,7 @@ type PixelId = `${number}`;
|
|
|
234
242
|
*
|
|
235
243
|
* reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters
|
|
236
244
|
*/
|
|
237
|
-
interface
|
|
245
|
+
interface Pixel {
|
|
238
246
|
/**
|
|
239
247
|
* reference: https://stackoverflow.com/questions/62304291/sending-user-data-parameters-via-pixel
|
|
240
248
|
*
|
|
@@ -251,28 +259,21 @@ interface Fbq {
|
|
|
251
259
|
fbq(type: 'init', pixelId: PixelId, parameters?: MatchingParameters): void;
|
|
252
260
|
/** Enable Manual Only mode. (value = false) */
|
|
253
261
|
fbq(type: 'set', key: 'autoConfig', value: boolean, pixelId: PixelId): void;
|
|
254
|
-
fbq<T extends keyof StandardEvents>(type: 'track', event: T, properties?: StandardEvents[T] & ObjectProperties, options?:
|
|
255
|
-
|
|
256
|
-
}): void;
|
|
257
|
-
fbq(type: 'trackCustom', event: string, properties?: Record<string, JSONValue> & ObjectProperties, options?: {
|
|
258
|
-
eventID?: string;
|
|
259
|
-
}): 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;
|
|
260
264
|
/** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */
|
|
261
|
-
fbq<T extends keyof StandardEvents>(type: 'trackSingle', pixelId: PixelId, event: T, properties?: StandardEvents[T] & ObjectProperties, options?:
|
|
262
|
-
eventID?: string;
|
|
263
|
-
}): void;
|
|
265
|
+
fbq<T extends keyof StandardEvents>(type: 'trackSingle', pixelId: PixelId, event: T, properties?: StandardEvents[T] & ObjectProperties, options?: Options): void;
|
|
264
266
|
/** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */
|
|
265
|
-
fbq(type: 'trackSingleCustom', pixelId: PixelId, event: string, properties?: Record<string, JSONValue> & ObjectProperties, options?:
|
|
266
|
-
eventID?: string;
|
|
267
|
-
}): void;
|
|
267
|
+
fbq(type: 'trackSingleCustom', pixelId: PixelId, event: string, properties?: Record<string, JSONValue> & ObjectProperties, options?: Options): void;
|
|
268
268
|
}
|
|
269
269
|
/**
|
|
270
270
|
* Please download this CSV filefor examples of properly normalized and hashed data for the
|
|
271
271
|
* parameters below.
|
|
272
272
|
*/
|
|
273
273
|
declare function normalize(parameters: MatchingParameters): MatchingParameters;
|
|
274
|
-
declare function
|
|
275
|
-
|
|
276
|
-
|
|
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>>;
|
|
277
278
|
|
|
278
|
-
export { type Content, type
|
|
279
|
+
export { type Content, type MatchingParameters, type ObjectProperties, type Options, type Pixel, type PixelId, type StandardEvents, mapFBEvent, mapItems, normalize };
|
package/dist/track/fbq.mjs
CHANGED
|
@@ -16,13 +16,16 @@ function normalize(parameters) {
|
|
|
16
16
|
function mapItems(items) {
|
|
17
17
|
if (!items) return {};
|
|
18
18
|
const categories = Array.from(new Set(items.map((i) => i.item_category).filter(Boolean)));
|
|
19
|
-
const contents = items.map(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
const contents = items.map(
|
|
20
|
+
({ item_id, quantity, price, item_name, item_brand, item_category, ...others }) => ({
|
|
21
|
+
id: item_id,
|
|
22
|
+
quantity: quantity ?? 1,
|
|
23
|
+
item_price: price,
|
|
24
|
+
title: item_name,
|
|
25
|
+
brand: item_brand,
|
|
26
|
+
category: item_category
|
|
27
|
+
})
|
|
28
|
+
);
|
|
26
29
|
return {
|
|
27
30
|
content_category: categories.length === 1 ? categories.at(0) : void 0,
|
|
28
31
|
contents,
|
|
@@ -30,88 +33,83 @@ function mapItems(items) {
|
|
|
30
33
|
num_items: items.reduce((acc, i) => acc + (i.quantity ?? 1), 0)
|
|
31
34
|
};
|
|
32
35
|
}
|
|
33
|
-
function
|
|
36
|
+
function mapFBEvent(name, properties) {
|
|
34
37
|
if (name === "add_payment_info") {
|
|
35
38
|
const p = properties;
|
|
36
|
-
|
|
39
|
+
return [
|
|
37
40
|
"track",
|
|
38
41
|
"AddPaymentInfo",
|
|
39
|
-
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
40
|
-
|
|
41
|
-
);
|
|
42
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
43
|
+
];
|
|
42
44
|
} else if (name === "add_to_cart") {
|
|
43
45
|
const p = properties;
|
|
44
|
-
|
|
46
|
+
return [
|
|
45
47
|
"track",
|
|
46
48
|
"AddToCart",
|
|
47
|
-
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
48
|
-
|
|
49
|
-
);
|
|
49
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
50
|
+
];
|
|
50
51
|
} else if (name === "add_to_wishlist") {
|
|
51
52
|
const p = properties;
|
|
52
|
-
|
|
53
|
+
return [
|
|
53
54
|
"track",
|
|
54
55
|
"AddToWishlist",
|
|
55
|
-
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
56
|
-
|
|
57
|
-
);
|
|
56
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
57
|
+
];
|
|
58
58
|
} else if (name === "login") {
|
|
59
59
|
const p = properties;
|
|
60
|
-
|
|
60
|
+
return ["track", "CompleteRegistration", { method: p == null ? void 0 : p.method }];
|
|
61
61
|
} else if (name === "contact") {
|
|
62
|
-
|
|
62
|
+
return ["track", "Contact", {}];
|
|
63
63
|
} else if (name === "customize_product") {
|
|
64
|
-
|
|
64
|
+
return ["track", "CustomizeProduct", {}];
|
|
65
65
|
} else if (name === "donate") {
|
|
66
|
-
|
|
66
|
+
return ["track", "Donate", {}];
|
|
67
67
|
} else if (name === "find_location") {
|
|
68
|
-
|
|
68
|
+
return ["track", "FindLocation", {}];
|
|
69
69
|
} else if (name === "begin_checkout") {
|
|
70
70
|
const p = properties;
|
|
71
|
-
|
|
71
|
+
return [
|
|
72
72
|
"track",
|
|
73
73
|
"InitiateCheckout",
|
|
74
|
-
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
75
|
-
|
|
76
|
-
);
|
|
74
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
75
|
+
];
|
|
77
76
|
} else if (name === "generate_lead") {
|
|
78
77
|
const p = properties;
|
|
79
|
-
|
|
78
|
+
return ["track", "Lead", { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value }];
|
|
80
79
|
} else if (name === "purchase") {
|
|
81
80
|
const p = properties;
|
|
82
|
-
|
|
81
|
+
return [
|
|
83
82
|
"track",
|
|
84
83
|
"Purchase",
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
);
|
|
84
|
+
{ currency: (p == null ? void 0 : p.currency) ?? "usd", value: (p == null ? void 0 : p.value) ?? 0, ...mapItems(p == null ? void 0 : p.items) }
|
|
85
|
+
];
|
|
88
86
|
} else if (name === "schedule") {
|
|
89
|
-
|
|
87
|
+
return ["track", "Schedule", {}];
|
|
90
88
|
} else if (name === "search") {
|
|
91
89
|
const p = properties;
|
|
92
|
-
|
|
90
|
+
return ["track", "Search", { search_string: p == null ? void 0 : p.search_term }];
|
|
93
91
|
} else if (name === "trial_begin") {
|
|
94
92
|
const p = properties;
|
|
95
|
-
|
|
93
|
+
return ["track", "StartTrial", { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value }];
|
|
96
94
|
} else if (name === "submit_application") {
|
|
97
|
-
|
|
95
|
+
return ["track", "SubmitApplication", {}];
|
|
98
96
|
} else if (name === "subscribe") {
|
|
99
97
|
const p = properties;
|
|
100
|
-
|
|
98
|
+
return ["track", "Subscribe", { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value }];
|
|
101
99
|
} else if (name === "view_item") {
|
|
102
100
|
const p = properties;
|
|
103
|
-
|
|
101
|
+
return [
|
|
104
102
|
"track",
|
|
105
103
|
"ViewContent",
|
|
106
|
-
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
107
|
-
|
|
108
|
-
);
|
|
104
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) }
|
|
105
|
+
];
|
|
109
106
|
} else {
|
|
110
|
-
|
|
107
|
+
return ["trackCustom", name, properties ?? {}];
|
|
111
108
|
}
|
|
112
109
|
}
|
|
113
110
|
export {
|
|
114
|
-
|
|
111
|
+
mapFBEvent,
|
|
112
|
+
mapItems,
|
|
115
113
|
normalize
|
|
116
114
|
};
|
|
117
115
|
//# sourceMappingURL=fbq.mjs.map
|