posthog-js-lite 4.11.0 → 4.12.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.
- package/dist/index.cjs +279 -361
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +26 -24
- package/dist/index.mjs +274 -356
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -12
- package/src/context.ts +4 -1
- package/src/version.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,381 +1,299 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const version = "4.
|
|
8
|
-
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
let _posthog_core = require("@posthog/core");
|
|
6
|
+
//#region src/version.ts
|
|
7
|
+
const version = "4.12.0";
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/context.ts
|
|
9
10
|
function getContext(window, disableCaptureUrlHashes = false) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
11
|
+
let context = {};
|
|
12
|
+
if (window?.navigator) {
|
|
13
|
+
const userAgent = window.navigator.userAgent;
|
|
14
|
+
const osValue = os(window);
|
|
15
|
+
const [webviewApp, webviewAppVersion] = (0, _posthog_core.detectWebviewApp)(userAgent);
|
|
16
|
+
context = {
|
|
17
|
+
...context,
|
|
18
|
+
...osValue !== void 0 && { $os: osValue },
|
|
19
|
+
$browser: (0, _posthog_core.detectBrowser)(userAgent, window.navigator.vendor),
|
|
20
|
+
...webviewApp && { $webview_app: webviewApp },
|
|
21
|
+
...webviewAppVersion && { $webview_app_version: webviewAppVersion },
|
|
22
|
+
$referrer: window.document.referrer,
|
|
23
|
+
$referring_domain: referringDomain(window.document.referrer),
|
|
24
|
+
$device: device(userAgent),
|
|
25
|
+
$current_url: disableCaptureUrlHashes ? (0, _posthog_core.stripUrlHash)(window.location.href) : window.location.href,
|
|
26
|
+
$host: window.location.host,
|
|
27
|
+
$pathname: window.location.pathname,
|
|
28
|
+
$browser_version: (0, _posthog_core.detectBrowserVersion)(userAgent, window.navigator.vendor),
|
|
29
|
+
$screen_height: window.screen.height,
|
|
30
|
+
$screen_width: window.screen.width,
|
|
31
|
+
$screen_dpr: window.devicePixelRatio
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
context = {
|
|
35
|
+
...context,
|
|
36
|
+
$lib: "js",
|
|
37
|
+
$lib_version: version,
|
|
38
|
+
$insert_id: Math.random().toString(36).substring(2, 10) + Math.random().toString(36).substring(2, 10),
|
|
39
|
+
$time: (0, _posthog_core.currentTimestamp)() / 1e3
|
|
40
|
+
};
|
|
41
|
+
return context;
|
|
40
42
|
}
|
|
41
43
|
function os(window) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return 'Android';
|
|
55
|
-
} else if (/(BlackBerry|PlayBook|BB10)/i.test(a)) {
|
|
56
|
-
return 'BlackBerry';
|
|
57
|
-
} else if (/Mac/i.test(a)) {
|
|
58
|
-
return 'Mac OS X';
|
|
59
|
-
} else if (/Linux/.test(a)) {
|
|
60
|
-
return 'Linux';
|
|
61
|
-
} else if (/CrOS/.test(a)) {
|
|
62
|
-
return 'Chrome OS';
|
|
63
|
-
} else {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
44
|
+
if (!window?.navigator) return;
|
|
45
|
+
const a = window.navigator.userAgent;
|
|
46
|
+
if (/Windows/i.test(a)) {
|
|
47
|
+
if (/Phone/.test(a) || /WPDesktop/.test(a)) return "Windows Phone";
|
|
48
|
+
return "Windows";
|
|
49
|
+
} else if (/(iPhone|iPad|iPod)/.test(a)) return "iOS";
|
|
50
|
+
else if (/Android/.test(a)) return "Android";
|
|
51
|
+
else if (/(BlackBerry|PlayBook|BB10)/i.test(a)) return "BlackBerry";
|
|
52
|
+
else if (/Mac/i.test(a)) return "Mac OS X";
|
|
53
|
+
else if (/Linux/.test(a)) return "Linux";
|
|
54
|
+
else if (/CrOS/.test(a)) return "Chrome OS";
|
|
55
|
+
else return;
|
|
66
56
|
}
|
|
67
57
|
function device(userAgent) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return 'iPhone';
|
|
76
|
-
} else if (/(BlackBerry|PlayBook|BB10)/i.test(userAgent)) {
|
|
77
|
-
return 'BlackBerry';
|
|
78
|
-
} else if (/Android/.test(userAgent)) {
|
|
79
|
-
return 'Android';
|
|
80
|
-
} else {
|
|
81
|
-
return '';
|
|
82
|
-
}
|
|
58
|
+
if (/Windows Phone/i.test(userAgent) || /WPDesktop/.test(userAgent)) return "Windows Phone";
|
|
59
|
+
else if (/iPad/.test(userAgent)) return "iPad";
|
|
60
|
+
else if (/iPod/.test(userAgent)) return "iPod Touch";
|
|
61
|
+
else if (/iPhone/.test(userAgent)) return "iPhone";
|
|
62
|
+
else if (/(BlackBerry|PlayBook|BB10)/i.test(userAgent)) return "BlackBerry";
|
|
63
|
+
else if (/Android/.test(userAgent)) return "Android";
|
|
64
|
+
else return "";
|
|
83
65
|
}
|
|
84
66
|
function referringDomain(referrer) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
return '';
|
|
67
|
+
const split = referrer.split("/");
|
|
68
|
+
if (split.length >= 3) return split[2];
|
|
69
|
+
return "";
|
|
90
70
|
}
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/storage.ts
|
|
93
73
|
const cookieStore = {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
for (let i = 0; i < ca.length; i++) {
|
|
135
|
-
let c = ca[i];
|
|
136
|
-
while (c.charAt(0) == ' ') {
|
|
137
|
-
c = c.substring(1, c.length);
|
|
138
|
-
}
|
|
139
|
-
keys.push(c.split('=')[0]);
|
|
140
|
-
}
|
|
141
|
-
return keys;
|
|
142
|
-
}
|
|
74
|
+
getItem(key) {
|
|
75
|
+
try {
|
|
76
|
+
const nameEQ = key + "=";
|
|
77
|
+
const ca = document.cookie.split(";");
|
|
78
|
+
for (let i = 0; i < ca.length; i++) {
|
|
79
|
+
let c = ca[i];
|
|
80
|
+
while (c.charAt(0) == " ") c = c.substring(1, c.length);
|
|
81
|
+
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {}
|
|
84
|
+
return null;
|
|
85
|
+
},
|
|
86
|
+
setItem(key, value) {
|
|
87
|
+
try {
|
|
88
|
+
const new_cookie_val = key + "=" + encodeURIComponent(value) + "; path=/";
|
|
89
|
+
document.cookie = new_cookie_val;
|
|
90
|
+
} catch (err) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
removeItem(name) {
|
|
95
|
+
try {
|
|
96
|
+
cookieStore.setItem(name, "");
|
|
97
|
+
} catch (err) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
clear() {
|
|
102
|
+
document.cookie = "";
|
|
103
|
+
},
|
|
104
|
+
getAllKeys() {
|
|
105
|
+
const ca = document.cookie.split(";");
|
|
106
|
+
const keys = [];
|
|
107
|
+
for (let i = 0; i < ca.length; i++) {
|
|
108
|
+
let c = ca[i];
|
|
109
|
+
while (c.charAt(0) == " ") c = c.substring(1, c.length);
|
|
110
|
+
keys.push(c.split("=")[0]);
|
|
111
|
+
}
|
|
112
|
+
return keys;
|
|
113
|
+
}
|
|
143
114
|
};
|
|
144
|
-
const createStorageLike = store => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
};
|
|
115
|
+
const createStorageLike = (store) => {
|
|
116
|
+
return {
|
|
117
|
+
getItem(key) {
|
|
118
|
+
return store.getItem(key);
|
|
119
|
+
},
|
|
120
|
+
setItem(key, value) {
|
|
121
|
+
store.setItem(key, value);
|
|
122
|
+
},
|
|
123
|
+
removeItem(key) {
|
|
124
|
+
store.removeItem(key);
|
|
125
|
+
},
|
|
126
|
+
clear() {
|
|
127
|
+
store.clear();
|
|
128
|
+
},
|
|
129
|
+
getAllKeys() {
|
|
130
|
+
const keys = [];
|
|
131
|
+
for (const key in localStorage) keys.push(key);
|
|
132
|
+
return keys;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
166
135
|
};
|
|
167
|
-
const checkStoreIsSupported = (storage, key =
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
136
|
+
const checkStoreIsSupported = (storage, key = "__mplssupport__") => {
|
|
137
|
+
try {
|
|
138
|
+
const val = "xyz";
|
|
139
|
+
storage.setItem(key, val);
|
|
140
|
+
if (storage.getItem(key) !== val) return false;
|
|
141
|
+
storage.removeItem(key);
|
|
142
|
+
return true;
|
|
143
|
+
} catch (err) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
179
146
|
};
|
|
180
|
-
let localStore =
|
|
181
|
-
let sessionStore =
|
|
147
|
+
let localStore = void 0;
|
|
148
|
+
let sessionStore = void 0;
|
|
182
149
|
const createMemoryStorage = () => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
return keys;
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
return store;
|
|
150
|
+
const _cache = {};
|
|
151
|
+
return {
|
|
152
|
+
getItem(key) {
|
|
153
|
+
return _cache[key];
|
|
154
|
+
},
|
|
155
|
+
setItem(key, value) {
|
|
156
|
+
_cache[key] = value !== null ? value : void 0;
|
|
157
|
+
},
|
|
158
|
+
removeItem(key) {
|
|
159
|
+
delete _cache[key];
|
|
160
|
+
},
|
|
161
|
+
clear() {
|
|
162
|
+
for (const key in _cache) delete _cache[key];
|
|
163
|
+
},
|
|
164
|
+
getAllKeys() {
|
|
165
|
+
const keys = [];
|
|
166
|
+
for (const key in _cache) keys.push(key);
|
|
167
|
+
return keys;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
208
170
|
};
|
|
209
171
|
const getStorage = (type, window) => {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
case 'memory':
|
|
228
|
-
return createMemoryStorage();
|
|
229
|
-
default:
|
|
230
|
-
return createMemoryStorage();
|
|
231
|
-
}
|
|
172
|
+
if (window) {
|
|
173
|
+
if (!localStore) {
|
|
174
|
+
const _localStore = createStorageLike(window.localStorage);
|
|
175
|
+
localStore = checkStoreIsSupported(_localStore) ? _localStore : void 0;
|
|
176
|
+
}
|
|
177
|
+
if (!sessionStore) {
|
|
178
|
+
const _sessionStore = createStorageLike(window.sessionStorage);
|
|
179
|
+
sessionStore = checkStoreIsSupported(_sessionStore) ? _sessionStore : void 0;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
switch (type) {
|
|
183
|
+
case "cookie": return cookieStore || localStore || sessionStore || createMemoryStorage();
|
|
184
|
+
case "localStorage": return localStore || sessionStore || createMemoryStorage();
|
|
185
|
+
case "sessionStorage": return sessionStore || createMemoryStorage();
|
|
186
|
+
case "memory": return createMemoryStorage();
|
|
187
|
+
default: return createMemoryStorage();
|
|
188
|
+
}
|
|
232
189
|
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
// import { patch } from 'rrweb/typings/utils'
|
|
238
|
-
// copied from: https://github.com/PostHog/posthog-js/blob/main/src/extensions/replay/rrweb-plugins/patch.ts
|
|
239
|
-
// which was copied from https://github.com/rrweb-io/rrweb/blob/8aea5b00a4dfe5a6f59bd2ae72bb624f45e51e81/packages/rrweb/src/utils.ts#L129
|
|
240
|
-
// copied from: https://github.com/PostHog/posthog-js/blob/main/react/src/utils/type-utils.ts#L4
|
|
241
|
-
const isFunction = function (f) {
|
|
242
|
-
return typeof f === 'function';
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/patch.ts
|
|
192
|
+
const isFunction = function(f) {
|
|
193
|
+
return typeof f === "function";
|
|
243
194
|
};
|
|
244
195
|
function patch(source, name, replacement) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
source[name] = wrapped;
|
|
265
|
-
return () => {
|
|
266
|
-
source[name] = original;
|
|
267
|
-
};
|
|
268
|
-
} catch {
|
|
269
|
-
return () => {
|
|
270
|
-
//
|
|
271
|
-
};
|
|
272
|
-
// This can throw when multiple instrumentation layers try to wrap the same global object,
|
|
273
|
-
// such as XMLHttpRequest, and redefine the same non-configurable wrapper marker.
|
|
274
|
-
}
|
|
196
|
+
try {
|
|
197
|
+
if (!(name in source)) return () => {};
|
|
198
|
+
const original = source[name];
|
|
199
|
+
const wrapped = replacement(original);
|
|
200
|
+
if (isFunction(wrapped)) {
|
|
201
|
+
wrapped.prototype = wrapped.prototype || {};
|
|
202
|
+
Object.defineProperties(wrapped, { __posthog_wrapped__: {
|
|
203
|
+
enumerable: false,
|
|
204
|
+
value: true
|
|
205
|
+
} });
|
|
206
|
+
}
|
|
207
|
+
source[name] = wrapped;
|
|
208
|
+
return () => {
|
|
209
|
+
source[name] = original;
|
|
210
|
+
};
|
|
211
|
+
} catch {
|
|
212
|
+
return () => {};
|
|
213
|
+
}
|
|
275
214
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
});
|
|
358
|
-
// For popstate we need to listen to the event instead of overriding a method
|
|
359
|
-
window.addEventListener('popstate', () => {
|
|
360
|
-
this.captureNavigationEvent('popstate');
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
captureNavigationEvent(navigationType) {
|
|
364
|
-
const window = this.getWindow();
|
|
365
|
-
if (!window) {
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
const currentPathname = window.location.pathname;
|
|
369
|
-
// Only capture pageview if the pathname has changed
|
|
370
|
-
if (currentPathname !== this._lastPathname) {
|
|
371
|
-
this.capture('$pageview', {
|
|
372
|
-
navigation_type: navigationType
|
|
373
|
-
});
|
|
374
|
-
this._lastPathname = currentPathname;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/posthog-web.ts
|
|
217
|
+
var PostHog = class extends _posthog_core.PostHogCore {
|
|
218
|
+
constructor(apiKey, options) {
|
|
219
|
+
super(apiKey, options);
|
|
220
|
+
this._lastPathname = "";
|
|
221
|
+
this._storageKey = options?.persistence_name ? `ph_${options.persistence_name}` : `ph_${apiKey}_posthog`;
|
|
222
|
+
this._disableCaptureUrlHashes = options?.disable_capture_url_hashes ?? false;
|
|
223
|
+
this._storage = getStorage(options?.persistence || "localStorage", this.getWindow());
|
|
224
|
+
this.setupBootstrap(options);
|
|
225
|
+
if (options?.preloadFeatureFlags !== false) this.reloadFeatureFlags();
|
|
226
|
+
if (options?.captureHistoryEvents && typeof window !== "undefined") {
|
|
227
|
+
this._lastPathname = window?.location?.pathname || "";
|
|
228
|
+
this.setupHistoryEventTracking();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
getWindow() {
|
|
232
|
+
return typeof window !== "undefined" ? window : void 0;
|
|
233
|
+
}
|
|
234
|
+
getPersistedProperty(key) {
|
|
235
|
+
if (!this._storageCache) this._storageCache = JSON.parse(this._storage.getItem(this._storageKey) || "{}") || {};
|
|
236
|
+
return this._storageCache[key];
|
|
237
|
+
}
|
|
238
|
+
setPersistedProperty(key, value) {
|
|
239
|
+
if (!this._storageCache) this._storageCache = JSON.parse(this._storage.getItem(this._storageKey) || "{}") || {};
|
|
240
|
+
if (value === null) delete this._storageCache[key];
|
|
241
|
+
else this._storageCache[key] = value;
|
|
242
|
+
this._storage.setItem(this._storageKey, JSON.stringify(this._storageCache));
|
|
243
|
+
}
|
|
244
|
+
fetch(url, options) {
|
|
245
|
+
const fetchFn = (0, _posthog_core.getFetch)();
|
|
246
|
+
if (!fetchFn) return Promise.reject(/* @__PURE__ */ new Error("Fetch API is not available in this environment."));
|
|
247
|
+
return fetchFn(url, options);
|
|
248
|
+
}
|
|
249
|
+
getLibraryId() {
|
|
250
|
+
return "posthog-js-lite";
|
|
251
|
+
}
|
|
252
|
+
getLibraryVersion() {
|
|
253
|
+
return version;
|
|
254
|
+
}
|
|
255
|
+
getCustomUserAgent() {}
|
|
256
|
+
getCommonEventProperties() {
|
|
257
|
+
return {
|
|
258
|
+
...super.getCommonEventProperties(),
|
|
259
|
+
...getContext(this.getWindow(), this._disableCaptureUrlHashes)
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
setupHistoryEventTracking() {
|
|
263
|
+
const window = this.getWindow();
|
|
264
|
+
if (!window) return;
|
|
265
|
+
const self = this;
|
|
266
|
+
patch(window.history, "pushState", (originalPushState) => {
|
|
267
|
+
return function patchedPushState(state, title, url) {
|
|
268
|
+
originalPushState.call(this, state, title, url);
|
|
269
|
+
self.captureNavigationEvent("pushState");
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
patch(window.history, "replaceState", (originalReplaceState) => {
|
|
273
|
+
return function patchedReplaceState(state, title, url) {
|
|
274
|
+
originalReplaceState.call(this, state, title, url);
|
|
275
|
+
self.captureNavigationEvent("replaceState");
|
|
276
|
+
};
|
|
277
|
+
});
|
|
278
|
+
window.addEventListener("popstate", () => {
|
|
279
|
+
this.captureNavigationEvent("popstate");
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
captureNavigationEvent(navigationType) {
|
|
283
|
+
const window = this.getWindow();
|
|
284
|
+
if (!window) return;
|
|
285
|
+
const currentPathname = window.location.pathname;
|
|
286
|
+
if (currentPathname !== this._lastPathname) {
|
|
287
|
+
this.capture("$pageview", { navigation_type: navigationType });
|
|
288
|
+
this._lastPathname = currentPathname;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/index.ts
|
|
294
|
+
var src_default = PostHog;
|
|
295
|
+
//#endregion
|
|
379
296
|
exports.PostHog = PostHog;
|
|
380
|
-
exports.default =
|
|
381
|
-
|
|
297
|
+
exports.default = src_default;
|
|
298
|
+
|
|
299
|
+
//# sourceMappingURL=index.cjs.map
|