@stacksee/analytics 0.4.6 → 0.5.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.
@@ -1,86 +0,0 @@
1
- var h = Object.defineProperty;
2
- var p = (a, s, e) => s in a ? h(a, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[s] = e;
3
- var t = (a, s, e) => p(a, typeof s != "symbol" ? s + "" : s, e);
4
- import { B as d } from "./base.provider-AfFL5W_P.js";
5
- function o() {
6
- return typeof window < "u" && typeof window.document < "u";
7
- }
8
- class u extends d {
9
- constructor(e) {
10
- super({ debug: e.debug, enabled: e.enabled });
11
- t(this, "name", "PostHog-Client");
12
- t(this, "posthog");
13
- t(this, "initialized", !1);
14
- t(this, "config");
15
- this.config = e;
16
- }
17
- async initialize() {
18
- if (this.isEnabled() && !this.initialized) {
19
- if (!o()) {
20
- this.log("Skipping initialization - not in browser environment");
21
- return;
22
- }
23
- if (!this.config.token || typeof this.config.token != "string")
24
- throw new Error("PostHog requires a token");
25
- try {
26
- const { default: e } = await import("posthog-js"), { token: i, debug: r, ...g } = this.config;
27
- e.init(i, {
28
- ...g,
29
- debug: r ?? this.debug
30
- }), this.posthog = e, this.initialized = !0, this.log("Initialized successfully", this.config);
31
- } catch (e) {
32
- throw console.error("[PostHog-Client] Failed to initialize:", e), e;
33
- }
34
- }
35
- }
36
- identify(e, i) {
37
- !this.isEnabled() || !this.initialized || !this.posthog || (this.posthog.identify(e, i), this.log("Identified user", { userId: e, traits: i }));
38
- }
39
- track(e, i) {
40
- if (!this.isEnabled() || !this.initialized || !this.posthog) return;
41
- const r = {
42
- ...e.properties,
43
- category: e.category,
44
- timestamp: e.timestamp || Date.now(),
45
- ...e.userId && { userId: e.userId },
46
- ...e.sessionId && { sessionId: e.sessionId },
47
- ...(i == null ? void 0 : i.page) && { $current_url: i.page.path },
48
- ...(i == null ? void 0 : i.device) && { device: i.device },
49
- ...(i == null ? void 0 : i.utm) && { utm: i.utm }
50
- };
51
- this.posthog.capture(e.action, r), this.log("Tracked event", { event: e, context: i });
52
- }
53
- pageView(e, i) {
54
- if (!this.isEnabled() || !this.initialized || !this.posthog || !o())
55
- return;
56
- const r = {
57
- ...e,
58
- ...(i == null ? void 0 : i.page) && {
59
- path: i.page.path,
60
- title: i.page.title,
61
- referrer: i.page.referrer
62
- }
63
- };
64
- this.posthog.capture("$pageview", r), this.log("Tracked page view", { properties: e, context: i });
65
- }
66
- pageLeave(e, i) {
67
- if (!this.isEnabled() || !this.initialized || !this.posthog || !o())
68
- return;
69
- const r = {
70
- ...e,
71
- ...(i == null ? void 0 : i.page) && {
72
- path: i.page.path,
73
- title: i.page.title,
74
- referrer: i.page.referrer
75
- }
76
- };
77
- this.posthog.capture("$pageleave", r), this.log("Tracked page leave", { properties: e, context: i });
78
- }
79
- reset() {
80
- !this.isEnabled() || !this.initialized || !this.posthog || !o() || (this.posthog.reset(), this.log("Reset user session"));
81
- }
82
- }
83
- export {
84
- u as P,
85
- o as i
86
- };
@@ -1,84 +0,0 @@
1
- var l = Object.defineProperty;
2
- var h = (r, s, i) => s in r ? l(r, s, { enumerable: !0, configurable: !0, writable: !0, value: i }) : r[s] = i;
3
- var t = (r, s, i) => h(r, typeof s != "symbol" ? s + "" : s, i);
4
- import { B as n } from "./base.provider-AfFL5W_P.js";
5
- import { PostHog as p } from "posthog-node";
6
- class u extends n {
7
- constructor(i) {
8
- super({ debug: i.debug, enabled: i.enabled });
9
- t(this, "name", "PostHog-Server");
10
- t(this, "client");
11
- t(this, "initialized", !1);
12
- t(this, "config");
13
- this.config = i;
14
- }
15
- initialize() {
16
- if (this.isEnabled() && !this.initialized) {
17
- if (!this.config.apiKey || typeof this.config.apiKey != "string")
18
- throw new Error("PostHog requires an apiKey");
19
- try {
20
- const { apiKey: i, ...e } = this.config;
21
- this.client = new p(i, {
22
- host: "https://app.posthog.com",
23
- flushAt: 20,
24
- flushInterval: 1e4,
25
- ...e
26
- }), this.initialized = !0, this.log("Initialized successfully", this.config);
27
- } catch (i) {
28
- throw console.error("[PostHog-Server] Failed to initialize:", i), i;
29
- }
30
- }
31
- }
32
- identify(i, e) {
33
- !this.isEnabled() || !this.initialized || !this.client || (this.client.identify({
34
- distinctId: i,
35
- properties: e
36
- }), this.log("Identified user", { userId: i, traits: e }));
37
- }
38
- track(i, e) {
39
- if (!this.isEnabled() || !this.initialized || !this.client) return;
40
- const a = {
41
- ...i.properties,
42
- category: i.category,
43
- timestamp: i.timestamp ? new Date(i.timestamp) : /* @__PURE__ */ new Date(),
44
- ...i.sessionId && { sessionId: i.sessionId },
45
- ...(e == null ? void 0 : e.page) && {
46
- $current_url: e.page.path,
47
- $page_title: e.page.title,
48
- $referrer: e.page.referrer
49
- },
50
- ...(e == null ? void 0 : e.device) && { device: e.device },
51
- ...(e == null ? void 0 : e.utm) && { utm: e.utm }
52
- };
53
- this.client.capture({
54
- distinctId: i.userId || "anonymous",
55
- event: i.action,
56
- properties: a
57
- }), this.log("Tracked event", { event: i, context: e });
58
- }
59
- pageView(i, e) {
60
- if (!this.isEnabled() || !this.initialized || !this.client) return;
61
- const a = {
62
- ...i,
63
- ...(e == null ? void 0 : e.page) && {
64
- path: e.page.path,
65
- title: e.page.title,
66
- referrer: e.page.referrer
67
- }
68
- };
69
- this.client.capture({
70
- distinctId: "anonymous",
71
- event: "$pageview",
72
- properties: a
73
- }), this.log("Tracked page view", { properties: i, context: e });
74
- }
75
- async reset() {
76
- !this.isEnabled() || !this.initialized || !this.client || (await this.client.flush(), this.log("Flushed pending events"));
77
- }
78
- async shutdown() {
79
- this.client && (await this.client.shutdown(), this.log("Shutdown complete"));
80
- }
81
- }
82
- export {
83
- u as P
84
- };