@stacksee/analytics 0.5.0 → 0.7.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,47 @@
1
+ import { BaseEvent, EventContext } from '../../core/events/types.js';
2
+ import { BaseAnalyticsProvider } from '../base.provider.js';
3
+ interface BentoClient {
4
+ view(): void;
5
+ identify(email: string): void;
6
+ track(event: string, data?: Record<string, unknown>): void;
7
+ tag(tag: string): void;
8
+ updateFields(fields: Record<string, unknown>): void;
9
+ getEmail(): string | null;
10
+ getName(): string | null;
11
+ }
12
+ export interface BentoClientConfig {
13
+ /**
14
+ * Your Bento Site UUID from Account Settings
15
+ */
16
+ siteUuid: string;
17
+ /**
18
+ * Enable debug logging
19
+ */
20
+ debug?: boolean;
21
+ /**
22
+ * Enable/disable the provider
23
+ */
24
+ enabled?: boolean;
25
+ }
26
+ declare global {
27
+ interface Window {
28
+ bento?: BentoClient;
29
+ }
30
+ }
31
+ export declare class BentoClientProvider extends BaseAnalyticsProvider {
32
+ name: string;
33
+ private bento?;
34
+ private initialized;
35
+ private config;
36
+ private scriptLoaded;
37
+ constructor(config: BentoClientConfig);
38
+ initialize(): Promise<void>;
39
+ private loadBentoScript;
40
+ private waitForBento;
41
+ identify(userId: string, traits?: Record<string, unknown>): void;
42
+ track(event: BaseEvent, context?: EventContext): void;
43
+ pageView(properties?: Record<string, unknown>, context?: EventContext): void;
44
+ pageLeave(properties?: Record<string, unknown>, context?: EventContext): void;
45
+ reset(): void;
46
+ }
47
+ export {};
@@ -0,0 +1,58 @@
1
+ import { BaseEvent, EventContext } from '../../core/events/types.js';
2
+ import { BaseAnalyticsProvider } from '../base.provider.js';
3
+ export interface BentoAnalyticsOptions {
4
+ /**
5
+ * Your Bento Site UUID from Team Settings
6
+ */
7
+ siteUuid: string;
8
+ /**
9
+ * Authentication credentials
10
+ */
11
+ authentication: {
12
+ /**
13
+ * Your Bento Publishable Key from Team Settings
14
+ */
15
+ publishableKey: string;
16
+ /**
17
+ * Your Bento Secret Key from Team Settings
18
+ */
19
+ secretKey: string;
20
+ };
21
+ /**
22
+ * Optional client configuration
23
+ */
24
+ clientOptions?: {
25
+ /**
26
+ * Base URL for the Bento API (optional)
27
+ */
28
+ baseUrl?: string;
29
+ };
30
+ /**
31
+ * Whether to log errors (optional)
32
+ */
33
+ logErrors?: boolean;
34
+ }
35
+ export interface BentoServerConfig extends BentoAnalyticsOptions {
36
+ /**
37
+ * Enable debug logging
38
+ */
39
+ debug?: boolean;
40
+ /**
41
+ * Enable/disable the provider
42
+ */
43
+ enabled?: boolean;
44
+ }
45
+ export declare class BentoServerProvider extends BaseAnalyticsProvider {
46
+ name: string;
47
+ private client?;
48
+ private initialized;
49
+ private config;
50
+ private currentUserEmail?;
51
+ constructor(config: BentoServerConfig);
52
+ initialize(): Promise<void>;
53
+ identify(userId: string, traits?: Record<string, unknown>): void;
54
+ track(event: BaseEvent, context?: EventContext): Promise<void>;
55
+ pageView(properties?: Record<string, unknown>, context?: EventContext): void;
56
+ reset(): Promise<void>;
57
+ shutdown(): Promise<void>;
58
+ }
@@ -1,3 +1,7 @@
1
1
  export { BaseAnalyticsProvider } from './base.provider.js';
2
2
  export { PostHogClientProvider } from './posthog/client.js';
3
3
  export type { PostHogConfig } from 'posthog-js';
