@stacksee/analytics 0.2.2 → 0.3.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.
@@ -1,25 +1,25 @@
1
1
  var c = Object.defineProperty;
2
- var h = (t, i, e) => i in t ? c(t, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[i] = e;
3
- var s = (t, i, e) => h(t, typeof i != "symbol" ? i + "" : i, e);
4
- class u {
5
- constructor(i) {
2
+ var u = (t, e, i) => e in t ? c(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
3
+ var s = (t, e, i) => u(t, typeof e != "symbol" ? e + "" : e, i);
4
+ class h {
5
+ constructor(e) {
6
6
  s(this, "providers", []);
7
7
  s(this, "context", {});
8
8
  s(this, "userId");
9
9
  s(this, "sessionId");
10
10
  s(this, "initialized", !1);
11
11
  s(this, "initializePromise");
12
- this.providers = i.providers, i.defaultContext && (this.context = { ...i.defaultContext }), this.sessionId = this.generateSessionId();
12
+ this.providers = e.providers, e.defaultContext && (this.context = { ...e.defaultContext }), this.sessionId = this.generateSessionId();
13
13
  }
14
14
  async initialize() {
15
15
  if (!this.initialized)
16
16
  return this.initializePromise ? this.initializePromise : (this.initializePromise = this._doInitialize(), this.initializePromise);
17
17
  }
18
18
  async _doInitialize() {
19
- const i = this.providers.map(
20
- (e) => e.initialize()
19
+ const e = this.providers.map(
20
+ (i) => i.initialize()
21
21
  );
22
- await Promise.all(i), this.initialized = !0, this.updateContext({
22
+ await Promise.all(e), this.initialized = !0, this.updateContext({
23
23
  page: {
24
24
  path: window.location.pathname,
25
25
  title: document.title,
@@ -35,19 +35,19 @@ class u {
35
35
  async ensureInitialized() {
36
36
  !this.initialized && !this.initializePromise ? await this.initialize() : this.initializePromise && await this.initializePromise;
37
37
  }
38
- identify(i, e) {
39
- this.userId = i, this.ensureInitialized().catch((r) => {
38
+ identify(e, i) {
39
+ this.userId = e, this.ensureInitialized().catch((r) => {
40
40
  console.error("[Analytics] Failed to initialize during identify:", r);
41
41
  });
42
42
  for (const r of this.providers)
43
- r.identify(i, e);
43
+ r.identify(e, i);
44
44
  }
45
- async track(i, e) {
45
+ async track(e, i) {
46
46
  await this.ensureInitialized();
47
47
  const r = {
48
- action: i,
49
- category: this.getCategoryFromEventName(i),
50
- properties: e,
48
+ action: e,
49
+ category: this.getCategoryFromEventName(e),
50
+ properties: i,
51
51
  timestamp: Date.now(),
52
52
  userId: this.userId,
53
53
  sessionId: this.sessionId
@@ -63,9 +63,9 @@ class u {
63
63
  });
64
64
  await Promise.all(a);
65
65
  }
66
- page(i) {
67
- this.ensureInitialized().catch((e) => {
68
- console.error("[Analytics] Failed to initialize during page:", e);
66
+ page(e) {
67
+ this.ensureInitialized().catch((i) => {
68
+ console.error("[Analytics] Failed to initialize during page:", i);
69
69
  }), this.updateContext({
70
70
  page: {
71
71
  path: window.location.pathname,
@@ -73,67 +73,69 @@ class u {
73
73
  referrer: document.referrer
74
74
  }
75
75
  });
76
- for (const e of this.providers)
77
- e.page(i, this.context);
76
+ for (const i of this.providers)
77
+ i.page(e, this.context);
78
78
  }
79
79
  reset() {
80
80
  this.userId = void 0, this.sessionId = this.generateSessionId();
81
- for (const i of this.providers)
82
- i.reset();
81
+ for (const e of this.providers)
82
+ e.reset();
83
83
  }
84
- updateContext(i) {
85
- var e, r, a;
84
+ updateContext(e) {
85
+ var i, r, a;
86
86
  this.context = {
87
87
  ...this.context,
88
- ...i,
89
- page: i.page ? {
90
- path: i.page.path || ((e = this.context.page) == null ? void 0 : e.path) || window.location.pathname,
91
- title: i.page.title || ((r = this.context.page) == null ? void 0 : r.title),
92
- referrer: i.page.referrer || ((a = this.context.page) == null ? void 0 : a.referrer)
88
+ ...e,
89
+ page: e.page ? {
90
+ path: e.page.path || ((i = this.context.page) == null ? void 0 : i.path) || window.location.pathname,
91
+ title: e.page.title || ((r = this.context.page) == null ? void 0 : r.title),
92
+ referrer: e.page.referrer || ((a = this.context.page) == null ? void 0 : a.referrer)
93
93
  } : this.context.page,
94
94
  device: {
95
95
  ...this.context.device,
96
- ...i.device
96
+ ...e.device
97
97
  },
98
- campaign: {
99
- ...this.context.campaign,
100
- ...i.campaign
98
+ utm: {
99
+ ...this.context.utm,
100
+ ...e.utm
101
101
  }
102
102
  };
103
103
  }
104
- getCategoryFromEventName(i) {
105
- const e = i.split("_");
106
- return e.length > 1 && e[0] ? e[0] : "engagement";
104
+ getCategoryFromEventName(e) {
105
+ const i = e.split("_");
106
+ return i.length > 1 && i[0] ? i[0] : "engagement";
107
107
  }
108
108
  generateSessionId() {
109
109
  return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
110
110
  }
111
111
  getDeviceType() {
112
- const i = navigator.userAgent;
113
- return /tablet|ipad|playbook|silk/i.test(i) ? "tablet" : /mobile|iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(
114
- i
112
+ const e = navigator.userAgent;
113
+ return /tablet|ipad|playbook|silk/i.test(e) ? "tablet" : /mobile|iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(
114
+ e
115
115
  ) ? "mobile" : "desktop";
116
116
  }
117
117
  getOS() {
118
- const i = navigator.userAgent;
119
- return i.indexOf("Win") !== -1 ? "Windows" : i.indexOf("Mac") !== -1 ? "macOS" : i.indexOf("Linux") !== -1 ? "Linux" : i.indexOf("Android") !== -1 ? "Android" : i.indexOf("iOS") !== -1 ? "iOS" : "Unknown";
118
+ const e = navigator.userAgent;
119
+ return e.indexOf("Win") !== -1 ? "Windows" : e.indexOf("Mac") !== -1 ? "macOS" : e.indexOf("Linux") !== -1 ? "Linux" : e.indexOf("Android") !== -1 ? "Android" : e.indexOf("iOS") !== -1 ? "iOS" : "Unknown";
120
120
  }
121
121
  getBrowser() {
122
- const i = navigator.userAgent;
123
- return i.indexOf("Chrome") !== -1 ? "Chrome" : i.indexOf("Safari") !== -1 ? "Safari" : i.indexOf("Firefox") !== -1 ? "Firefox" : i.indexOf("Edge") !== -1 ? "Edge" : "Unknown";
122
+ const e = navigator.userAgent;
123
+ return e.indexOf("Chrome") !== -1 ? "Chrome" : e.indexOf("Safari") !== -1 ? "Safari" : e.indexOf("Firefox") !== -1 ? "Firefox" : e.indexOf("Edge") !== -1 ? "Edge" : "Unknown";
124
124
  }
125
125
  }
126
126
  let n = null;
127
- function f(t) {
127
+ function p(t) {
128
128
  if (n)
129
129
  return console.warn("[Analytics] Already initialized"), n;
130
- const i = {
130
+ const e = {
131
131
  providers: t.providers || [],
132
132
  debug: t.debug,
133
133
  enabled: t.enabled
134
134
  };
135
- return n = new u(i), n.initialize().catch((e) => {
136
- console.error("[Analytics] Failed to initialize:", e);
135
+ return n = new h(
136
+ e
137
+ ), n.initialize().catch((i) => {
138
+ console.error("[Analytics] Failed to initialize:", i);
137
139
  }), n;
138
140
  }
139
141
  function o() {
@@ -143,11 +145,11 @@ function o() {
143
145
  );
144
146
  return n;
145
147
  }
146
- function g(t, i) {
147
- return o().track(t, i);
148
+ function g(t, e) {
149
+ return o().track(t, e);
148
150
  }
149
- function m(t, i) {
150
- o().identify(t, i);
151
+ function m(t, e) {
152
+ o().identify(t, e);
151
153
  }
152
154
  function y(t) {
153
155
  o().page(t);
@@ -159,9 +161,9 @@ function z() {
159
161
  n = null;
160
162
  }
161
163
  export {
162
- u as B,
164
+ h as B,
163
165
  z as a,
164
- f as c,
166
+ p as c,
165
167
  o as g,
166
168
  m as i,
167
169
  y as p,
package/dist/client.js CHANGED
@@ -1,4 +1,4 @@
1
- import { c as t, c as e, g as c, i, p as n, r, a as l, t as y } from "./client-DIOWX7_9.js";
1
+ import { c as t, c as e, g as c, i, p as n, r, a as l, t as y } from "./client-yfDfetWt.js";
2
2
  export {
3
3
  t as createAnalytics,
4
4
  e as createClientAnalytics,