@walkeros/web-destination-meta 0.4.0 → 0.4.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.
@@ -113,7 +113,7 @@ function S(e) {
113
113
  }
114
114
  function C(e = {}) {
115
115
  var _a;
116
- const t = e.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n = e.group || "gr0up", o = e.count || 1, r = y({ name: "entity action", data: { string: "foo", number: 1, boolean: true, array: [0, "text", false], not: void 0 }, context: { dev: ["test", 1] }, globals: { lang: "elb" }, custom: { completely: "random" }, user: { id: "us3r", device: "c00k13", session: "s3ss10n" }, nested: [{ entity: "child", data: { is: "subordinated" }, nested: [], context: { element: ["child", 0] } }], consent: { functional: true }, id: `${t}-${n}-${o}`, trigger: "test", entity: "entity", action: "action", timestamp: t, timing: 3.14, group: n, count: o, version: { source: "0.3.1", tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e, { merge: false });
116
+ const t = e.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n = e.group || "gr0up", o = e.count || 1, r = y({ name: "entity action", data: { string: "foo", number: 1, boolean: true, array: [0, "text", false], not: void 0 }, context: { dev: ["test", 1] }, globals: { lang: "elb" }, custom: { completely: "random" }, user: { id: "us3r", device: "c00k13", session: "s3ss10n" }, nested: [{ entity: "child", data: { is: "subordinated" }, nested: [], context: { element: ["child", 0] } }], consent: { functional: true }, id: `${t}-${n}-${o}`, trigger: "test", entity: "entity", action: "action", timestamp: t, timing: 3.14, group: n, count: o, version: { source: "0.4.1", tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e, { merge: false });
117
117
  if (e.name) {
118
118
  const [t2, n2] = (_a = e.name.split(" ")) != null ? _a : [];
119
119
  t2 && n2 && (r.entity = t2, r.action = n2);
@@ -91,7 +91,7 @@ function S(e) {
91
91
  }
92
92
  function C(e = {}) {
93
93
  var _a;
94
- const t = e.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n = e.group || "gr0up", o = e.count || 1, r = y({ name: "entity action", data: { string: "foo", number: 1, boolean: true, array: [0, "text", false], not: void 0 }, context: { dev: ["test", 1] }, globals: { lang: "elb" }, custom: { completely: "random" }, user: { id: "us3r", device: "c00k13", session: "s3ss10n" }, nested: [{ entity: "child", data: { is: "subordinated" }, nested: [], context: { element: ["child", 0] } }], consent: { functional: true }, id: `${t}-${n}-${o}`, trigger: "test", entity: "entity", action: "action", timestamp: t, timing: 3.14, group: n, count: o, version: { source: "0.3.1", tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e, { merge: false });
94
+ const t = e.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n = e.group || "gr0up", o = e.count || 1, r = y({ name: "entity action", data: { string: "foo", number: 1, boolean: true, array: [0, "text", false], not: void 0 }, context: { dev: ["test", 1] }, globals: { lang: "elb" }, custom: { completely: "random" }, user: { id: "us3r", device: "c00k13", session: "s3ss10n" }, nested: [{ entity: "child", data: { is: "subordinated" }, nested: [], context: { element: ["child", 0] } }], consent: { functional: true }, id: `${t}-${n}-${o}`, trigger: "test", entity: "entity", action: "action", timestamp: t, timing: 3.14, group: n, count: o, version: { source: "0.4.1", tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e, { merge: false });
95
95
  if (e.name) {
96
96
  const [t2, n2] = (_a = e.name.split(" ")) != null ? _a : [];
97
97
  t2 && n2 && (r.entity = t2, r.action = n2);
package/dist/index.d.mts CHANGED
@@ -10,6 +10,7 @@ declare global {
10
10
  interface Settings {
11
11
  pixelId: string;
12
12
  }
13
+ type InitSettings = Partial<Settings>;
13
14
  interface Mapping {
14
15
  track?: StandardEventNames;
15
16
  trackCustom?: string;
@@ -26,7 +27,7 @@ interface Env extends DestinationWeb.Env {
26
27
  };
27
28
  };
28
29
  }
29
- type Types = Destination$1.Types<Settings, Mapping, Env>;
30
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
30
31
  type Destination = DestinationWeb.Destination<Types>;
31
32
  type Config = DestinationWeb.Config<Types>;
32
33
  type Rule = Mapping$1.Rule<Mapping>;
@@ -36,6 +37,7 @@ type StandardEventNames = 'PageView' | 'AddPaymentInfo' | 'AddToCart' | 'AddToWi
36
37
  type index_Config = Config;
37
38
  type index_Destination = Destination;
38
39
  type index_Env = Env;
40
+ type index_InitSettings = InitSettings;
39
41
  type index_Mapping = Mapping;
40
42
  type index_Rule = Rule;
41
43
  type index_Rules = Rules;
@@ -43,7 +45,7 @@ type index_Settings = Settings;
43
45
  type index_StandardEventNames = StandardEventNames;
44
46
  type index_Types = Types;
45
47
  declare namespace index {
46
- export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_Mapping as Mapping, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_StandardEventNames as StandardEventNames, index_Types as Types };
48
+ export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_InitSettings as InitSettings, index_Mapping as Mapping, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_StandardEventNames as StandardEventNames, index_Types as Types };
47
49
  }
48
50
 
49
51
  declare const destinationMeta: Destination;
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ declare global {
10
10
  interface Settings {
11
11
  pixelId: string;
12
12
  }
13
+ type InitSettings = Partial<Settings>;
13
14
  interface Mapping {
14
15
  track?: StandardEventNames;
15
16
  trackCustom?: string;
@@ -26,7 +27,7 @@ interface Env extends DestinationWeb.Env {
26
27
  };
27
28
  };
28
29
  }
29
- type Types = Destination$1.Types<Settings, Mapping, Env>;
30
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
30
31
  type Destination = DestinationWeb.Destination<Types>;
31
32
  type Config = DestinationWeb.Config<Types>;
32
33
  type Rule = Mapping$1.Rule<Mapping>;
@@ -36,6 +37,7 @@ type StandardEventNames = 'PageView' | 'AddPaymentInfo' | 'AddToCart' | 'AddToWi
36
37
  type index_Config = Config;
37
38
  type index_Destination = Destination;
38
39
  type index_Env = Env;
40
+ type index_InitSettings = InitSettings;
39
41
  type index_Mapping = Mapping;
40
42
  type index_Rule = Rule;
41
43
  type index_Rules = Rules;
@@ -43,7 +45,7 @@ type index_Settings = Settings;
43
45
  type index_StandardEventNames = StandardEventNames;
44
46
  type index_Types = Types;
45
47
  declare namespace index {
46
- export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_Mapping as Mapping, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_StandardEventNames as StandardEventNames, index_Types as Types };
48
+ export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_InitSettings as InitSettings, index_Mapping as Mapping, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_StandardEventNames as StandardEventNames, index_Types as Types };
47
49
  }
48
50
 
49
51
  declare const destinationMeta: Destination;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/setup.ts","../src/types/index.ts"],"sourcesContent":["import type { Settings, Destination } from './types';\nimport { addScript, setup } from './setup';\nimport { isObject } from '@walkeros/core';\nimport { getEnv } from '@walkeros/web-core';\n\n// Types\nexport * as DestinationMeta from './types';\n\nexport const destinationMeta: Destination = {\n type: 'meta-pixel',\n\n config: {},\n\n init({ config, env }) {\n const { settings, loadScript } = config;\n const { pixelId } = settings || {};\n\n // Load Meta Pixel script if required (fbevents.js)\n if (loadScript) addScript(env);\n\n // Required pixel id\n if (!pixelId) return false;\n\n // fbq function setup\n setup(env);\n\n const { window } = getEnv(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n fbq('init', pixelId);\n },\n\n push(event, { config, mapping = {}, data, env }) {\n const { track, trackCustom } = mapping.settings || {};\n const { window } = getEnv(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n\n // page view\n if (event.name === 'page view' && !mapping.settings) {\n // Define a custom mapping\n event.name = 'PageView';\n }\n\n const eventName = track || trackCustom || event.name;\n\n fbq(\n trackCustom ? 'trackCustom' : 'track',\n String(eventName),\n isObject(data) ? data : {},\n { eventID: event.id },\n );\n },\n};\n\nexport default destinationMeta;\n","import type { DestinationWeb } from '@walkeros/web-core';\nimport { getEnv } from '@walkeros/web-core';\n\nexport function addScript(\n env?: DestinationWeb.Env,\n src = 'https://connect.facebook.net/en_US/fbevents.js',\n) {\n const { document } = getEnv(env);\n const script = (document as Document).createElement('script');\n script.src = src;\n script.async = true;\n (document as Document).head.appendChild(script);\n}\n\ninterface FBQFunction {\n (...args: unknown[]): void;\n callMethod?: (this: FBQFunction, ...args: unknown[]) => void;\n queue: unknown[];\n push: FBQFunction;\n loaded: boolean;\n version: string;\n}\n\nexport function setup(env?: DestinationWeb.Env) {\n const { window } = getEnv(env);\n const w = window as unknown as {\n fbq?: FBQFunction;\n _fbq?: FBQFunction;\n };\n if (w.fbq as unknown) return;\n\n const n = function (...args: unknown[]): void {\n n.callMethod ? n.callMethod.apply(n, args) : n.queue.push(args);\n } as FBQFunction;\n\n w.fbq = n;\n if (!w._fbq) w._fbq = n;\n n.push = n;\n n.loaded = true;\n n.version = '2.0';\n n.queue = [];\n}\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n\ndeclare global {\n interface Window {\n _fbq?: facebook.Pixel.Event;\n fbq?: facebook.Pixel.Event;\n }\n}\n\nexport interface Settings {\n pixelId: string;\n}\n\nexport interface Mapping {\n track?: StandardEventNames;\n trackCustom?: string;\n}\n\nexport interface Env extends DestinationWeb.Env {\n window: {\n fbq: facebook.Pixel.Event;\n _fbq?: facebook.Pixel.Event;\n };\n document: {\n createElement: (tagName: string) => Element;\n head: { appendChild: (node: unknown) => void };\n };\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env>;\n\nexport type Destination = DestinationWeb.Destination<Types>;\nexport type Config = DestinationWeb.Config<Types>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\nexport type StandardEventNames =\n | 'PageView'\n | 'AddPaymentInfo'\n | 'AddToCart'\n | 'AddToWishlist'\n | 'CompleteRegistration'\n | 'Contact'\n | 'CustomizeProduct'\n | 'Donate'\n | 'FindLocation'\n | 'InitiateCheckout'\n | 'Lead'\n | 'Purchase'\n | 'Schedule'\n | 'Search'\n | 'StartTrial'\n | 'SubmitApplication'\n | 'Subscribe'\n | 'ViewContent'\n | string;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sBAAuB;AAEhB,SAAS,UACd,KACA,MAAM,kDACN;AACA,QAAM,EAAE,UAAAA,UAAS,QAAI,wBAAO,GAAG;AAC/B,QAAM,SAAUA,UAAsB,cAAc,QAAQ;AAC5D,SAAO,MAAM;AACb,SAAO,QAAQ;AACf,EAACA,UAAsB,KAAK,YAAY,MAAM;AAChD;AAWO,SAAS,MAAM,KAA0B;AAC9C,QAAM,EAAE,OAAO,QAAI,wBAAO,GAAG;AAC7B,QAAM,IAAI;AAIV,MAAI,EAAE,IAAgB;AAEtB,QAAM,IAAI,YAAa,MAAuB;AAC5C,MAAE,aAAa,EAAE,WAAW,MAAM,GAAG,IAAI,IAAI,EAAE,MAAM,KAAK,IAAI;AAAA,EAChE;AAEA,IAAE,MAAM;AACR,MAAI,CAAC,EAAE,KAAM,GAAE,OAAO;AACtB,IAAE,OAAO;AACT,IAAE,SAAS;AACX,IAAE,UAAU;AACZ,IAAE,QAAQ,CAAC;AACb;A;;;;;;;;;;ADtCA,IAAAC,mBAAuB;;;AEHvB;;;AFQO,IAAM,kBAA+B;AAAA,EAC1C,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,KAAK,EAAE,QAAQ,IAAI,GAAG;AACpB,UAAM,EAAE,UAAU,WAAW,IAAI;AACjC,UAAM,EAAE,QAAQ,IAAI,YAAY,CAAC;AAGjC,QAAI,WAAY,WAAU,GAAG;AAG7B,QAAI,CAAC,QAAS,QAAO;AAGrB,UAAM,GAAG;AAET,UAAM,EAAE,OAAO,QAAI,yBAAO,GAAG;AAC7B,UAAM,MAAM,OAAO;AACnB,QAAI,QAAQ,OAAO;AAAA,EACrB;AAAA,EAEA,KAAK,OAAO,EAAE,QAAQ,UAAU,CAAC,GAAG,MAAM,IAAI,GAAG;AAC/C,UAAM,EAAE,OAAO,YAAY,IAAI,QAAQ,YAAY,CAAC;AACpD,UAAM,EAAE,OAAO,QAAI,yBAAO,GAAG;AAC7B,UAAM,MAAM,OAAO;AAGnB,QAAI,MAAM,SAAS,eAAe,CAAC,QAAQ,UAAU;AAEnD,YAAM,OAAO;AAAA,IACf;AAEA,UAAM,YAAY,SAAS,eAAe,MAAM;AAEhD;AAAA,MACE,cAAc,gBAAgB;AAAA,MAC9B,OAAO,SAAS;AAAA,MAChB,EAAS,IAAI,IAAI,OAAO,CAAC;AAAA,MACzB,EAAE,SAAS,MAAM,GAAG;AAAA,IACtB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["document","import_web_core"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/setup.ts","../src/types/index.ts"],"sourcesContent":["import type { Settings, Destination } from './types';\nimport { addScript, setup } from './setup';\nimport { isObject } from '@walkeros/core';\nimport { getEnv } from '@walkeros/web-core';\n\n// Types\nexport * as DestinationMeta from './types';\n\nexport const destinationMeta: Destination = {\n type: 'meta-pixel',\n\n config: {},\n\n init({ config, env }) {\n const { settings, loadScript } = config;\n const { pixelId } = settings || {};\n\n // Load Meta Pixel script if required (fbevents.js)\n if (loadScript) addScript(env);\n\n // Required pixel id\n if (!pixelId) return false;\n\n // fbq function setup\n setup(env);\n\n const { window } = getEnv(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n fbq('init', pixelId);\n },\n\n push(event, { config, mapping = {}, data, env }) {\n const { track, trackCustom } = mapping.settings || {};\n const { window } = getEnv(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n\n // page view\n if (event.name === 'page view' && !mapping.settings) {\n // Define a custom mapping\n event.name = 'PageView';\n }\n\n const eventName = track || trackCustom || event.name;\n\n fbq(\n trackCustom ? 'trackCustom' : 'track',\n String(eventName),\n isObject(data) ? data : {},\n { eventID: event.id },\n );\n },\n};\n\nexport default destinationMeta;\n","import type { DestinationWeb } from '@walkeros/web-core';\nimport { getEnv } from '@walkeros/web-core';\n\nexport function addScript(\n env?: DestinationWeb.Env,\n src = 'https://connect.facebook.net/en_US/fbevents.js',\n) {\n const { document } = getEnv(env);\n const script = (document as Document).createElement('script');\n script.src = src;\n script.async = true;\n (document as Document).head.appendChild(script);\n}\n\ninterface FBQFunction {\n (...args: unknown[]): void;\n callMethod?: (this: FBQFunction, ...args: unknown[]) => void;\n queue: unknown[];\n push: FBQFunction;\n loaded: boolean;\n version: string;\n}\n\nexport function setup(env?: DestinationWeb.Env) {\n const { window } = getEnv(env);\n const w = window as unknown as {\n fbq?: FBQFunction;\n _fbq?: FBQFunction;\n };\n if (w.fbq as unknown) return;\n\n const n = function (...args: unknown[]): void {\n n.callMethod ? n.callMethod.apply(n, args) : n.queue.push(args);\n } as FBQFunction;\n\n w.fbq = n;\n if (!w._fbq) w._fbq = n;\n n.push = n;\n n.loaded = true;\n n.version = '2.0';\n n.queue = [];\n}\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n\ndeclare global {\n interface Window {\n _fbq?: facebook.Pixel.Event;\n fbq?: facebook.Pixel.Event;\n }\n}\n\nexport interface Settings {\n pixelId: string;\n}\n\nexport type InitSettings = Partial<Settings>;\n\nexport interface Mapping {\n track?: StandardEventNames;\n trackCustom?: string;\n}\n\nexport interface Env extends DestinationWeb.Env {\n window: {\n fbq: facebook.Pixel.Event;\n _fbq?: facebook.Pixel.Event;\n };\n document: {\n createElement: (tagName: string) => Element;\n head: { appendChild: (node: unknown) => void };\n };\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport type Destination = DestinationWeb.Destination<Types>;\nexport type Config = DestinationWeb.Config<Types>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\nexport type StandardEventNames =\n | 'PageView'\n | 'AddPaymentInfo'\n | 'AddToCart'\n | 'AddToWishlist'\n | 'CompleteRegistration'\n | 'Contact'\n | 'CustomizeProduct'\n | 'Donate'\n | 'FindLocation'\n | 'InitiateCheckout'\n | 'Lead'\n | 'Purchase'\n | 'Schedule'\n | 'Search'\n | 'StartTrial'\n | 'SubmitApplication'\n | 'Subscribe'\n | 'ViewContent'\n | string;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sBAAuB;AAEhB,SAAS,UACd,KACA,MAAM,kDACN;AACA,QAAM,EAAE,UAAAA,UAAS,QAAI,wBAAO,GAAG;AAC/B,QAAM,SAAUA,UAAsB,cAAc,QAAQ;AAC5D,SAAO,MAAM;AACb,SAAO,QAAQ;AACf,EAACA,UAAsB,KAAK,YAAY,MAAM;AAChD;AAWO,SAAS,MAAM,KAA0B;AAC9C,QAAM,EAAE,OAAO,QAAI,wBAAO,GAAG;AAC7B,QAAM,IAAI;AAIV,MAAI,EAAE,IAAgB;AAEtB,QAAM,IAAI,YAAa,MAAuB;AAC5C,MAAE,aAAa,EAAE,WAAW,MAAM,GAAG,IAAI,IAAI,EAAE,MAAM,KAAK,IAAI;AAAA,EAChE;AAEA,IAAE,MAAM;AACR,MAAI,CAAC,EAAE,KAAM,GAAE,OAAO;AACtB,IAAE,OAAO;AACT,IAAE,SAAS;AACX,IAAE,UAAU;AACZ,IAAE,QAAQ,CAAC;AACb;A;;;;;;;;;;ADtCA,IAAAC,mBAAuB;;;AEHvB;;;AFQO,IAAM,kBAA+B;AAAA,EAC1C,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,KAAK,EAAE,QAAQ,IAAI,GAAG;AACpB,UAAM,EAAE,UAAU,WAAW,IAAI;AACjC,UAAM,EAAE,QAAQ,IAAI,YAAY,CAAC;AAGjC,QAAI,WAAY,WAAU,GAAG;AAG7B,QAAI,CAAC,QAAS,QAAO;AAGrB,UAAM,GAAG;AAET,UAAM,EAAE,OAAO,QAAI,yBAAO,GAAG;AAC7B,UAAM,MAAM,OAAO;AACnB,QAAI,QAAQ,OAAO;AAAA,EACrB;AAAA,EAEA,KAAK,OAAO,EAAE,QAAQ,UAAU,CAAC,GAAG,MAAM,IAAI,GAAG;AAC/C,UAAM,EAAE,OAAO,YAAY,IAAI,QAAQ,YAAY,CAAC;AACpD,UAAM,EAAE,OAAO,QAAI,yBAAO,GAAG;AAC7B,UAAM,MAAM,OAAO;AAGnB,QAAI,MAAM,SAAS,eAAe,CAAC,QAAQ,UAAU;AAEnD,YAAM,OAAO;AAAA,IACf;AAEA,UAAM,YAAY,SAAS,eAAe,MAAM;AAEhD;AAAA,MACE,cAAc,gBAAgB;AAAA,MAC9B,OAAO,SAAS;AAAA,MAChB,EAAS,IAAI,IAAI,OAAO,CAAC;AAAA,MACzB,EAAE,SAAS,MAAM,GAAG;AAAA,IACtB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["document","import_web_core"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/setup.ts","../src/index.ts","../src/types/index.ts"],"sourcesContent":["import type { DestinationWeb } from '@walkeros/web-core';\nimport { getEnv } from '@walkeros/web-core';\n\nexport function addScript(\n env?: DestinationWeb.Env,\n src = 'https://connect.facebook.net/en_US/fbevents.js',\n) {\n const { document } = getEnv(env);\n const script = (document as Document).createElement('script');\n script.src = src;\n script.async = true;\n (document as Document).head.appendChild(script);\n}\n\ninterface FBQFunction {\n (...args: unknown[]): void;\n callMethod?: (this: FBQFunction, ...args: unknown[]) => void;\n queue: unknown[];\n push: FBQFunction;\n loaded: boolean;\n version: string;\n}\n\nexport function setup(env?: DestinationWeb.Env) {\n const { window } = getEnv(env);\n const w = window as unknown as {\n fbq?: FBQFunction;\n _fbq?: FBQFunction;\n };\n if (w.fbq as unknown) return;\n\n const n = function (...args: unknown[]): void {\n n.callMethod ? n.callMethod.apply(n, args) : n.queue.push(args);\n } as FBQFunction;\n\n w.fbq = n;\n if (!w._fbq) w._fbq = n;\n n.push = n;\n n.loaded = true;\n n.version = '2.0';\n n.queue = [];\n}\n","import type { Settings, Destination } from './types';\nimport { addScript, setup } from './setup';\nimport { isObject } from '@walkeros/core';\nimport { getEnv } from '@walkeros/web-core';\n\n// Types\nexport * as DestinationMeta from './types';\n\nexport const destinationMeta: Destination = {\n type: 'meta-pixel',\n\n config: {},\n\n init({ config, env }) {\n const { settings, loadScript } = config;\n const { pixelId } = settings || {};\n\n // Load Meta Pixel script if required (fbevents.js)\n if (loadScript) addScript(env);\n\n // Required pixel id\n if (!pixelId) return false;\n\n // fbq function setup\n setup(env);\n\n const { window } = getEnv(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n fbq('init', pixelId);\n },\n\n push(event, { config, mapping = {}, data, env }) {\n const { track, trackCustom } = mapping.settings || {};\n const { window } = getEnv(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n\n // page view\n if (event.name === 'page view' && !mapping.settings) {\n // Define a custom mapping\n event.name = 'PageView';\n }\n\n const eventName = track || trackCustom || event.name;\n\n fbq(\n trackCustom ? 'trackCustom' : 'track',\n String(eventName),\n isObject(data) ? data : {},\n { eventID: event.id },\n );\n },\n};\n\nexport default destinationMeta;\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n\ndeclare global {\n interface Window {\n _fbq?: facebook.Pixel.Event;\n fbq?: facebook.Pixel.Event;\n }\n}\n\nexport interface Settings {\n pixelId: string;\n}\n\nexport interface Mapping {\n track?: StandardEventNames;\n trackCustom?: string;\n}\n\nexport interface Env extends DestinationWeb.Env {\n window: {\n fbq: facebook.Pixel.Event;\n _fbq?: facebook.Pixel.Event;\n };\n document: {\n createElement: (tagName: string) => Element;\n head: { appendChild: (node: unknown) => void };\n };\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env>;\n\nexport type Destination = DestinationWeb.Destination<Types>;\nexport type Config = DestinationWeb.Config<Types>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\nexport type StandardEventNames =\n | 'PageView'\n | 'AddPaymentInfo'\n | 'AddToCart'\n | 'AddToWishlist'\n | 'CompleteRegistration'\n | 'Contact'\n | 'CustomizeProduct'\n | 'Donate'\n | 'FindLocation'\n | 'InitiateCheckout'\n | 'Lead'\n | 'Purchase'\n | 'Schedule'\n | 'Search'\n | 'StartTrial'\n | 'SubmitApplication'\n | 'Subscribe'\n | 'ViewContent'\n | string;\n"],"mappings":";AACA,SAAS,cAAc;AAEhB,SAAS,UACd,KACA,MAAM,kDACN;AACA,QAAM,EAAE,UAAAA,UAAS,IAAI,OAAO,GAAG;AAC/B,QAAM,SAAUA,UAAsB,cAAc,QAAQ;AAC5D,SAAO,MAAM;AACb,SAAO,QAAQ;AACf,EAACA,UAAsB,KAAK,YAAY,MAAM;AAChD;AAWO,SAAS,MAAM,KAA0B;AAC9C,QAAM,EAAE,OAAO,IAAI,OAAO,GAAG;AAC7B,QAAM,IAAI;AAIV,MAAI,EAAE,IAAgB;AAEtB,QAAM,IAAI,YAAa,MAAuB;AAC5C,MAAE,aAAa,EAAE,WAAW,MAAM,GAAG,IAAI,IAAI,EAAE,MAAM,KAAK,IAAI;AAAA,EAChE;AAEA,IAAE,MAAM;AACR,MAAI,CAAC,EAAE,KAAM,GAAE,OAAO;AACtB,IAAE,OAAO;AACT,IAAE,SAAS;AACX,IAAE,UAAU;AACZ,IAAE,QAAQ,CAAC;AACb;A;;;;;;;;;;ACtCA,SAAS,UAAAC,eAAc;;;ACHvB;;;ADQO,IAAM,kBAA+B;AAAA,EAC1C,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,KAAK,EAAE,QAAQ,IAAI,GAAG;AACpB,UAAM,EAAE,UAAU,WAAW,IAAI;AACjC,UAAM,EAAE,QAAQ,IAAI,YAAY,CAAC;AAGjC,QAAI,WAAY,WAAU,GAAG;AAG7B,QAAI,CAAC,QAAS,QAAO;AAGrB,UAAM,GAAG;AAET,UAAM,EAAE,OAAO,IAAIC,QAAO,GAAG;AAC7B,UAAM,MAAM,OAAO;AACnB,QAAI,QAAQ,OAAO;AAAA,EACrB;AAAA,EAEA,KAAK,OAAO,EAAE,QAAQ,UAAU,CAAC,GAAG,MAAM,IAAI,GAAG;AAC/C,UAAM,EAAE,OAAO,YAAY,IAAI,QAAQ,YAAY,CAAC;AACpD,UAAM,EAAE,OAAO,IAAIA,QAAO,GAAG;AAC7B,UAAM,MAAM,OAAO;AAGnB,QAAI,MAAM,SAAS,eAAe,CAAC,QAAQ,UAAU;AAEnD,YAAM,OAAO;AAAA,IACf;AAEA,UAAM,YAAY,SAAS,eAAe,MAAM;AAEhD;AAAA,MACE,cAAc,gBAAgB;AAAA,MAC9B,OAAO,SAAS;AAAA,MAChB,EAAS,IAAI,IAAI,OAAO,CAAC;AAAA,MACzB,EAAE,SAAS,MAAM,GAAG;AAAA,IACtB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["document","getEnv","getEnv"]}
1
+ {"version":3,"sources":["../src/setup.ts","../src/index.ts","../src/types/index.ts"],"sourcesContent":["import type { DestinationWeb } from '@walkeros/web-core';\nimport { getEnv } from '@walkeros/web-core';\n\nexport function addScript(\n env?: DestinationWeb.Env,\n src = 'https://connect.facebook.net/en_US/fbevents.js',\n) {\n const { document } = getEnv(env);\n const script = (document as Document).createElement('script');\n script.src = src;\n script.async = true;\n (document as Document).head.appendChild(script);\n}\n\ninterface FBQFunction {\n (...args: unknown[]): void;\n callMethod?: (this: FBQFunction, ...args: unknown[]) => void;\n queue: unknown[];\n push: FBQFunction;\n loaded: boolean;\n version: string;\n}\n\nexport function setup(env?: DestinationWeb.Env) {\n const { window } = getEnv(env);\n const w = window as unknown as {\n fbq?: FBQFunction;\n _fbq?: FBQFunction;\n };\n if (w.fbq as unknown) return;\n\n const n = function (...args: unknown[]): void {\n n.callMethod ? n.callMethod.apply(n, args) : n.queue.push(args);\n } as FBQFunction;\n\n w.fbq = n;\n if (!w._fbq) w._fbq = n;\n n.push = n;\n n.loaded = true;\n n.version = '2.0';\n n.queue = [];\n}\n","import type { Settings, Destination } from './types';\nimport { addScript, setup } from './setup';\nimport { isObject } from '@walkeros/core';\nimport { getEnv } from '@walkeros/web-core';\n\n// Types\nexport * as DestinationMeta from './types';\n\nexport const destinationMeta: Destination = {\n type: 'meta-pixel',\n\n config: {},\n\n init({ config, env }) {\n const { settings, loadScript } = config;\n const { pixelId } = settings || {};\n\n // Load Meta Pixel script if required (fbevents.js)\n if (loadScript) addScript(env);\n\n // Required pixel id\n if (!pixelId) return false;\n\n // fbq function setup\n setup(env);\n\n const { window } = getEnv(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n fbq('init', pixelId);\n },\n\n push(event, { config, mapping = {}, data, env }) {\n const { track, trackCustom } = mapping.settings || {};\n const { window } = getEnv(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n\n // page view\n if (event.name === 'page view' && !mapping.settings) {\n // Define a custom mapping\n event.name = 'PageView';\n }\n\n const eventName = track || trackCustom || event.name;\n\n fbq(\n trackCustom ? 'trackCustom' : 'track',\n String(eventName),\n isObject(data) ? data : {},\n { eventID: event.id },\n );\n },\n};\n\nexport default destinationMeta;\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n\ndeclare global {\n interface Window {\n _fbq?: facebook.Pixel.Event;\n fbq?: facebook.Pixel.Event;\n }\n}\n\nexport interface Settings {\n pixelId: string;\n}\n\nexport type InitSettings = Partial<Settings>;\n\nexport interface Mapping {\n track?: StandardEventNames;\n trackCustom?: string;\n}\n\nexport interface Env extends DestinationWeb.Env {\n window: {\n fbq: facebook.Pixel.Event;\n _fbq?: facebook.Pixel.Event;\n };\n document: {\n createElement: (tagName: string) => Element;\n head: { appendChild: (node: unknown) => void };\n };\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport type Destination = DestinationWeb.Destination<Types>;\nexport type Config = DestinationWeb.Config<Types>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\nexport type StandardEventNames =\n | 'PageView'\n | 'AddPaymentInfo'\n | 'AddToCart'\n | 'AddToWishlist'\n | 'CompleteRegistration'\n | 'Contact'\n | 'CustomizeProduct'\n | 'Donate'\n | 'FindLocation'\n | 'InitiateCheckout'\n | 'Lead'\n | 'Purchase'\n | 'Schedule'\n | 'Search'\n | 'StartTrial'\n | 'SubmitApplication'\n | 'Subscribe'\n | 'ViewContent'\n | string;\n"],"mappings":";AACA,SAAS,cAAc;AAEhB,SAAS,UACd,KACA,MAAM,kDACN;AACA,QAAM,EAAE,UAAAA,UAAS,IAAI,OAAO,GAAG;AAC/B,QAAM,SAAUA,UAAsB,cAAc,QAAQ;AAC5D,SAAO,MAAM;AACb,SAAO,QAAQ;AACf,EAACA,UAAsB,KAAK,YAAY,MAAM;AAChD;AAWO,SAAS,MAAM,KAA0B;AAC9C,QAAM,EAAE,OAAO,IAAI,OAAO,GAAG;AAC7B,QAAM,IAAI;AAIV,MAAI,EAAE,IAAgB;AAEtB,QAAM,IAAI,YAAa,MAAuB;AAC5C,MAAE,aAAa,EAAE,WAAW,MAAM,GAAG,IAAI,IAAI,EAAE,MAAM,KAAK,IAAI;AAAA,EAChE;AAEA,IAAE,MAAM;AACR,MAAI,CAAC,EAAE,KAAM,GAAE,OAAO;AACtB,IAAE,OAAO;AACT,IAAE,SAAS;AACX,IAAE,UAAU;AACZ,IAAE,QAAQ,CAAC;AACb;A;;;;;;;;;;ACtCA,SAAS,UAAAC,eAAc;;;ACHvB;;;ADQO,IAAM,kBAA+B;AAAA,EAC1C,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,KAAK,EAAE,QAAQ,IAAI,GAAG;AACpB,UAAM,EAAE,UAAU,WAAW,IAAI;AACjC,UAAM,EAAE,QAAQ,IAAI,YAAY,CAAC;AAGjC,QAAI,WAAY,WAAU,GAAG;AAG7B,QAAI,CAAC,QAAS,QAAO;AAGrB,UAAM,GAAG;AAET,UAAM,EAAE,OAAO,IAAIC,QAAO,GAAG;AAC7B,UAAM,MAAM,OAAO;AACnB,QAAI,QAAQ,OAAO;AAAA,EACrB;AAAA,EAEA,KAAK,OAAO,EAAE,QAAQ,UAAU,CAAC,GAAG,MAAM,IAAI,GAAG;AAC/C,UAAM,EAAE,OAAO,YAAY,IAAI,QAAQ,YAAY,CAAC;AACpD,UAAM,EAAE,OAAO,IAAIA,QAAO,GAAG;AAC7B,UAAM,MAAM,OAAO;AAGnB,QAAI,MAAM,SAAS,eAAe,CAAC,QAAQ,UAAU;AAEnD,YAAM,OAAO;AAAA,IACf;AAEA,UAAM,YAAY,SAAS,eAAe,MAAM;AAEhD;AAAA,MACE,cAAc,gBAAgB;AAAA,MAC9B,OAAO,SAAS;AAAA,MAChB,EAAS,IAAI,IAAI,OAAO,CAAC;AAAA,MACzB,EAAE,SAAS,MAAM,GAAG;AAAA,IACtB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["document","getEnv","getEnv"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@walkeros/web-destination-meta",
3
3
  "description": "Meta pixel web destination for walkerOS",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -35,7 +35,7 @@
35
35
  "update": "npx npm-check-updates -u && npm update"
36
36
  },
37
37
  "dependencies": {
38
- "@walkeros/web-core": "0.4.0"
38
+ "@walkeros/web-core": "0.4.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/facebook-pixel": "^0.0.31"