pishoniq-tracker 0.0.0-stage → 2.0.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.
@@ -0,0 +1,50 @@
1
+ interface AutoCaptureOptions {
2
+ clicks?: boolean;
3
+ pageViews?: boolean;
4
+ scrollDepth?: boolean;
5
+ sessions?: boolean;
6
+ }
7
+ interface InitOptions {
8
+ apiKey: string;
9
+ /** Backend host to send events to, e.g. "https://analytics.example.com". Required — there is no default. */
10
+ host: string;
11
+ debug?: boolean;
12
+ /** Disable individual auto-captured event groups. Defaults to all enabled. */
13
+ autoCapture?: AutoCaptureOptions;
14
+ /** 0..1 — fraction of events to keep. Default 1 (no sampling). */
15
+ sampleRate?: number;
16
+ /** Flush interval in ms. Default 2000. Paused while tab is hidden. */
17
+ flushIntervalMs?: number;
18
+ /** Immediate flush threshold. Default 100. */
19
+ maxBatchSize?: number;
20
+ /** In-memory queue cap; oldest events dropped past it. Default 1000. */
21
+ maxQueueSize?: number;
22
+ }
23
+ interface EventPayload {
24
+ sessionId: string;
25
+ userId?: string;
26
+ event: string;
27
+ properties?: Record<string, unknown>;
28
+ timestamp: number;
29
+ url: string;
30
+ userAgent: string;
31
+ /** Payload version. Defaults to 1. Reserved for future breaking changes. */
32
+ schemaVersion?: number;
33
+ }
34
+ interface EventsBatchBody {
35
+ events: EventPayload[];
36
+ }
37
+
38
+ declare class PishonIQ {
39
+ static isInitialized(): boolean;
40
+ static init(options: InitOptions): void;
41
+ static track(event: string, properties?: Record<string, unknown>): void;
42
+ static identify(id: string, traits?: Record<string, unknown>): void;
43
+ static page(pageName?: string): void;
44
+ /** @internal Used by React integration to avoid duplicate page_view events */
45
+ static _setReactRouterActive(active: boolean): void;
46
+ /** @internal Reset SDK state (testing only) */
47
+ static _reset(): void;
48
+ }
49
+
50
+ export { type AutoCaptureOptions, type EventPayload, type EventsBatchBody, type InitOptions, PishonIQ, PishonIQ as default };
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var chunkPDDJOQBE_js = require('./chunk-PDDJOQBE.js');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, "PishonIQ", {
10
+ enumerable: true,
11
+ get: function () { return chunkPDDJOQBE_js.PishonIQ; }
12
+ });
13
+ Object.defineProperty(exports, "default", {
14
+ enumerable: true,
15
+ get: function () { return chunkPDDJOQBE_js.index_default; }
16
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export { PishonIQ, index_default as default } from './chunk-S3CPHTEK.mjs';
@@ -0,0 +1,30 @@
1
+ import { AutoCaptureOptions, PishonIQ } from './index.mjs';
2
+ import { ReactNode } from 'react';
3
+
4
+ interface PishonIQProviderProps {
5
+ apiKey: string;
6
+ host: string;
7
+ debug?: boolean;
8
+ autoCapture?: AutoCaptureOptions;
9
+ sampleRate?: number;
10
+ children: ReactNode;
11
+ }
12
+ declare function PishonIQProvider({ apiKey, host, debug, autoCapture, sampleRate, children, }: PishonIQProviderProps): JSX.Element;
13
+ /**
14
+ * Returns `track`/`identify`/`page` bound to the PishonIQ singleton.
15
+ *
16
+ * Route-change page views are NOT fired from here — they don't need a
17
+ * router dependency at all. `PishonIQProvider` patches `history.pushState`/
18
+ * `replaceState` once (see `src/tracker.ts`), and since React Router (and
19
+ * any other router built on the History API) calls those same native
20
+ * methods internally, navigations are already captured automatically,
21
+ * with or without react-router-dom installed. Call `page()` from this hook
22
+ * yourself only if you want to pass a custom page name.
23
+ */
24
+ declare function usePishonIQ(): {
25
+ track: typeof PishonIQ.track;
26
+ identify: typeof PishonIQ.identify;
27
+ page: typeof PishonIQ.page;
28
+ };
29
+
30
+ export { PishonIQProvider, type PishonIQProviderProps, usePishonIQ };
@@ -0,0 +1,30 @@
1
+ import { AutoCaptureOptions, PishonIQ } from './index.js';
2
+ import { ReactNode } from 'react';
3
+
4
+ interface PishonIQProviderProps {
5
+ apiKey: string;
6
+ host: string;
7
+ debug?: boolean;
8
+ autoCapture?: AutoCaptureOptions;
9
+ sampleRate?: number;
10
+ children: ReactNode;
11
+ }
12
+ declare function PishonIQProvider({ apiKey, host, debug, autoCapture, sampleRate, children, }: PishonIQProviderProps): JSX.Element;
13
+ /**
14
+ * Returns `track`/`identify`/`page` bound to the PishonIQ singleton.
15
+ *
16
+ * Route-change page views are NOT fired from here — they don't need a
17
+ * router dependency at all. `PishonIQProvider` patches `history.pushState`/
18
+ * `replaceState` once (see `src/tracker.ts`), and since React Router (and
19
+ * any other router built on the History API) calls those same native
20
+ * methods internally, navigations are already captured automatically,
21
+ * with or without react-router-dom installed. Call `page()` from this hook
22
+ * yourself only if you want to pass a custom page name.
23
+ */
24
+ declare function usePishonIQ(): {
25
+ track: typeof PishonIQ.track;
26
+ identify: typeof PishonIQ.identify;
27
+ page: typeof PishonIQ.page;
28
+ };
29
+
30
+ export { PishonIQProvider, type PishonIQProviderProps, usePishonIQ };
package/dist/react.js ADDED
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ var chunkPDDJOQBE_js = require('./chunk-PDDJOQBE.js');
4
+ var react = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ function ensurePishonIQInit(apiKey, host, debug, autoCapture, sampleRate) {
8
+ if (typeof window === "undefined") return;
9
+ if (!chunkPDDJOQBE_js.index_default.isInitialized()) {
10
+ chunkPDDJOQBE_js.index_default.init({ apiKey, host, debug, autoCapture, sampleRate });
11
+ }
12
+ }
13
+ function PishonIQProvider({
14
+ apiKey,
15
+ host,
16
+ debug,
17
+ autoCapture,
18
+ sampleRate,
19
+ children
20
+ }) {
21
+ const lastConfig = react.useRef(null);
22
+ const configKey = JSON.stringify([apiKey, host, debug, autoCapture, sampleRate]);
23
+ react.useEffect(() => {
24
+ if (lastConfig.current !== null && lastConfig.current !== configKey && chunkPDDJOQBE_js.index_default.isInitialized()) {
25
+ console.warn(
26
+ "[PishonIQ] Provider props changed after init; PishonIQ is a singleton and keeps the first configuration."
27
+ );
28
+ }
29
+ lastConfig.current = configKey;
30
+ ensurePishonIQInit(apiKey, host, debug, autoCapture, sampleRate);
31
+ }, [configKey, apiKey, host, debug, autoCapture, sampleRate]);
32
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
33
+ }
34
+ function usePishonIQ() {
35
+ return react.useMemo(
36
+ () => ({
37
+ track: chunkPDDJOQBE_js.index_default.track.bind(chunkPDDJOQBE_js.index_default),
38
+ identify: chunkPDDJOQBE_js.index_default.identify.bind(chunkPDDJOQBE_js.index_default),
39
+ page: chunkPDDJOQBE_js.index_default.page.bind(chunkPDDJOQBE_js.index_default)
40
+ }),
41
+ []
42
+ );
43
+ }
44
+
45
+ exports.PishonIQProvider = PishonIQProvider;
46
+ exports.usePishonIQ = usePishonIQ;
package/dist/react.mjs ADDED
@@ -0,0 +1,43 @@
1
+ import { index_default } from './chunk-S3CPHTEK.mjs';
2
+ import { useRef, useEffect, useMemo } from 'react';
3
+ import { jsx, Fragment } from 'react/jsx-runtime';
4
+
5
+ function ensurePishonIQInit(apiKey, host, debug, autoCapture, sampleRate) {
6
+ if (typeof window === "undefined") return;
7
+ if (!index_default.isInitialized()) {
8
+ index_default.init({ apiKey, host, debug, autoCapture, sampleRate });
9
+ }
10
+ }
11
+ function PishonIQProvider({
12
+ apiKey,
13
+ host,
14
+ debug,
15
+ autoCapture,
16
+ sampleRate,
17
+ children
18
+ }) {
19
+ const lastConfig = useRef(null);
20
+ const configKey = JSON.stringify([apiKey, host, debug, autoCapture, sampleRate]);
21
+ useEffect(() => {
22
+ if (lastConfig.current !== null && lastConfig.current !== configKey && index_default.isInitialized()) {
23
+ console.warn(
24
+ "[PishonIQ] Provider props changed after init; PishonIQ is a singleton and keeps the first configuration."
25
+ );
26
+ }
27
+ lastConfig.current = configKey;
28
+ ensurePishonIQInit(apiKey, host, debug, autoCapture, sampleRate);
29
+ }, [configKey, apiKey, host, debug, autoCapture, sampleRate]);
30
+ return /* @__PURE__ */ jsx(Fragment, { children });
31
+ }
32
+ function usePishonIQ() {
33
+ return useMemo(
34
+ () => ({
35
+ track: index_default.track.bind(index_default),
36
+ identify: index_default.identify.bind(index_default),
37
+ page: index_default.page.bind(index_default)
38
+ }),
39
+ []
40
+ );
41
+ }
42
+
43
+ export { PishonIQProvider, usePishonIQ };
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "pishoniq-tracker",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.0",
4
+ "description": "PishonIQ analytics SDK for web applications",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./react": {
15
+ "types": "./dist/react.d.ts",
16
+ "import": "./dist/react.mjs",
17
+ "require": "./dist/react.js"
18
+ },
19
+ "./dist/browser.global.js": "./dist/browser.global.js",
20
+ "./package.json": "./package.json"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "CHANGELOG.md"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsup",
28
+ "dev": "tsup --watch",
29
+ "typecheck": "tsc --noEmit",
30
+ "test": "vitest run",
31
+ "test:watch": "vitest",
32
+ "prepublishOnly": "npm run typecheck && npm test && npm run build"
33
+ },
34
+ "keywords": [
35
+ "analytics",
36
+ "tracking",
37
+ "sdk",
38
+ "pishoniq",
39
+ "product-analytics"
40
+ ],
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/pishoniq/pishoniq-sdk.git"
44
+ },
45
+ "peerDependencies": {
46
+ "react": ">=18",
47
+ "react-dom": ">=18"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "react": {
51
+ "optional": true
52
+ },
53
+ "react-dom": {
54
+ "optional": true
55
+ }
56
+ },
57
+ "devDependencies": {
58
+ "@types/react": "^18.2.0",
59
+ "@types/react-dom": "^18.2.0",
60
+ "jsdom": "^24.0.0",
61
+ "tsup": "^8.0.0",
62
+ "typescript": "^5.4.0",
63
+ "vitest": "^2.1.0"
64
+ },
65
+ "license": "MIT"
66
+ }