@fire-spark/analytics-tiktok 0.0.0-stage → 0.1.2

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 TikTokLogEvent = (name: string, params?: Record<string, unknown>) => Promise<void> | void;
4
+ type TikTokOptions = {
5
+ pixelId?: string;
6
+ logEvent?: TikTokLogEvent;
7
+ };
8
+ declare const tiktok: (options?: TikTokOptions) => AnalyticsAdapter;
9
+ //#endregion
10
+ export { TikTokLogEvent, TikTokOptions, tiktok };
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ //#region src/index.ts
2
+ const existingTtq = () => {
3
+ const root = globalThis;
4
+ if (root.ttq) return root.ttq;
5
+ return globalThis.window?.ttq;
6
+ };
7
+ const injectScript = (src, id) => {
8
+ if (typeof document === "undefined") return Promise.resolve();
9
+ if (document.getElementById(id)) return Promise.resolve();
10
+ return new Promise((resolve, reject) => {
11
+ const el = document.createElement("script");
12
+ el.id = id;
13
+ el.async = true;
14
+ el.src = src;
15
+ el.onload = () => resolve();
16
+ el.onerror = () => reject(/* @__PURE__ */ new Error(`Failed to load ${src}`));
17
+ document.head.appendChild(el);
18
+ });
19
+ };
20
+ let loading = null;
21
+ const ensureTtq = async (pixelId) => {
22
+ if (loading) return loading;
23
+ const present = existingTtq();
24
+ if (present) return present;
25
+ if (!pixelId || typeof document === "undefined") return void 0;
26
+ loading = (async () => {
27
+ const src = `https://analytics.tiktok.com/i18n/pixel/events.js?sdkid=${encodeURIComponent(pixelId)}&lib=ttq`;
28
+ await injectScript(src, "firespark-tiktok-ttq");
29
+ const ttq = existingTtq();
30
+ ttq?.load?.(pixelId);
31
+ return ttq;
32
+ })();
33
+ try {
34
+ return await loading;
35
+ } finally {
36
+ loading = null;
37
+ }
38
+ };
39
+ const tiktok = (options = {}) => {
40
+ return {
41
+ provider: "tiktok",
42
+ send: async (event) => {
43
+ if (event.runtime === "react-native") {
44
+ if (!options.logEvent) return;
45
+ await options.logEvent(event.name, event.params);
46
+ return;
47
+ }
48
+ const ttq = await ensureTtq(options.pixelId);
49
+ if (!ttq?.track) return;
50
+ ttq.track(event.name, event.params);
51
+ }
52
+ };
53
+ };
54
+ //#endregion
55
+ export { tiktok };
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "@fire-spark/analytics-tiktok",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.2",
4
+ "description": "Fire Spark TikTok analytics adapter (web ttq + 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.2"
21
+ },
22
+ "devDependencies": {
23
+ "tsdown": "^0.22.14",
24
+ "typescript": "^7.0.2",
25
+ "vitest": "^2.1.8",
26
+ "@fire-spark/analytics": "0.1.2"
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.