4
+ export { BentoClientProvider } from './bento/client.js';
5
+ export type { BentoClientConfig } from './bento/client.js';
6
+ export { PirschClientProvider } from './pirsch/client.js';
7
+ export type { PirschClientConfig } from './pirsch/client.js';
@@ -1,6 +1,233 @@
1
- import { B as e } from "../base.provider-AfFL5W_P.js";
2
- import { P as t } from "../client-DTHZYkxx.js";
1
+ var g = Object.defineProperty;
2
+ var p = (d, t, e) => t in d ? g(d, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : d[t] = e;
3
+ var a = (d, t, e) => p(d, typeof t != "symbol" ? t + "" : t, e);
4
+ import { B as h } from "../base.provider-AfFL5W_P.js";
5
+ import { i as l } from "../client-DTHZYkxx.js";
6
+ import { P as y } from "../client-DTHZYkxx.js";
7
+ class m extends h {
8
+ constructor(e) {
9
+ super({ debug: e.debug, enabled: e.enabled });
10
+ a(this, "name", "Bento-Client");
11
+ a(this, "bento");
12
+ a(this, "initialized", !1);
13
+ a(this, "config");
14
+ a(this, "scriptLoaded", !1);
15
+ this.config = e;
16
+ }
17
+ async initialize() {
18
+ if (this.isEnabled() && !this.initialized) {
19
+ if (!l()) {
20
+ this.log("Skipping initialization - not in browser environment");
21
+ return;
22
+ }
23
+ if (!this.config.siteUuid || typeof this.config.siteUuid != "string")
24
+ throw new Error("Bento requires a siteUuid");
25
+ try {
26
+ this.scriptLoaded || await this.loadBentoScript(), await this.waitForBento(), this.bento = window.bento, this.initialized = !0, this.log("Initialized successfully", this.config);
27
+ } catch (e) {
28
+ throw console.error("[Bento-Client] Failed to initialize:", e), e;
29
+ }
30
+ }
31
+ }
32
+ async loadBentoScript() {
33
+ return new Promise((e, i) => {
34
+ if (document.querySelector(
35
+ 'script[src*="bentonow.com"]'
36
+ )) {
37
+ this.scriptLoaded = !0, e();
38
+ return;
39
+ }
40
+ const r = document.createElement("script");
41
+ r.src = `https://cdn.bentonow.com/v1/${this.config.siteUuid}/bento.js`, r.async = !0, r.onload = () => {
42
+ this.scriptLoaded = !0, e();
43
+ }, r.onerror = () => {
44
+ i(new Error("Failed to load Bento script"));
45
+ }, document.head.appendChild(r);
46
+ });
47
+ }
48
+ async waitForBento(e = 50, i = 100) {
49
+ for (let s = 0; s < e; s++) {
50
+ if (window.bento)
51
+ return;
52
+ await new Promise((r) => setTimeout(r, i));
53
+ }
54
+ throw new Error("Bento SDK not available after loading script");
55
+ }
56
+ identify(e, i) {
57
+ if (!this.isEnabled() || !this.initialized || !this.bento) return;
58
+ const s = (i == null ? void 0 : i.email) || e;
59
+ if (this.bento.identify(s), i) {
60
+ const r = { ...i };
61
+ delete r.email, Object.keys(r).length > 0 && this.bento.updateFields(r);
62
+ }
63
+ this.log("Identified user", { userId: e, email: s, traits: i });
64
+ }
65
+ track(e, i) {
66
+ var r, n;
67
+ if (!this.isEnabled() || !this.initialized || !this.bento) return;
68
+ const s = {
69
+ ...e.properties,
70
+ category: e.category,
71
+ timestamp: e.timestamp || Date.now(),
72
+ ...e.userId && { userId: e.userId },
73
+ ...e.sessionId && { sessionId: e.sessionId },
74
+ ...(i == null ? void 0 : i.page) && {
75
+ page: {
76
+ path: i.page.path,
77
+ title: i.page.title,
78
+ referrer: i.page.referrer
79
+ }
80
+ },
81
+ ...(i == null ? void 0 : i.device) && { device: i.device },
82
+ ...(i == null ? void 0 : i.utm) && { utm: i.utm },
83
+ // Include user email and traits as regular event properties
84
+ ...((r = i == null ? void 0 : i.user) == null ? void 0 : r.email) && { user_email: i.user.email },
85
+ ...((n = i == null ? void 0 : i.user) == null ? void 0 : n.traits) && { user_traits: i.user.traits }
86
+ };
87
+ this.bento.track(e.action, s), this.log("Tracked event", { event: e, context: i });
88
+ }
89
+ pageView(e, i) {
90
+ if (!(!this.isEnabled() || !this.initialized || !this.bento || !l())) {
91
+ if (this.bento.view(), e || i != null && i.page) {
92
+ const s = {
93
+ ...e,
94
+ ...(i == null ? void 0 : i.page) && {
95
+ path: i.page.path,
96
+ title: i.page.title,
97
+ referrer: i.page.referrer
98
+ }
99
+ };
100
+ this.bento.track("$pageview", s);
101
+ }
102
+ this.log("Tracked page view", { properties: e, context: i });
103
+ }
104
+ }
105
+ pageLeave(e, i) {
106
+ if (!this.isEnabled() || !this.initialized || !this.bento || !l())
107
+ return;
108
+ const s = {
109
+ ...e,
110
+ ...(i == null ? void 0 : i.page) && {
111
+ path: i.page.path,
112
+ title: i.page.title,
113
+ referrer: i.page.referrer
114
+ }
115
+ };
116
+ this.bento.track("$pageleave", s), this.log("Tracked page leave", { properties: e, context: i });
117
+ }
118
+ reset() {
119
+ !this.isEnabled() || !this.initialized || !this.bento || !l() || this.log("Reset user session - Note: Bento doesn't have a native reset method");
120
+ }
121
+ }
122
+ class b extends h {
123
+ constructor(e) {
124
+ super({ debug: e.debug, enabled: e.enabled });
125
+ a(this, "name", "Pirsch-Client");
126
+ a(this, "client");
127
+ a(this, "initialized", !1);
128
+ a(this, "config");
129
+ this.config = e;
130
+ }
131
+ async initialize() {
132
+ if (this.isEnabled() && !this.initialized) {
133
+ if (!l()) {
134
+ this.log("Skipping initialization - not in browser environment");
135
+ return;
136
+ }
137
+ if (!this.config.identificationCode || typeof this.config.identificationCode != "string")
138
+ throw new Error("Pirsch requires an identificationCode");
139
+ try {
140
+ const { Pirsch: e } = await import("../web-CvEQewPd.js").then((i) => i.w);
141
+ this.client = new e({
142
+ identificationCode: this.config.identificationCode,
143
+ ...this.config.hostname && { hostname: this.config.hostname }
144
+ }), this.initialized = !0, this.log("Initialized successfully", this.config);
145
+ } catch (e) {
146
+ throw console.error(
147
+ "[Pirsch-Client] Failed to initialize. Make sure pirsch-sdk is installed:",
148
+ e
149
+ ), e;
150
+ }
151
+ }
152
+ }
153
+ identify(e, i) {
154
+ !this.isEnabled() || !this.initialized || !this.client || (this.client.event("user_identified", 0, {
155
+ userId: e,
156
+ ...i
157
+ }).catch((s) => {
158
+ console.error("[Pirsch-Client] Failed to track identify event:", s);
159
+ }), this.log("Identified user via event", { userId: e, traits: i }));
160
+ }
161
+ async track(e, i) {
162
+ var r, n;
163
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
164
+ const s = {
165
+ ...e.properties,
166
+ category: e.category,
167
+ ...e.userId && { userId: e.userId },
168
+ ...e.sessionId && { sessionId: e.sessionId },
169
+ ...(i == null ? void 0 : i.page) && {
170
+ page_path: i.page.path,
171
+ page_title: i.page.title,
172
+ page_referrer: i.page.referrer
173
+ },
174
+ ...(i == null ? void 0 : i.device) && { device: i.device },
175
+ ...(i == null ? void 0 : i.utm) && { utm: i.utm },
176
+ ...((r = i == null ? void 0 : i.user) == null ? void 0 : r.email) && { user_email: i.user.email },
177
+ ...((n = i == null ? void 0 : i.user) == null ? void 0 : n.traits) && { user_traits: i.user.traits }
178
+ };
179
+ try {
180
+ await this.client.event(e.action, 0, s), this.log("Tracked event", { event: e, context: i });
181
+ } catch (o) {
182
+ console.error("[Pirsch-Client] Failed to track event:", o);
183
+ }
184
+ }
185
+ pageView(e, i) {
186
+ if (!(!this.isEnabled() || !this.initialized || !this.client || !l())) {
187
+ if (this.client.hit().catch((s) => {
188
+ console.error("[Pirsch-Client] Failed to track page view:", s);
189
+ }), e && Object.keys(e).length > 0) {
190
+ const s = {
191
+ ...e,
192
+ ...(i == null ? void 0 : i.page) && {
193
+ path: i.page.path,
194
+ title: i.page.title,
195
+ referrer: i.page.referrer
196
+ }
197
+ };
198
+ this.client.event("page_view", 0, s).catch((r) => {
199
+ console.error(
200
+ "[Pirsch-Client] Failed to track page view event:",
201
+ r
202
+ );
203
+ });
204
+ }
205
+ this.log("Tracked page view", { properties: e, context: i });
206
+ }
207
+ }
208
+ pageLeave(e, i) {
209
+ if (!this.isEnabled() || !this.initialized || !this.client || !l())
210
+ return;
211
+ const s = {
212
+ ...e,
213
+ ...(i == null ? void 0 : i.page) && {
214
+ path: i.page.path,
215
+ title: i.page.title
216
+ }
217
+ };
218
+ this.client.event("page_leave", 0, s).catch((r) => {
219
+ console.error("[Pirsch-Client] Failed to track page leave:", r);
220
+ }), this.log("Tracked page leave", { properties: e, context: i });
221
+ }
222
+ reset() {
223
+ !this.isEnabled() || !this.initialized || !this.client || !l() || (this.client.event("session_reset", 0, {}).catch((e) => {
224
+ console.error("[Pirsch-Client] Failed to track session reset:", e);
225
+ }), this.log("Reset user session"));
226
+ }
227
+ }
3
228
  export {
4
- e as BaseAnalyticsProvider,
5
- t as PostHogClientProvider
229
+ h as BaseAnalyticsProvider,
230
+ m as BentoClientProvider,
231
+ b as PirschClientProvider,
232
+ y as PostHogClientProvider
6
233
  };
@@ -0,0 +1,34 @@
1
+ import { BaseEvent, EventContext } from '../../core/events/types.js';
2
+ import { BaseAnalyticsProvider } from '../base.provider.js';
3
+ export interface PirschClientConfig {
4
+ /**
5
+ * Your Pirsch identification code from the dashboard
6
+ * Found in: Settings > Integrations > JavaScript Snippet
7
+ */
8
+ identificationCode: string;
9
+ /**
10
+ * The hostname/domain being tracked (e.g., "example.com")
11
+ */
12
+ hostname?: string;
13
+ /**
14
+ * Enable debug logging
15
+ */
16
+ debug?: boolean;
17
+ /**
18
+ * Enable/disable the provider
19
+ */
20
+ enabled?: boolean;
21
+ }
22
+ export declare class PirschClientProvider extends BaseAnalyticsProvider {
23
+ name: string;
24
+ private client?;
25
+ private initialized;
26
+ private config;
27
+ constructor(config: PirschClientConfig);
28
+ initialize(): Promise<void>;
29
+ identify(userId: string, traits?: Record<string, unknown>): void;
30
+ track(event: BaseEvent, context?: EventContext): Promise<void>;
31
+ pageView(properties?: Record<string, unknown>, context?: EventContext): void;
32
+ pageLeave(properties?: Record<string, unknown>, context?: EventContext): void;
33
+ reset(): void;
34
+ }
@@ -0,0 +1,49 @@
1
+ import { BaseEvent, EventContext } from '../../core/events/types.js';
2
+ import { BaseAnalyticsProvider } from '../base.provider.js';
3
+ import { PirschProxyHeader, Protocol } from 'pirsch-sdk';
4
+ export interface PirschServerConfig {
5
+ /**
6
+ * The hostname/domain being tracked (required)
7
+ * Example: "example.com"
8
+ */
9
+ hostname: string;
10
+ /**
11
+ * Protocol to use (default: "https")
12
+ */
13
+ protocol?: Protocol;
14
+ /**
15
+ * Client ID for OAuth authentication
16
+ * Required if not using access key
17
+ */
18
+ clientId?: string;
19
+ /**
20
+ * Client secret or access key for authentication
21
+ * Access keys start with "pa_"
22
+ */
23
+ clientSecret: string;
24
+ /**
25
+ * Trusted proxy headers for IP extraction
26
+ */
27
+ trustedProxyHeaders?: PirschProxyHeader[];
28
+ /**
29
+ * Enable debug logging
30
+ */
31
+ debug?: boolean;
32
+ /**
33
+ * Enable/disable the provider
34
+ */
35
+ enabled?: boolean;
36
+ }
37
+ export declare class PirschServerProvider extends BaseAnalyticsProvider {
38
+ name: string;
39
+ private client?;
40
+ private initialized;
41
+ private config;
42
+ constructor(config: PirschServerConfig);
43
+ initialize(): Promise<void>;
44
+ identify(userId: string, traits?: Record<string, unknown>): void;
45
+ track(event: BaseEvent, context?: EventContext): Promise<void>;
46
+ pageView(properties?: Record<string, unknown>, context?: EventContext): void;
47
+ reset(): Promise<void>;
48
+ shutdown(): Promise<void>;
49
+ }
@@ -1,3 +1,7 @@
1
1
  export { BaseAnalyticsProvider } from './base.provider.js';
2
2
  export { PostHogServerProvider } from './posthog/server.js';
3
3
  export type { PostHogOptions } from 'posthog-node';
4
+ export { BentoServerProvider } from './bento/server.js';
5
+ export type { BentoServerConfig, BentoAnalyticsOptions } from './bento/server.js';
6
+ export { PirschServerProvider } from './pirsch/server.js';
7
+ export type { PirschServerConfig } from './pirsch/server.js';
@@ -1,6 +1,224 @@
1
- import { B as e } from "../base.provider-AfFL5W_P.js";
2
- import { P as a } from "../server-DjEk1fUD.js";
1
+ var g = Object.defineProperty;
2
+ var p = (o, h, e) => h in o ? g(o, h, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[h] = e;
3
+ var n = (o, h, e) => p(o, typeof h != "symbol" ? h + "" : h, e);
4
+ import { B as f } from "../base.provider-AfFL5W_P.js";
5
+ import { P as k } from "../server-DjEk1fUD.js";
6
+ class b extends f {
7
+ constructor(e) {
8
+ super({ debug: e.debug, enabled: e.enabled });
9
+ n(this, "name", "Bento-Server");
10
+ n(this, "client");
11
+ n(this, "initialized", !1);
12
+ n(this, "config");
13
+ n(this, "currentUserEmail");
14
+ this.config = e;
15
+ }
16
+ async initialize() {
17
+ var e, i;
18
+ if (this.isEnabled() && !this.initialized) {
19
+ if (!this.config.siteUuid || typeof this.config.siteUuid != "string")
20
+ throw new Error("Bento requires a siteUuid");
21
+ if (!((e = this.config.authentication) != null && e.publishableKey) || typeof this.config.authentication.publishableKey != "string")
22
+ throw new Error("Bento requires authentication.publishableKey");
23
+ if (!((i = this.config.authentication) != null && i.secretKey) || typeof this.config.authentication.secretKey != "string")
24
+ throw new Error("Bento requires authentication.secretKey");
25
+ try {
26
+ const { Analytics: r } = await import("../bento-node-sdk.esm-C4HG7SVz.js"), { debug: a, enabled: s, ...l } = this.config;
27
+ this.client = new r(l), this.initialized = !0, this.log("Initialized successfully", {
28
+ siteUuid: this.config.siteUuid
29
+ });
30
+ } catch (r) {
31
+ throw console.error(
32
+ "[Bento-Server] Failed to initialize. Make sure @bentonow/bento-node-sdk is installed:",
33
+ r
34
+ ), r;
35
+ }
36
+ }
37
+ }
38
+ identify(e, i) {
39
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
40
+ const r = (i == null ? void 0 : i.email) || e;
41
+ this.currentUserEmail = r;
42
+ const a = i ? { ...i } : {};
43
+ delete a.email, this.client.V1.addSubscriber({
44
+ email: r,
45
+ fields: a
46
+ }).catch((s) => {
47
+ console.error("[Bento-Server] Failed to identify user:", s);
48
+ }), this.log("Identified user", { userId: e, email: r, traits: i });
49
+ }
50
+ async track(e, i) {
51
+ var l, t, d;
52
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
53
+ const r = ((l = i == null ? void 0 : i.user) == null ? void 0 : l.email) || this.currentUserEmail || ((t = i == null ? void 0 : i.user) == null ? void 0 : t.userId) || e.userId || "anonymous@unknown.com", a = {
54
+ ...e.properties,
55
+ category: e.category,
56
+ timestamp: e.timestamp || Date.now(),
57
+ ...e.sessionId && { sessionId: e.sessionId },
58
+ ...(i == null ? void 0 : i.page) && {
59
+ page: {
60
+ path: i.page.path,
61
+ title: i.page.title,
62
+ referrer: i.page.referrer
63
+ }
64
+ },
65
+ ...(i == null ? void 0 : i.device) && { device: i.device },
66
+ ...(i == null ? void 0 : i.utm) && { utm: i.utm }
67
+ }, s = ((d = i == null ? void 0 : i.user) == null ? void 0 : d.traits) || {};
68
+ try {
69
+ await this.client.V1.track({
70
+ email: r,
71
+ type: `$${e.action}`,
72
+ details: a,
73
+ fields: s
74
+ }), this.log("Tracked event", { event: e, context: i });
75
+ } catch (c) {
76
+ console.error("[Bento-Server] Failed to track event:", c);
77
+ }
78
+ }
79
+ pageView(e, i) {
80
+ var l, t;
81
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
82
+ const r = ((l = i == null ? void 0 : i.user) == null ? void 0 : l.email) || this.currentUserEmail || "anonymous@unknown.com", a = {
83
+ ...e,
84
+ ...(i == null ? void 0 : i.page) && {
85
+ path: i.page.path,
86
+ title: i.page.title,
87
+ referrer: i.page.referrer
88
+ }
89
+ }, s = ((t = i == null ? void 0 : i.user) == null ? void 0 : t.traits) || {};
90
+ this.client.V1.track({
91
+ email: r,
92
+ type: "$pageview",
93
+ details: a,
94
+ fields: s
95
+ }).catch((d) => {
96
+ console.error("[Bento-Server] Failed to track page view:", d);
97
+ }), this.log("Tracked page view", { properties: e, context: i });
98
+ }
99
+ async reset() {
100
+ !this.isEnabled() || !this.initialized || !this.client || (this.currentUserEmail = void 0, this.log("Reset user session"));
101
+ }
102
+ async shutdown() {
103
+ this.client = void 0, this.initialized = !1, this.log("Shutdown complete");
104
+ }
105
+ }
106
+ class w extends f {
107
+ constructor(e) {
108
+ super({ debug: e.debug, enabled: e.enabled });
109
+ n(this, "name", "Pirsch-Server");
110
+ n(this, "client");
111
+ n(this, "initialized", !1);
112
+ n(this, "config");
113
+ this.config = e;
114
+ }
115
+ async initialize() {
116
+ if (this.isEnabled() && !this.initialized) {
117
+ if (!this.config.hostname || typeof this.config.hostname != "string")
118
+ throw new Error("Pirsch requires a hostname");
119
+ if (!this.config.clientSecret || typeof this.config.clientSecret != "string")
120
+ throw new Error("Pirsch requires a clientSecret (or access key)");
121
+ try {
122
+ const { Pirsch: e } = await import("../index-bgxxv-IJ.js").then((s) => s.i), { debug: i, enabled: r, ...a } = this.config;
123
+ this.client = new e(a), this.initialized = !0, this.log("Initialized successfully", {
124
+ hostname: this.config.hostname
125
+ });
126
+ } catch (e) {
127
+ throw console.error(
128
+ "[Pirsch-Server] Failed to initialize. Make sure pirsch-sdk is installed:",
129
+ e
130
+ ), e;
131
+ }
132
+ }
133
+ }
134
+ identify(e, i) {
135
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
136
+ const r = {
137
+ url: "https://identify",
138
+ ip: "0.0.0.0",
139
+ user_agent: "analytics-library"
140
+ }, a = {
141
+ userId: e,
142
+ ...i && Object.fromEntries(
143
+ Object.entries(i).filter(
144
+ ([, s]) => typeof s == "string" || typeof s == "number" || typeof s == "boolean"
145
+ )
146
+ )
147
+ };
148
+ this.client.event("user_identified", r, 0, a).catch((s) => {
149
+ console.error("[Pirsch-Server] Failed to track identify event:", s);
150
+ }), this.log("Identified user via event", { userId: e, traits: i });
151
+ }
152
+ async track(e, i) {
153
+ var l, t, d, c;
154
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
155
+ const r = {
156
+ url: ((l = i == null ? void 0 : i.page) == null ? void 0 : l.path) || "https://event",
157
+ ip: "0.0.0.0",
158
+ // Server-side should provide real IP if available
159
+ user_agent: "analytics-library",
160
+ // Server-side should provide real UA if available
161
+ ...((t = i == null ? void 0 : i.page) == null ? void 0 : t.title) && { title: i.page.title },
162
+ ...((d = i == null ? void 0 : i.page) == null ? void 0 : d.referrer) && { referrer: i.page.referrer }
163
+ }, s = {
164
+ ...Object.fromEntries(
165
+ Object.entries(e.properties).filter(
166
+ ([, u]) => typeof u == "string" || typeof u == "number" || typeof u == "boolean"
167
+ )
168
+ ),
169
+ category: e.category,
170
+ timestamp: String(e.timestamp || Date.now()),
171
+ ...e.userId && { userId: e.userId },
172
+ ...e.sessionId && { sessionId: e.sessionId },
173
+ ...((c = i == null ? void 0 : i.user) == null ? void 0 : c.email) && { user_email: i.user.email }
174
+ };
175
+ try {
176
+ await this.client.event(e.action, r, 0, s), this.log("Tracked event", { event: e, context: i });
177
+ } catch (u) {
178
+ console.error("[Pirsch-Server] Failed to track event:", u);
179
+ }
180
+ }
181
+ pageView(e, i) {
182
+ var a, s, l;
183
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
184
+ const r = {
185
+ url: ((a = i == null ? void 0 : i.page) == null ? void 0 : a.path) || "https://pageview",
186
+ ip: "0.0.0.0",
187
+ // Server-side should provide real IP if available
188
+ user_agent: "analytics-library",
189
+ // Server-side should provide real UA if available
190
+ ...((s = i == null ? void 0 : i.page) == null ? void 0 : s.title) && { title: i.page.title },
191
+ ...((l = i == null ? void 0 : i.page) == null ? void 0 : l.referrer) && { referrer: i.page.referrer },
192
+ ...e && {
193
+ tags: Object.fromEntries(
194
+ Object.entries(e).filter(
195
+ ([, t]) => typeof t == "string" || typeof t == "number" || typeof t == "boolean"
196
+ )
197
+ )
198
+ }
199
+ };
200
+ this.client.hit(r).catch((t) => {
201
+ console.error("[Pirsch-Server] Failed to track page view:", t);
202
+ }), this.log("Tracked page view", { properties: e, context: i });
203
+ }
204
+ async reset() {
205
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
206
+ const e = {
207
+ url: "https://session-reset",
208
+ ip: "0.0.0.0",
209
+ user_agent: "analytics-library"
210
+ };
211
+ await this.client.event("session_reset", e, 0, {}).catch((i) => {
212
+ console.error("[Pirsch-Server] Failed to track session reset:", i);
213
+ }), this.log("Reset user session");
214
+ }
215
+ async shutdown() {
216
+ this.client = void 0, this.initialized = !1, this.log("Shutdown complete");
217
+ }
218
+ }
3
219
  export {
4
- e as BaseAnalyticsProvider,
5
- a as PostHogServerProvider
220
+ f as BaseAnalyticsProvider,
221
+ b as BentoServerProvider,
222
+ w as PirschServerProvider,
223
+ k as PostHogServerProvider
6
224
  };