@funnelsgrove/analytics 0.1.13 → 0.1.14

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.
@@ -11,15 +11,25 @@ export type AnalyticsEventForMetaPixel = {
11
11
  };
12
12
  declare global {
13
13
  interface Window {
14
- fbq?: (...args: unknown[]) => void;
14
+ fbq?: MetaPixelQueue;
15
+ _fbq?: MetaPixelQueue;
15
16
  }
16
17
  }
18
+ type MetaPixelQueue = {
19
+ (...args: unknown[]): void;
20
+ callMethod?: (...args: unknown[]) => void;
21
+ loaded?: boolean;
22
+ push?: MetaPixelQueue;
23
+ queue?: unknown[][];
24
+ version?: string;
25
+ };
17
26
  export declare const mapAnalyticsEventToMetaPixelEvent: (event: AnalyticsEventForMetaPixel) => MetaPixelTrackInput | null;
18
27
  export declare class MetaPixelService {
19
28
  private initialized;
20
29
  track(input: MetaPixelTrackInput): void;
21
30
  private isConfigured;
22
31
  private ensureInitialized;
32
+ private ensureQueue;
23
33
  private installScript;
24
34
  }
25
35
  export declare const metaPixelService: MetaPixelService;
@@ -78,10 +78,30 @@ export class MetaPixelService {
78
78
  return;
79
79
  }
80
80
  this.initialized = true;
81
+ this.ensureQueue();
81
82
  this.installScript();
82
83
  (_a = window.fbq) === null || _a === void 0 ? void 0 : _a.call(window, 'init', META_PIXEL_ID);
83
84
  (_b = window.fbq) === null || _b === void 0 ? void 0 : _b.call(window, 'track', 'PageView');
84
85
  }
86
+ ensureQueue() {
87
+ if (typeof window.fbq === 'function') {
88
+ return;
89
+ }
90
+ const fbq = (...args) => {
91
+ var _a;
92
+ if (typeof fbq.callMethod === 'function') {
93
+ fbq.callMethod(...args);
94
+ return;
95
+ }
96
+ (_a = fbq.queue) === null || _a === void 0 ? void 0 : _a.push(args);
97
+ };
98
+ fbq.push = fbq;
99
+ fbq.loaded = true;
100
+ fbq.version = '2.0';
101
+ fbq.queue = [];
102
+ window.fbq = fbq;
103
+ window._fbq = window._fbq || fbq;
104
+ }
85
105
  installScript() {
86
106
  if (typeof document === 'undefined') {
87
107
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/analytics",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",