@shware/analytics 2.7.0 → 2.8.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.
- package/README.md +4 -0
- package/dist/next/index.cjs +32 -43
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +8 -14
- package/dist/next/index.d.ts +8 -14
- package/dist/next/index.mjs +31 -39
- package/dist/next/index.mjs.map +1 -1
- package/dist/react-router/index.cjs +32 -43
- package/dist/react-router/index.cjs.map +1 -1
- package/dist/react-router/index.d.cts +8 -14
- package/dist/react-router/index.d.ts +8 -14
- package/dist/react-router/index.mjs +31 -39
- package/dist/react-router/index.mjs.map +1 -1
- package/dist/schema/index.cjs +85 -148
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +81 -1
- package/dist/schema/index.d.ts +81 -1
- package/dist/schema/index.mjs +83 -148
- package/dist/schema/index.mjs.map +1 -1
- package/dist/server/{conversions-api.cjs → meta-conversions-api.cjs} +5 -5
- package/dist/server/meta-conversions-api.cjs.map +1 -0
- package/dist/server/{conversions-api.mjs → meta-conversions-api.mjs} +2 -2
- package/dist/server/meta-conversions-api.mjs.map +1 -0
- package/dist/server/reddit-conversions-api.cjs +88 -0
- package/dist/server/reddit-conversions-api.cjs.map +1 -0
- package/dist/server/reddit-conversions-api.d.cts +75 -0
- package/dist/server/reddit-conversions-api.d.ts +75 -0
- package/dist/server/reddit-conversions-api.mjs +62 -0
- package/dist/server/reddit-conversions-api.mjs.map +1 -0
- package/dist/third-parties/google-analytics.cjs +48 -0
- package/dist/third-parties/google-analytics.cjs.map +1 -0
- package/dist/third-parties/google-analytics.d.cts +12 -0
- package/dist/third-parties/google-analytics.d.ts +12 -0
- package/dist/third-parties/google-analytics.mjs +22 -0
- package/dist/third-parties/google-analytics.mjs.map +1 -0
- package/dist/third-parties/hotjar.cjs +2 -0
- package/dist/third-parties/hotjar.cjs.map +1 -0
- package/dist/third-parties/hotjar.d.cts +2 -0
- package/dist/third-parties/hotjar.d.ts +2 -0
- package/dist/third-parties/hotjar.mjs +1 -0
- package/dist/third-parties/hotjar.mjs.map +1 -0
- package/dist/third-parties/index.cjs +43 -0
- package/dist/third-parties/index.cjs.map +1 -0
- package/dist/third-parties/index.d.cts +8 -0
- package/dist/third-parties/index.d.ts +8 -0
- package/dist/third-parties/index.mjs +13 -0
- package/dist/third-parties/index.mjs.map +1 -0
- package/dist/third-parties/meta-pixel.cjs +68 -0
- package/dist/third-parties/meta-pixel.cjs.map +1 -0
- package/dist/third-parties/meta-pixel.d.cts +13 -0
- package/dist/third-parties/meta-pixel.d.ts +13 -0
- package/dist/third-parties/meta-pixel.mjs +42 -0
- package/dist/third-parties/meta-pixel.mjs.map +1 -0
- package/dist/third-parties/reddit-pixel.cjs +60 -0
- package/dist/third-parties/reddit-pixel.cjs.map +1 -0
- package/dist/third-parties/reddit-pixel.d.cts +13 -0
- package/dist/third-parties/reddit-pixel.d.ts +13 -0
- package/dist/third-parties/reddit-pixel.mjs +34 -0
- package/dist/third-parties/reddit-pixel.mjs.map +1 -0
- package/dist/track/fbq.cjs.map +1 -1
- package/dist/track/fbq.d.cts +2 -2
- package/dist/track/fbq.d.ts +2 -2
- package/dist/track/fbq.mjs.map +1 -1
- package/dist/track/rdt.cjs +104 -0
- package/dist/track/rdt.cjs.map +1 -0
- package/dist/track/rdt.d.cts +94 -0
- package/dist/track/rdt.d.ts +94 -0
- package/dist/track/rdt.mjs +78 -0
- package/dist/track/rdt.mjs.map +1 -0
- package/dist/track/types.cjs.map +1 -1
- package/dist/track/types.d.cts +4 -3
- package/dist/track/types.d.ts +4 -3
- package/dist/{react/index.cjs → utils/field.cjs} +11 -9
- package/dist/utils/field.cjs.map +1 -0
- package/dist/utils/field.d.cts +3 -0
- package/dist/utils/field.d.ts +3 -0
- package/dist/utils/field.mjs +10 -0
- package/dist/utils/field.mjs.map +1 -0
- package/dist/web/index.cjs +3 -0
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.mjs +3 -0
- package/dist/web/index.mjs.map +1 -1
- package/package.json +15 -10
- package/dist/react/index.cjs.map +0 -1
- package/dist/react/index.d.cts +0 -3
- package/dist/react/index.d.ts +0 -3
- package/dist/react/index.mjs +0 -8
- package/dist/react/index.mjs.map +0 -1
- package/dist/server/conversions-api.cjs.map +0 -1
- package/dist/server/conversions-api.mjs.map +0 -1
- /package/dist/server/{conversions-api.d.cts → meta-conversions-api.d.cts} +0 -0
- /package/dist/server/{conversions-api.d.ts → meta-conversions-api.d.ts} +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
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/third-parties/reddit-pixel.ts
|
|
21
|
+
var reddit_pixel_exports = {};
|
|
22
|
+
__export(reddit_pixel_exports, {
|
|
23
|
+
sendRDTEvent: () => sendRDTEvent,
|
|
24
|
+
setRDTUser: () => setRDTUser
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(reddit_pixel_exports);
|
|
27
|
+
var import_rdt = require("../track/rdt.cjs");
|
|
28
|
+
var import_field = require("../utils/field.cjs");
|
|
29
|
+
function sendRDTEvent(name, properties, eventId) {
|
|
30
|
+
if (typeof window === "undefined" || !window.rdt) {
|
|
31
|
+
console.warn("rdt has not been initialized");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const { rdt } = window;
|
|
35
|
+
const [type, params] = (0, import_rdt.mapRDTEvent)(name, properties, eventId);
|
|
36
|
+
if (type === "Custom") {
|
|
37
|
+
rdt("track", type, params);
|
|
38
|
+
} else {
|
|
39
|
+
rdt("track", type, params);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function setRDTUser(pixelId) {
|
|
43
|
+
return ({ user_id, data }) => {
|
|
44
|
+
if (!window.rdt) {
|
|
45
|
+
console.warn("rdt has not been initialized");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
window.rdt("init", pixelId, {
|
|
49
|
+
email: (0, import_field.getFirst)(data == null ? void 0 : data.email),
|
|
50
|
+
phoneNumber: (0, import_field.getFirst)(data == null ? void 0 : data.phone_number),
|
|
51
|
+
externalId: user_id
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
sendRDTEvent,
|
|
58
|
+
setRDTUser
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=reddit-pixel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/third-parties/reddit-pixel.ts"],"sourcesContent":["import { mapRDTEvent } from '../track/rdt';\nimport { getFirst } from '../utils/field';\nimport type { PixelId, RDT } from '../track/rdt';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport type { UpdateVisitorDTO } from '../visitor/types';\n\ndeclare global {\n interface Window extends RDT {}\n}\n\nexport function sendRDTEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.rdt) {\n console.warn('rdt has not been initialized');\n return;\n }\n\n const { rdt } = window;\n const [type, params] = mapRDTEvent(name, properties, eventId);\n if (type === 'Custom') {\n rdt('track', type, params);\n } else {\n rdt('track', type, params);\n }\n}\n\nexport function setRDTUser(pixelId: PixelId) {\n return ({ user_id, data }: UpdateVisitorDTO) => {\n if (!window.rdt) {\n console.warn('rdt has not been initialized');\n return;\n }\n\n window.rdt('init', pixelId, {\n email: getFirst(data?.email),\n phoneNumber: getFirst(data?.phone_number),\n externalId: user_id,\n });\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA4B;AAC5B,mBAAyB;AASlB,SAAS,aACd,MACA,YACA,SACA;AACA,MAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;AAChD,YAAQ,KAAK,8BAA8B;AAC3C;AAAA,EACF;AAEA,QAAM,EAAE,IAAI,IAAI;AAChB,QAAM,CAAC,MAAM,MAAM,QAAI,wBAAY,MAAM,YAAY,OAAO;AAC5D,MAAI,SAAS,UAAU;AACrB,QAAI,SAAS,MAAM,MAAM;AAAA,EAC3B,OAAO;AACL,QAAI,SAAS,MAAM,MAAM;AAAA,EAC3B;AACF;AAEO,SAAS,WAAW,SAAkB;AAC3C,SAAO,CAAC,EAAE,SAAS,KAAK,MAAwB;AAC9C,QAAI,CAAC,OAAO,KAAK;AACf,cAAQ,KAAK,8BAA8B;AAC3C;AAAA,IACF;AAEA,WAAO,IAAI,QAAQ,SAAS;AAAA,MAC1B,WAAO,uBAAS,6BAAM,KAAK;AAAA,MAC3B,iBAAa,uBAAS,6BAAM,YAAY;AAAA,MACxC,YAAY;AAAA,IACd,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RDT, PixelId } from '../track/rdt.cjs';
|
|
2
|
+
import { EventName, TrackName, TrackProperties } from '../track/types.cjs';
|
|
3
|
+
import { UpdateVisitorDTO } from '../visitor/types.cjs';
|
|
4
|
+
import '../track/gtag.cjs';
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window extends RDT {
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
declare function sendRDTEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, eventId?: string): void;
|
|
11
|
+
declare function setRDTUser(pixelId: PixelId): ({ user_id, data }: UpdateVisitorDTO) => void;
|
|
12
|
+
|
|
13
|
+
export { sendRDTEvent, setRDTUser };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RDT, PixelId } from '../track/rdt.js';
|
|
2
|
+
import { EventName, TrackName, TrackProperties } from '../track/types.js';
|
|
3
|
+
import { UpdateVisitorDTO } from '../visitor/types.js';
|
|
4
|
+
import '../track/gtag.js';
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window extends RDT {
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
declare function sendRDTEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, eventId?: string): void;
|
|
11
|
+
declare function setRDTUser(pixelId: PixelId): ({ user_id, data }: UpdateVisitorDTO) => void;
|
|
12
|
+
|
|
13
|
+
export { sendRDTEvent, setRDTUser };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/third-parties/reddit-pixel.ts
|
|
2
|
+
import { mapRDTEvent } from "../track/rdt.mjs";
|
|
3
|
+
import { getFirst } from "../utils/field.mjs";
|
|
4
|
+
function sendRDTEvent(name, properties, eventId) {
|
|
5
|
+
if (typeof window === "undefined" || !window.rdt) {
|
|
6
|
+
console.warn("rdt has not been initialized");
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const { rdt } = window;
|
|
10
|
+
const [type, params] = mapRDTEvent(name, properties, eventId);
|
|
11
|
+
if (type === "Custom") {
|
|
12
|
+
rdt("track", type, params);
|
|
13
|
+
} else {
|
|
14
|
+
rdt("track", type, params);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function setRDTUser(pixelId) {
|
|
18
|
+
return ({ user_id, data }) => {
|
|
19
|
+
if (!window.rdt) {
|
|
20
|
+
console.warn("rdt has not been initialized");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
window.rdt("init", pixelId, {
|
|
24
|
+
email: getFirst(data == null ? void 0 : data.email),
|
|
25
|
+
phoneNumber: getFirst(data == null ? void 0 : data.phone_number),
|
|
26
|
+
externalId: user_id
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
sendRDTEvent,
|
|
32
|
+
setRDTUser
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=reddit-pixel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/third-parties/reddit-pixel.ts"],"sourcesContent":["import { mapRDTEvent } from '../track/rdt';\nimport { getFirst } from '../utils/field';\nimport type { PixelId, RDT } from '../track/rdt';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport type { UpdateVisitorDTO } from '../visitor/types';\n\ndeclare global {\n interface Window extends RDT {}\n}\n\nexport function sendRDTEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.rdt) {\n console.warn('rdt has not been initialized');\n return;\n }\n\n const { rdt } = window;\n const [type, params] = mapRDTEvent(name, properties, eventId);\n if (type === 'Custom') {\n rdt('track', type, params);\n } else {\n rdt('track', type, params);\n }\n}\n\nexport function setRDTUser(pixelId: PixelId) {\n return ({ user_id, data }: UpdateVisitorDTO) => {\n if (!window.rdt) {\n console.warn('rdt has not been initialized');\n return;\n }\n\n window.rdt('init', pixelId, {\n email: getFirst(data?.email),\n phoneNumber: getFirst(data?.phone_number),\n externalId: user_id,\n });\n };\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AASlB,SAAS,aACd,MACA,YACA,SACA;AACA,MAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;AAChD,YAAQ,KAAK,8BAA8B;AAC3C;AAAA,EACF;AAEA,QAAM,EAAE,IAAI,IAAI;AAChB,QAAM,CAAC,MAAM,MAAM,IAAI,YAAY,MAAM,YAAY,OAAO;AAC5D,MAAI,SAAS,UAAU;AACrB,QAAI,SAAS,MAAM,MAAM;AAAA,EAC3B,OAAO;AACL,QAAI,SAAS,MAAM,MAAM;AAAA,EAC3B;AACF;AAEO,SAAS,WAAW,SAAkB;AAC3C,SAAO,CAAC,EAAE,SAAS,KAAK,MAAwB;AAC9C,QAAI,CAAC,OAAO,KAAK;AACf,cAAQ,KAAK,8BAA8B;AAC3C;AAAA,IACF;AAEA,WAAO,IAAI,QAAQ,SAAS;AAAA,MAC1B,OAAO,SAAS,6BAAM,KAAK;AAAA,MAC3B,aAAa,SAAS,6BAAM,YAAY;AAAA,MACxC,YAAY;AAAA,IACd,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/dist/track/fbq.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/track/fbq.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-empty-object-type */\nimport 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;AA+UO,SAAS,UAAU,YAAoD;AA/U9E;AAgVE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,KAAI,gBAAW,OAAX,mBAAe,cAAc;AAAA,IACjC,KAAI,gBAAW,OAAX,mBAAe,QAAQ,aAAa,IAAI,QAAQ,OAAO;AAAA,IAC3D,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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S,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":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/track/fbq.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-empty-object-type */\nimport 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 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, '').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;AA+UO,SAAS,UAAU,YAAoD;AA/U9E;AAgVE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,KAAI,gBAAW,OAAX,mBAAe,cAAc;AAAA,IACjC,KAAI,gBAAW,OAAX,mBAAe,QAAQ,aAAa,IAAI,QAAQ,OAAO;AAAA,IAC3D,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,WA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;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":[]}
|
package/dist/track/fbq.d.cts
CHANGED
|
@@ -242,7 +242,7 @@ type Options = {
|
|
|
242
242
|
*
|
|
243
243
|
* reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters
|
|
244
244
|
*/
|
|
245
|
-
interface
|
|
245
|
+
interface FBQ {
|
|
246
246
|
/**
|
|
247
247
|
* reference: https://stackoverflow.com/questions/62304291/sending-user-data-parameters-via-pixel
|
|
248
248
|
*
|
|
@@ -276,4 +276,4 @@ type Mapped<F extends keyof StandardEvents> = ['track', F, StandardEvents[F] & O
|
|
|
276
276
|
type Missed<F extends string> = ['trackCustom', F, Record<string, JSONValue> & ObjectProperties];
|
|
277
277
|
declare function mapFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): Mapped<keyof StandardEvents> | Missed<TrackName<T>>;
|
|
278
278
|
|
|
279
|
-
export { type Content, type
|
|
279
|
+
export { type Content, type FBQ, type MatchingParameters, type ObjectProperties, type Options, type PixelId, type StandardEvents, mapFBEvent, mapItems, normalize };
|
package/dist/track/fbq.d.ts
CHANGED
|
@@ -242,7 +242,7 @@ type Options = {
|
|
|
242
242
|
*
|
|
243
243
|
* reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters
|
|
244
244
|
*/
|
|
245
|
-
interface
|
|
245
|
+
interface FBQ {
|
|
246
246
|
/**
|
|
247
247
|
* reference: https://stackoverflow.com/questions/62304291/sending-user-data-parameters-via-pixel
|
|
248
248
|
*
|
|
@@ -276,4 +276,4 @@ type Mapped<F extends keyof StandardEvents> = ['track', F, StandardEvents[F] & O
|
|
|
276
276
|
type Missed<F extends string> = ['trackCustom', F, Record<string, JSONValue> & ObjectProperties];
|
|
277
277
|
declare function mapFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): Mapped<keyof StandardEvents> | Missed<TrackName<T>>;
|
|
278
278
|
|
|
279
|
-
export { type Content, type
|
|
279
|
+
export { type Content, type FBQ, type MatchingParameters, type ObjectProperties, type Options, type PixelId, type StandardEvents, mapFBEvent, mapItems, normalize };
|
package/dist/track/fbq.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/track/fbq.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-empty-object-type */\nimport 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":";AA+UO,SAAS,UAAU,YAAoD;AA/U9E;AAgVE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,KAAI,gBAAW,OAAX,mBAAe,cAAc;AAAA,IACjC,KAAI,gBAAW,OAAX,mBAAe,QAAQ,aAAa,IAAI,QAAQ,OAAO;AAAA,IAC3D,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,QAAQ,OAAO;AAAA,MACnF,IAAI;AAAA,MACJ,UAAU,YAAY;AAAA,MACtB,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,OAAO;AAAA,MACP,UAAU;AAAA,IACZ;AAAA,EACF;AAEA,SAAO;AAAA,IACL,kBAAkB,WAAW,WAAW,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
|
1
|
+
{"version":3,"sources":["../../src/track/fbq.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-empty-object-type */\nimport 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 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, '').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":";AA+UO,SAAS,UAAU,YAAoD;AA/U9E;AAgVE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,KA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AA,MACL;AAAA,MACA;AAAA,MACA,EAAE,WAAU,uBAAG,aAAY,OAAO,QAAO,uBAAG,UAAS,GAAG,GAAG,SAAS,uBAAG,KAAK,EAAE;AAAA,IAChF;AAAA,EACF,WAAW,SAAS,YAAY;AAC9B,WAAO,CAAC,SAAS,YAAY,CAAC,CAAC;AAAA,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,104 @@
|
|
|
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/rdt.ts
|
|
21
|
+
var rdt_exports = {};
|
|
22
|
+
__export(rdt_exports, {
|
|
23
|
+
mapItems: () => mapItems,
|
|
24
|
+
mapRDTEvent: () => mapRDTEvent
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(rdt_exports);
|
|
27
|
+
function mapItems(items) {
|
|
28
|
+
if (!items || items.length === 0) return void 0;
|
|
29
|
+
return items.map((item) => ({
|
|
30
|
+
id: item.item_id,
|
|
31
|
+
name: item.item_name,
|
|
32
|
+
category: item.item_category
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
function mapRDTEvent(name, properties, eventId) {
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
if (name === "page_view") {
|
|
38
|
+
return ["PageVisit", { conversionId: eventId }];
|
|
39
|
+
} else if (name === "view_item") {
|
|
40
|
+
return ["ViewContent", { conversionId: eventId }];
|
|
41
|
+
} else if (name === "search") {
|
|
42
|
+
return ["Search", { conversionId: eventId }];
|
|
43
|
+
} else if (name === "add_to_cart") {
|
|
44
|
+
const p = properties;
|
|
45
|
+
return [
|
|
46
|
+
"AddToCart",
|
|
47
|
+
{
|
|
48
|
+
conversionId: eventId,
|
|
49
|
+
value: p == null ? void 0 : p.value,
|
|
50
|
+
currency: p == null ? void 0 : p.currency.toUpperCase(),
|
|
51
|
+
itemCount: (_a = p == null ? void 0 : p.items) == null ? void 0 : _a.reduce((acc, i) => acc + (i.quantity ?? 1), 0),
|
|
52
|
+
products: mapItems(p == null ? void 0 : p.items)
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
} else if (name === "add_to_wishlist") {
|
|
56
|
+
const p = properties;
|
|
57
|
+
return [
|
|
58
|
+
"AddToWishlist",
|
|
59
|
+
{
|
|
60
|
+
conversionId: eventId,
|
|
61
|
+
value: p == null ? void 0 : p.value,
|
|
62
|
+
currency: p == null ? void 0 : p.currency.toUpperCase(),
|
|
63
|
+
itemCount: (_b = p == null ? void 0 : p.items) == null ? void 0 : _b.reduce((acc, i) => acc + (i.quantity ?? 1), 0),
|
|
64
|
+
products: mapItems(p == null ? void 0 : p.items)
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
} else if (name === "purchase") {
|
|
68
|
+
const p = properties;
|
|
69
|
+
return [
|
|
70
|
+
"Purchase",
|
|
71
|
+
{
|
|
72
|
+
conversionId: eventId,
|
|
73
|
+
value: p == null ? void 0 : p.value,
|
|
74
|
+
currency: p == null ? void 0 : p.currency.toUpperCase(),
|
|
75
|
+
itemCount: (_c = p == null ? void 0 : p.items) == null ? void 0 : _c.reduce((acc, i) => acc + (i.quantity ?? 1), 0),
|
|
76
|
+
products: mapItems(p == null ? void 0 : p.items)
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
} else if (name === "generate_lead") {
|
|
80
|
+
const p = properties;
|
|
81
|
+
return [
|
|
82
|
+
"Lead",
|
|
83
|
+
{ conversionId: eventId, value: p == null ? void 0 : p.value, currency: p == null ? void 0 : p.currency.toUpperCase() }
|
|
84
|
+
];
|
|
85
|
+
} else if (name === "sign_up" || name === "login") {
|
|
86
|
+
return ["SignUp", { conversionId: eventId }];
|
|
87
|
+
} else {
|
|
88
|
+
return [
|
|
89
|
+
"Custom",
|
|
90
|
+
{
|
|
91
|
+
customEventName: name,
|
|
92
|
+
conversionId: eventId,
|
|
93
|
+
value: properties && "value" in properties && typeof properties.value === "number" ? properties.value : void 0,
|
|
94
|
+
currency: properties && "currency" in properties && typeof properties.currency === "string" ? properties.currency.toUpperCase() : void 0
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
mapItems,
|
|
102
|
+
mapRDTEvent
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=rdt.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/track/rdt.ts"],"sourcesContent":["import type { Item } 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: item.item_id,\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqGO,SAAS,SAAS,OAAuC;AAC9D,MAAI,CAAC,SAAS,MAAM,WAAW,EAAG,QAAO;AACzC,SAAO,MAAM,IAAI,CAAC,UAAU;AAAA,IAC1B,IAAI,KAAK;AAAA,IACT,MAAM,KAAK;AAAA,IACX,UAAU,KAAK;AAAA,EACjB,EAAE;AACJ;AAEO,SAAS,YACd,MACA,YACA,SACqD;AAlHvD;AAoHE,MAAI,SAAS,aAAa;AACxB,WAAO,CAAC,aAAa,EAAE,cAAc,QAAQ,CAAC;AAAA,EAChD,WAAW,SAAS,aAAa;AAC/B,WAAO,CAAC,eAAe,EAAE,cAAc,QAAQ,CAAC;AAAA,EAClD,WAAW,SAAS,UAAU;AAC5B,WAAO,CAAC,UAAU,EAAE,cAAc,QAAQ,CAAC;AAAA,EAC7C,WAAW,SAAS,eAAe;AACjC,UAAM,IAAI;AACV,WAAO;AAAA,MACL;AAAA,MACA;AAAA,QACE,cAAc;AAAA,QACd,OAAO,uBAAG;AAAA,QACV,UAAU,uBAAG,SAAS;AAAA,QACtB,YAAW,4BAAG,UAAH,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,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Item } from './gtag.cjs';
|
|
2
|
+
import { EventName, TrackName, TrackProperties } from './types.cjs';
|
|
3
|
+
|
|
4
|
+
/** https://business.reddithelp.com/s/article/about-event-metadata */
|
|
5
|
+
type Product = {
|
|
6
|
+
/**
|
|
7
|
+
* (Required) Product ID: Either the SKU or GTIN, which represents the variant ID, not the
|
|
8
|
+
* parent ID. If there are no variants, pass the assigned ID for that item.
|
|
9
|
+
*/
|
|
10
|
+
id: string;
|
|
11
|
+
/** (Optional) Product Category: The group the product belongs to. */
|
|
12
|
+
name?: string;
|
|
13
|
+
/** (Optional) Product Name: The title of the product. */
|
|
14
|
+
category?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* https://business.reddithelp.com/s/article/supported-conversion-events#supported-conversion-events
|
|
18
|
+
* https://business.reddithelp.com/s/article/about-event-metadata
|
|
19
|
+
* https://business.reddithelp.com/s/article/map-a-catalog-to-a-signal-source
|
|
20
|
+
*/
|
|
21
|
+
type StandardEvents = {
|
|
22
|
+
PageVisit: {
|
|
23
|
+
conversionId?: string;
|
|
24
|
+
products?: Product[];
|
|
25
|
+
};
|
|
26
|
+
ViewContent: {
|
|
27
|
+
conversionId?: string;
|
|
28
|
+
products?: Product[];
|
|
29
|
+
};
|
|
30
|
+
Search: {
|
|
31
|
+
conversionId?: string;
|
|
32
|
+
products?: Product[];
|
|
33
|
+
};
|
|
34
|
+
AddToCart: {
|
|
35
|
+
value?: number;
|
|
36
|
+
currency?: string;
|
|
37
|
+
itemCount?: number;
|
|
38
|
+
conversionId?: string;
|
|
39
|
+
products?: Product[];
|
|
40
|
+
};
|
|
41
|
+
AddToWishlist: {
|
|
42
|
+
value?: number;
|
|
43
|
+
currency?: string;
|
|
44
|
+
itemCount?: number;
|
|
45
|
+
conversionId?: string;
|
|
46
|
+
products?: Product[];
|
|
47
|
+
};
|
|
48
|
+
Purchase: {
|
|
49
|
+
value?: number;
|
|
50
|
+
currency?: string;
|
|
51
|
+
itemCount?: number;
|
|
52
|
+
conversionId?: string;
|
|
53
|
+
products?: Product[];
|
|
54
|
+
};
|
|
55
|
+
Lead: {
|
|
56
|
+
value?: number;
|
|
57
|
+
currency?: string;
|
|
58
|
+
conversionId?: string;
|
|
59
|
+
products?: Product[];
|
|
60
|
+
};
|
|
61
|
+
SignUp: {
|
|
62
|
+
value?: number;
|
|
63
|
+
currency?: string;
|
|
64
|
+
conversionId?: string;
|
|
65
|
+
products?: Product[];
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
type PixelId = `a2_${string}`;
|
|
69
|
+
type MatchKeys = {
|
|
70
|
+
email?: string;
|
|
71
|
+
phoneNumber?: string;
|
|
72
|
+
externalId?: string;
|
|
73
|
+
idfa?: string;
|
|
74
|
+
aaid?: string;
|
|
75
|
+
};
|
|
76
|
+
type CustomEventParams<T extends string = string> = {
|
|
77
|
+
customEventName: T;
|
|
78
|
+
value?: number;
|
|
79
|
+
currency?: string;
|
|
80
|
+
itemCount?: number;
|
|
81
|
+
conversionId?: string;
|
|
82
|
+
products?: Product[];
|
|
83
|
+
};
|
|
84
|
+
interface RDT {
|
|
85
|
+
rdt(event: 'init', pixelId: PixelId, matchKeys?: MatchKeys): void;
|
|
86
|
+
rdt<T extends keyof StandardEvents>(event: 'track', type: T, params?: StandardEvents[T]): void;
|
|
87
|
+
rdt(event: 'track', type: 'Custom', params: CustomEventParams): void;
|
|
88
|
+
}
|
|
89
|
+
type Mapped<F extends keyof StandardEvents> = [F, StandardEvents[F]];
|
|
90
|
+
type Missed<F extends string> = ['Custom', CustomEventParams<F>];
|
|
91
|
+
declare function mapItems(items?: Item[]): undefined | Product[];
|
|
92
|
+
declare function mapRDTEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, eventId?: string): Mapped<keyof StandardEvents> | Missed<TrackName<T>>;
|
|
93
|
+
|
|
94
|
+
export { type CustomEventParams, type MatchKeys, type PixelId, type Product, type RDT, type StandardEvents, mapItems, mapRDTEvent };
|