@fire-spark/analytics-meta 0.0.0-stage → 0.1.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.
@@ -0,0 +1,10 @@
1
+ import { AnalyticsAdapter } from "@fire-spark/analytics";
2
+ //#region src/index.d.ts
3
+ type MetaLogEvent = (name: string, params?: Record<string, unknown>) => Promise<void> | void;
4
+ type MetaOptions = {
5
+ pixelId?: string;
6
+ logEvent?: MetaLogEvent;
7
+ };
8
+ declare const meta: (options?: MetaOptions) => AnalyticsAdapter;
9
+ //#endregion
10
+ export { MetaLogEvent, MetaOptions, meta };
package/dist/index.js ADDED
@@ -0,0 +1,76 @@
1
+ //#region src/index.ts
2
+ const host = () => {
3
+ return globalThis;
4
+ };
5
+ const existingFbq = () => {
6
+ const root = host();
7
+ if (typeof root.fbq === "function") return root.fbq;
8
+ const win = globalThis.window;
9
+ if (win && typeof win.fbq === "function") return win.fbq;
10
+ };
11
+ const injectScript = (src, id) => {
12
+ if (typeof document === "undefined") return Promise.resolve();
13
+ if (document.getElementById(id)) return Promise.resolve();
14
+ return new Promise((resolve, reject) => {
15
+ const el = document.createElement("script");
16
+ el.id = id;
17
+ el.async = true;
18
+ el.src = src;
19
+ el.onload = () => resolve();
20
+ el.onerror = () => reject(/* @__PURE__ */ new Error(`Failed to load ${src}`));
21
+ document.head.appendChild(el);
22
+ });
23
+ };
24
+ let loading = null;
25
+ const installFbqStub = () => {
26
+ const present = existingFbq();
27
+ if (present) return present;
28
+ const root = host();
29
+ const fbq = (...args) => {
30
+ if (fbq.callMethod) {
31
+ fbq.callMethod(...args);
32
+ return;
33
+ }
34
+ fbq.queue = fbq.queue ?? [];
35
+ fbq.queue.push(args);
36
+ };
37
+ fbq.loaded = true;
38
+ fbq.queue = [];
39
+ root.fbq = fbq;
40
+ root._fbq = fbq;
41
+ return fbq;
42
+ };
43
+ const ensureFbq = async (pixelId) => {
44
+ if (loading) return loading;
45
+ const present = existingFbq();
46
+ if (present) return present;
47
+ if (!pixelId || typeof document === "undefined") return void 0;
48
+ loading = (async () => {
49
+ const fbq = installFbqStub();
50
+ fbq("init", pixelId);
51
+ await injectScript("https://connect.facebook.net/en_US/fbevents.js", "firespark-meta-fbevents");
52
+ return existingFbq() ?? fbq;
53
+ })();
54
+ try {
55
+ return await loading;
56
+ } finally {
57
+ loading = null;
58
+ }
59
+ };
60
+ const meta = (options = {}) => {
61
+ return {
62
+ provider: "meta",
63
+ send: async (event) => {
64
+ if (event.runtime === "react-native") {
65
+ if (!options.logEvent) return;
66
+ await options.logEvent(event.name, event.params);
67
+ return;
68
+ }
69
+ const fbq = await ensureFbq(options.pixelId);
70
+ if (!fbq) return;
71
+ fbq("track", event.name, event.params);
72
+ }
73
+ };
74
+ };
75
+ //#endregion
76
+ export { meta };
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "@fire-spark/analytics-meta",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Fire Spark Meta analytics adapter (web fbevents + RN inject)",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "peerDependencies": {
20
+ "@fire-spark/analytics": "^0.1.1"
21
+ },
22
+ "devDependencies": {
23
+ "tsdown": "^0.22.14",
24
+ "typescript": "^7.0.2",
25
+ "vitest": "^2.1.8",
26
+ "@fire-spark/analytics": "0.1.1"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "tsdown": {
32
+ "entry": [
33
+ "src/index.ts"
34
+ ],
35
+ "format": [
36
+ "esm"
37
+ ],
38
+ "platform": "neutral",
39
+ "dts": {
40
+ "tsconfig": "tsconfig.build.json"
41
+ },
42
+ "clean": true,
43
+ "deps": {
44
+ "neverBundle": [
45
+ "@fire-spark/analytics"
46
+ ]
47
+ }
48
+ },
49
+ "scripts": {
50
+ "build": "tsdown",
51
+ "dev": "tsdown --watch",
52
+ "check-types": "tsc --noEmit",
53
+ "test:utils": "vitest run",
54
+ "lint": "oxlint ./src --max-warnings=0",
55
+ "format": "oxfmt ./src",
56
+ "check-format": "oxfmt --check ./src"
57
+ }
6
58
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.