@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.
- package/dist/{client-DIOWX7_9.js → client-yfDfetWt.js} +55 -53
- package/dist/client.js +1 -1
- package/dist/index.js +15 -2620
- package/dist/providers.d.ts +2 -0
- package/dist/providers.js +2611 -0
- package/dist/server.js +3 -1
- package/dist/src/adapters/client/browser-analytics.d.ts +4 -3
- package/dist/src/adapters/server/server-analytics.d.ts +4 -3
- package/dist/src/client.d.ts +19 -5
- package/dist/src/core/events/types.d.ts +1 -1
- package/dist/src/server.d.ts +18 -2
- package/package.json +5 -1
- package/readme.md +94 -94
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
var c = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var s = (t,
|
|
4
|
-
class
|
|
5
|
-
constructor(
|
|
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 =
|
|
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
|
|
20
|
-
(
|
|
19
|
+
const e = this.providers.map(
|
|
20
|
+
(i) => i.initialize()
|
|
21
21
|
);
|
|
22
|
-
await Promise.all(
|
|
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(
|
|
39
|
-
this.userId =
|
|
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(
|
|
43
|
+
r.identify(e, i);
|
|
44
44
|
}
|
|
45
|
-
async track(
|
|
45
|
+
async track(e, i) {
|
|
46
46
|
await this.ensureInitialized();
|
|
47
47
|
const r = {
|
|
48
|
-
action:
|
|
49
|
-
category: this.getCategoryFromEventName(
|
|
50
|
-
properties:
|
|
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(
|
|
67
|
-
this.ensureInitialized().catch((
|
|
68
|
-
console.error("[Analytics] Failed to initialize during page:",
|
|
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
|
|
77
|
-
|
|
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
|
|
82
|
-
|
|
81
|
+
for (const e of this.providers)
|
|
82
|
+
e.reset();
|
|
83
83
|
}
|
|
84
|
-
updateContext(
|
|
85
|
-
var
|
|
84
|
+
updateContext(e) {
|
|
85
|
+
var i, r, a;
|
|
86
86
|
this.context = {
|
|
87
87
|
...this.context,
|
|
88
|
-
...
|
|
89
|
-
page:
|
|
90
|
-
path:
|
|
91
|
-
title:
|
|
92
|
-
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
|
-
...
|
|
96
|
+
...e.device
|
|
97
97
|
},
|
|
98
|
-
|
|
99
|
-
...this.context.
|
|
100
|
-
...
|
|
98
|
+
utm: {
|
|
99
|
+
...this.context.utm,
|
|
100
|
+
...e.utm
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
-
getCategoryFromEventName(
|
|
105
|
-
const
|
|
106
|
-
return
|
|
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
|
|
113
|
-
return /tablet|ipad|playbook|silk/i.test(
|
|
114
|
-
|
|
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
|
|
119
|
-
return
|
|
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
|
|
123
|
-
return
|
|
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
|
|
127
|
+
function p(t) {
|
|
128
128
|
if (n)
|
|
129
129
|
return console.warn("[Analytics] Already initialized"), n;
|
|
130
|
-
const
|
|
130
|
+
const e = {
|
|
131
131
|
providers: t.providers || [],
|
|
132
132
|
debug: t.debug,
|
|
133
133
|
enabled: t.enabled
|
|
134
134
|
};
|
|
135
|
-
return n = new
|
|
136
|
-
|
|
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,
|
|
147
|
-
return o().track(t,
|
|
148
|
+
function g(t, e) {
|
|
149
|
+
return o().track(t, e);
|
|
148
150
|
}
|
|
149
|
-
function m(t,
|
|
150
|
-
o().identify(t,
|
|
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
|
-
|
|
164
|
+
h as B,
|
|
163
165
|
z as a,
|
|
164
|
-
|
|
166
|
+
p as c,
|
|
165
167
|
o as g,
|
|
166
168
|
m as i,
|
|
167
169
|
y as p,
|
package/dist/client.js
CHANGED