@posthog/browser 0.1.1 → 0.2.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/ARCHITECTURE.md +28 -22
- package/README.md +65 -29
- package/dist/analytics-api.d.ts +26 -0
- package/dist/analytics-api.js +18 -0
- package/dist/analytics-api.mjs +1 -0
- package/dist/analytics-buffer.d.ts +3 -3
- package/dist/analytics-buffer.js +2 -161
- package/dist/analytics-buffer.mjs +2 -161
- package/dist/analytics-extension.d.ts +76 -0
- package/dist/analytics-extension.js +589 -0
- package/dist/analytics-extension.mjs +551 -0
- package/dist/analytics-internal.d.ts +32 -18
- package/dist/analytics-options.d.ts +7 -2
- package/dist/analytics-options.js +38 -1
- package/dist/analytics-options.mjs +17 -1
- package/dist/analytics.d.ts +4 -3
- package/dist/autocapture.d.ts +2 -2
- package/dist/autocapture.js +21 -10
- package/dist/autocapture.mjs +21 -10
- package/dist/automatic-analytics.d.ts +2 -2
- package/dist/browser-client.d.ts +44 -4
- package/dist/capture-properties.d.ts +9 -0
- package/dist/capture-properties.js +68 -0
- package/dist/capture-properties.mjs +30 -0
- package/dist/capture-v1.js +7 -19
- package/dist/capture-v1.mjs +1 -13
- package/dist/core.d.ts +7 -5
- package/dist/extensions/registry.d.ts +42 -7
- package/dist/extensions/registry.js +194 -37
- package/dist/extensions/registry.mjs +194 -37
- package/dist/flags-token.d.ts +4 -4
- package/dist/flags.js +15 -2
- package/dist/flags.mjs +15 -2
- package/dist/immutable.d.ts +1 -0
- package/dist/immutable.js +46 -0
- package/dist/immutable.mjs +8 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.js +3 -67
- package/dist/index.mjs +3 -67
- package/dist/logs-internal.d.ts +2 -2
- package/dist/logs.js +5 -2
- package/dist/logs.mjs +5 -2
- package/dist/person-processing.d.ts +11 -0
- package/dist/person-processing.js +84 -0
- package/dist/person-processing.mjs +37 -0
- package/dist/posthog.d.ts +4 -3
- package/dist/posthog.js +153 -353
- package/dist/posthog.mjs +153 -353
- package/dist/root-composition.d.ts +11 -0
- package/dist/root-composition.js +138 -0
- package/dist/root-composition.mjs +100 -0
- package/dist/state.d.ts +1 -0
- package/dist/state.js +4 -0
- package/dist/state.mjs +4 -0
- package/dist/surveys-extension.js +11 -6
- package/dist/surveys-extension.mjs +11 -6
- package/dist/surveys-internal.d.ts +3 -2
- package/dist/types.d.ts +13 -19
- package/dist/utf8.d.ts +1 -0
- package/dist/utf8.js +52 -0
- package/dist/utf8.mjs +14 -0
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
createProductComposition: ()=>createProductComposition
|
|
32
|
+
});
|
|
33
|
+
const constants_namespaceObject = require("@posthog/browser-common/constants");
|
|
34
|
+
const surveys_config_namespaceObject = require("@posthog/browser-common/surveys-config");
|
|
35
|
+
const external_autocapture_options_js_namespaceObject = require("./autocapture-options.js");
|
|
36
|
+
const external_surveys_options_js_namespaceObject = require("./surveys-options.js");
|
|
37
|
+
const external_logs_options_js_namespaceObject = require("./logs-options.js");
|
|
38
|
+
const external_analytics_options_js_namespaceObject = require("./analytics-options.js");
|
|
39
|
+
const activateFromSignals = (hasSaved, enabled)=>(host, acquire)=>{
|
|
40
|
+
let loading;
|
|
41
|
+
host.onRemoteConfig((result)=>{
|
|
42
|
+
if (result.ok && enabled(result.config)) loading = acquire();
|
|
43
|
+
});
|
|
44
|
+
return hasSaved(host) ? acquire() : loading;
|
|
45
|
+
};
|
|
46
|
+
const registerProduct = (composition, name, label, configure)=>{
|
|
47
|
+
if (composition.extensions.some((extension)=>extension.name === name)) return;
|
|
48
|
+
try {
|
|
49
|
+
const definition = configure();
|
|
50
|
+
if (definition) {
|
|
51
|
+
composition.loaders[name] = definition.load;
|
|
52
|
+
composition.automatic.push({
|
|
53
|
+
name,
|
|
54
|
+
activate: definition.activate ?? ((_host, acquire)=>acquire())
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
composition.loadingErrors.push([
|
|
59
|
+
label,
|
|
60
|
+
error
|
|
61
|
+
]);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const configureAnalytics = (options, composition)=>{
|
|
65
|
+
let configuration;
|
|
66
|
+
if (composition.extensions.some((extension)=>'analytics' === extension.name)) configuration = false;
|
|
67
|
+
else try {
|
|
68
|
+
configuration = options?.analytics;
|
|
69
|
+
} catch {}
|
|
70
|
+
const snapshot = (0, external_analytics_options_js_namespaceObject.snapshotAutomaticAnalyticsOptions)(configuration || {});
|
|
71
|
+
if (false !== configuration) composition.loaders.analytics = ()=>import("./automatic-analytics.js").then(({ analytics })=>analytics(snapshot));
|
|
72
|
+
return snapshot;
|
|
73
|
+
};
|
|
74
|
+
const configureFlags = (options)=>{
|
|
75
|
+
const configuration = options?.flags;
|
|
76
|
+
if (false === configuration) return;
|
|
77
|
+
const snapshot = configuration && JSON.parse(JSON.stringify(configuration));
|
|
78
|
+
return {
|
|
79
|
+
load: ()=>import("./flags.js").then(({ flags })=>flags(snapshot))
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const configureLogs = (options)=>{
|
|
83
|
+
const configuration = options?.logs;
|
|
84
|
+
if (false === configuration) return;
|
|
85
|
+
const snapshot = (0, external_logs_options_js_namespaceObject.snapshotLogsOptions)(configuration);
|
|
86
|
+
return {
|
|
87
|
+
load: ()=>import("./logs.js").then(({ logs })=>logs(snapshot)),
|
|
88
|
+
activate: void 0 === configuration ? activateFromSignals((host)=>true === host.kv.get('consoleCaptureEnabled'), (config)=>config.logs?.captureConsoleLogs === true) : void 0
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
const configureSurveys = (options)=>{
|
|
92
|
+
const configuration = options?.surveys;
|
|
93
|
+
if (false === configuration) return;
|
|
94
|
+
const snapshot = (0, external_surveys_options_js_namespaceObject.snapshotSurveysOptions)(configuration);
|
|
95
|
+
return {
|
|
96
|
+
load: ()=>import("./automatic-surveys.js").then(({ surveys })=>surveys(snapshot)),
|
|
97
|
+
activate: void 0 === configuration ? activateFromSignals((host)=>{
|
|
98
|
+
const cached = host.kv.get(surveys_config_namespaceObject.SURVEYS);
|
|
99
|
+
return Array.isArray(cached) && cached.length > 0;
|
|
100
|
+
}, (config)=>true === config.surveys || Array.isArray(config.surveys) && config.surveys.length > 0) : void 0
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
const configureAutocapture = (options)=>{
|
|
104
|
+
const configuration = options?.autocapture;
|
|
105
|
+
if (false === configuration) return;
|
|
106
|
+
const snapshot = (0, external_autocapture_options_js_namespaceObject.snapshotAutocaptureOptions)(configuration);
|
|
107
|
+
return {
|
|
108
|
+
load: ()=>import("./autocapture.js").then(({ autocapture })=>autocapture(snapshot)),
|
|
109
|
+
activate: void 0 === configuration ? activateFromSignals((host)=>false === host.kv.get(constants_namespaceObject.AUTOCAPTURE_DISABLED_SERVER_SIDE), (config)=>false === config.autocapture_opt_out) : void 0
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
const createProductComposition = (options)=>{
|
|
113
|
+
const composition = {
|
|
114
|
+
extensions: [
|
|
115
|
+
...options?.extensions ?? []
|
|
116
|
+
],
|
|
117
|
+
loaders: {},
|
|
118
|
+
automatic: [],
|
|
119
|
+
loadingErrors: []
|
|
120
|
+
};
|
|
121
|
+
const analyticsOptions = configureAnalytics(options, composition);
|
|
122
|
+
if ('eager' === analyticsOptions.load) composition.automatic.push({
|
|
123
|
+
name: 'analytics',
|
|
124
|
+
activate: (_host, acquire)=>acquire()
|
|
125
|
+
});
|
|
126
|
+
registerProduct(composition, 'featureFlags', 'flags', ()=>configureFlags(options));
|
|
127
|
+
registerProduct(composition, 'logs', 'logs', ()=>configureLogs(options));
|
|
128
|
+
registerProduct(composition, 'surveys', 'surveys', ()=>configureSurveys(options));
|
|
129
|
+
registerProduct(composition, 'autocapture', 'autocapture', ()=>configureAutocapture(options));
|
|
130
|
+
return composition;
|
|
131
|
+
};
|
|
132
|
+
exports.createProductComposition = __webpack_exports__.createProductComposition;
|
|
133
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
134
|
+
"createProductComposition"
|
|
135
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
136
|
+
Object.defineProperty(exports, '__esModule', {
|
|
137
|
+
value: true
|
|
138
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { AUTOCAPTURE_DISABLED_SERVER_SIDE } from "@posthog/browser-common/constants";
|
|
2
|
+
import { SURVEYS } from "@posthog/browser-common/surveys-config";
|
|
3
|
+
import { snapshotAutocaptureOptions } from "./autocapture-options.mjs";
|
|
4
|
+
import { snapshotSurveysOptions } from "./surveys-options.mjs";
|
|
5
|
+
import { snapshotLogsOptions } from "./logs-options.mjs";
|
|
6
|
+
import { snapshotAutomaticAnalyticsOptions } from "./analytics-options.mjs";
|
|
7
|
+
const activateFromSignals = (hasSaved, enabled)=>(host, acquire)=>{
|
|
8
|
+
let loading;
|
|
9
|
+
host.onRemoteConfig((result)=>{
|
|
10
|
+
if (result.ok && enabled(result.config)) loading = acquire();
|
|
11
|
+
});
|
|
12
|
+
return hasSaved(host) ? acquire() : loading;
|
|
13
|
+
};
|
|
14
|
+
const registerProduct = (composition, name, label, configure)=>{
|
|
15
|
+
if (composition.extensions.some((extension)=>extension.name === name)) return;
|
|
16
|
+
try {
|
|
17
|
+
const definition = configure();
|
|
18
|
+
if (definition) {
|
|
19
|
+
composition.loaders[name] = definition.load;
|
|
20
|
+
composition.automatic.push({
|
|
21
|
+
name,
|
|
22
|
+
activate: definition.activate ?? ((_host, acquire)=>acquire())
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
} catch (error) {
|
|
26
|
+
composition.loadingErrors.push([
|
|
27
|
+
label,
|
|
28
|
+
error
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const configureAnalytics = (options, composition)=>{
|
|
33
|
+
let configuration;
|
|
34
|
+
if (composition.extensions.some((extension)=>'analytics' === extension.name)) configuration = false;
|
|
35
|
+
else try {
|
|
36
|
+
configuration = options?.analytics;
|
|
37
|
+
} catch {}
|
|
38
|
+
const snapshot = snapshotAutomaticAnalyticsOptions(configuration || {});
|
|
39
|
+
if (false !== configuration) composition.loaders.analytics = ()=>import("./automatic-analytics.mjs").then(({ analytics })=>analytics(snapshot));
|
|
40
|
+
return snapshot;
|
|
41
|
+
};
|
|
42
|
+
const configureFlags = (options)=>{
|
|
43
|
+
const configuration = options?.flags;
|
|
44
|
+
if (false === configuration) return;
|
|
45
|
+
const snapshot = configuration && JSON.parse(JSON.stringify(configuration));
|
|
46
|
+
return {
|
|
47
|
+
load: ()=>import("./flags.mjs").then(({ flags })=>flags(snapshot))
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const configureLogs = (options)=>{
|
|
51
|
+
const configuration = options?.logs;
|
|
52
|
+
if (false === configuration) return;
|
|
53
|
+
const snapshot = snapshotLogsOptions(configuration);
|
|
54
|
+
return {
|
|
55
|
+
load: ()=>import("./logs.mjs").then(({ logs })=>logs(snapshot)),
|
|
56
|
+
activate: void 0 === configuration ? activateFromSignals((host)=>true === host.kv.get('consoleCaptureEnabled'), (config)=>config.logs?.captureConsoleLogs === true) : void 0
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const configureSurveys = (options)=>{
|
|
60
|
+
const configuration = options?.surveys;
|
|
61
|
+
if (false === configuration) return;
|
|
62
|
+
const snapshot = snapshotSurveysOptions(configuration);
|
|
63
|
+
return {
|
|
64
|
+
load: ()=>import("./automatic-surveys.mjs").then(({ surveys })=>surveys(snapshot)),
|
|
65
|
+
activate: void 0 === configuration ? activateFromSignals((host)=>{
|
|
66
|
+
const cached = host.kv.get(SURVEYS);
|
|
67
|
+
return Array.isArray(cached) && cached.length > 0;
|
|
68
|
+
}, (config)=>true === config.surveys || Array.isArray(config.surveys) && config.surveys.length > 0) : void 0
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const configureAutocapture = (options)=>{
|
|
72
|
+
const configuration = options?.autocapture;
|
|
73
|
+
if (false === configuration) return;
|
|
74
|
+
const snapshot = snapshotAutocaptureOptions(configuration);
|
|
75
|
+
return {
|
|
76
|
+
load: ()=>import("./autocapture.mjs").then(({ autocapture })=>autocapture(snapshot)),
|
|
77
|
+
activate: void 0 === configuration ? activateFromSignals((host)=>false === host.kv.get(AUTOCAPTURE_DISABLED_SERVER_SIDE), (config)=>false === config.autocapture_opt_out) : void 0
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const createProductComposition = (options)=>{
|
|
81
|
+
const composition = {
|
|
82
|
+
extensions: [
|
|
83
|
+
...options?.extensions ?? []
|
|
84
|
+
],
|
|
85
|
+
loaders: {},
|
|
86
|
+
automatic: [],
|
|
87
|
+
loadingErrors: []
|
|
88
|
+
};
|
|
89
|
+
const analyticsOptions = configureAnalytics(options, composition);
|
|
90
|
+
if ('eager' === analyticsOptions.load) composition.automatic.push({
|
|
91
|
+
name: 'analytics',
|
|
92
|
+
activate: (_host, acquire)=>acquire()
|
|
93
|
+
});
|
|
94
|
+
registerProduct(composition, 'featureFlags', 'flags', ()=>configureFlags(options));
|
|
95
|
+
registerProduct(composition, 'logs', 'logs', ()=>configureLogs(options));
|
|
96
|
+
registerProduct(composition, 'surveys', 'surveys', ()=>configureSurveys(options));
|
|
97
|
+
registerProduct(composition, 'autocapture', 'autocapture', ()=>configureAutocapture(options));
|
|
98
|
+
return composition;
|
|
99
|
+
};
|
|
100
|
+
export { createProductComposition };
|
package/dist/state.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ export declare class BrowserState {
|
|
|
56
56
|
observeConsent(value: unknown): ConsentState;
|
|
57
57
|
identify(distinctId: string): void;
|
|
58
58
|
group(type: string, key: string): boolean;
|
|
59
|
+
resetGroups(): void;
|
|
59
60
|
prepareSessionForEvent(now?: number): PreparedSession;
|
|
60
61
|
sessionAdmitted(prepared: PreparedSession): boolean;
|
|
61
62
|
reset(): void;
|
package/dist/state.js
CHANGED
|
@@ -282,6 +282,10 @@ class BrowserState {
|
|
|
282
282
|
this._save();
|
|
283
283
|
return true;
|
|
284
284
|
}
|
|
285
|
+
resetGroups() {
|
|
286
|
+
this._state.groups = emptyRecord();
|
|
287
|
+
this._save();
|
|
288
|
+
}
|
|
285
289
|
prepareSessionForEvent(now = Date.now()) {
|
|
286
290
|
const safeNow = isTimestamp(now) ? now : 0;
|
|
287
291
|
const [sharedRead, external] = this._readPersistedState();
|
package/dist/state.mjs
CHANGED
|
@@ -248,6 +248,10 @@ class BrowserState {
|
|
|
248
248
|
this._save();
|
|
249
249
|
return true;
|
|
250
250
|
}
|
|
251
|
+
resetGroups() {
|
|
252
|
+
this._state.groups = emptyRecord();
|
|
253
|
+
this._save();
|
|
254
|
+
}
|
|
251
255
|
prepareSessionForEvent(now = Date.now()) {
|
|
252
256
|
const safeNow = isTimestamp(now) ? now : 0;
|
|
253
257
|
const [sharedRead, external] = this._readPersistedState();
|
|
@@ -52,7 +52,7 @@ const createSurveys = (options, load)=>{
|
|
|
52
52
|
let loading;
|
|
53
53
|
let remoteSubscription;
|
|
54
54
|
let resetSubscription;
|
|
55
|
-
const getFlagsContext = ()=>client?.
|
|
55
|
+
const getFlagsContext = ()=>client?.featureFlags?.getSurveyContext?.();
|
|
56
56
|
const reset = ()=>{
|
|
57
57
|
shared.reset();
|
|
58
58
|
};
|
|
@@ -92,7 +92,7 @@ const createSurveys = (options, load)=>{
|
|
|
92
92
|
getActionUrl: ()=>runtimeHost ? (0, url_targeting_utils_namespaceObject.getTargetingUrl)(runtimeHost) : void 0,
|
|
93
93
|
setElementSelectors: (selectors)=>{
|
|
94
94
|
elementSelectors = new Set(selectors);
|
|
95
|
-
|
|
95
|
+
client?.autocapture?.setElementSelectors(new Set(elementSelectors));
|
|
96
96
|
}
|
|
97
97
|
}, onActivationChanged);
|
|
98
98
|
return eventReceiver;
|
|
@@ -147,12 +147,17 @@ const createSurveys = (options, load)=>{
|
|
|
147
147
|
};
|
|
148
148
|
return {
|
|
149
149
|
name: 'surveys',
|
|
150
|
+
bindings: {
|
|
151
|
+
surveys: shared
|
|
152
|
+
},
|
|
150
153
|
setup: async (value)=>{
|
|
151
154
|
client = value;
|
|
155
|
+
await value.resolveExtension('analytics');
|
|
156
|
+
if (disposed) return;
|
|
152
157
|
await value.kv.initialize();
|
|
153
158
|
if (disposed) return;
|
|
154
159
|
resetSubscription = value.onReset(reset);
|
|
155
|
-
const renderClient = Object.create(value);
|
|
160
|
+
const renderClient = Object.create(value.sharedClient);
|
|
156
161
|
const read = (key)=>key === constants_namespaceObject.STORED_PERSON_PROPERTIES_KEY ? getFlagsContext()?.personProperties : value.kv.get(key);
|
|
157
162
|
const renderKv = {
|
|
158
163
|
...value.kv,
|
|
@@ -178,9 +183,9 @@ const createSurveys = (options, load)=>{
|
|
|
178
183
|
if (remoteEnabled && !disposed) manager?.startAutomaticDisplay?.();
|
|
179
184
|
}
|
|
180
185
|
});
|
|
181
|
-
await shared.setup(value);
|
|
186
|
+
await shared.setup(value.sharedClient);
|
|
182
187
|
if (disposed) return void shared.dispose();
|
|
183
|
-
teardownSubscription = client.
|
|
188
|
+
teardownSubscription = client.analytics?.onBeforeTeardown?.(()=>shared.handlePageUnload());
|
|
184
189
|
if ("u" > typeof window) window.addEventListener('pagehide', pagehide);
|
|
185
190
|
},
|
|
186
191
|
getSurveys: (callback, forceReload)=>run(callback, (notify)=>shared.getSurveys(notify, forceReload)),
|
|
@@ -247,7 +252,7 @@ const createSurveys = (options, load)=>{
|
|
|
247
252
|
disposed = true;
|
|
248
253
|
elementSelectors.clear();
|
|
249
254
|
try {
|
|
250
|
-
client?.
|
|
255
|
+
client?.autocapture?.setElementSelectors(new Set());
|
|
251
256
|
} catch (error) {
|
|
252
257
|
client?.logger.error('Failed to clear survey action selectors', error);
|
|
253
258
|
}
|
|
@@ -20,7 +20,7 @@ const createSurveys = (options, load)=>{
|
|
|
20
20
|
let loading;
|
|
21
21
|
let remoteSubscription;
|
|
22
22
|
let resetSubscription;
|
|
23
|
-
const getFlagsContext = ()=>client?.
|
|
23
|
+
const getFlagsContext = ()=>client?.featureFlags?.getSurveyContext?.();
|
|
24
24
|
const reset = ()=>{
|
|
25
25
|
shared.reset();
|
|
26
26
|
};
|
|
@@ -60,7 +60,7 @@ const createSurveys = (options, load)=>{
|
|
|
60
60
|
getActionUrl: ()=>runtimeHost ? getTargetingUrl(runtimeHost) : void 0,
|
|
61
61
|
setElementSelectors: (selectors)=>{
|
|
62
62
|
elementSelectors = new Set(selectors);
|
|
63
|
-
|
|
63
|
+
client?.autocapture?.setElementSelectors(new Set(elementSelectors));
|
|
64
64
|
}
|
|
65
65
|
}, onActivationChanged);
|
|
66
66
|
return eventReceiver;
|
|
@@ -115,12 +115,17 @@ const createSurveys = (options, load)=>{
|
|
|
115
115
|
};
|
|
116
116
|
return {
|
|
117
117
|
name: 'surveys',
|
|
118
|
+
bindings: {
|
|
119
|
+
surveys: shared
|
|
120
|
+
},
|
|
118
121
|
setup: async (value)=>{
|
|
119
122
|
client = value;
|
|
123
|
+
await value.resolveExtension('analytics');
|
|
124
|
+
if (disposed) return;
|
|
120
125
|
await value.kv.initialize();
|
|
121
126
|
if (disposed) return;
|
|
122
127
|
resetSubscription = value.onReset(reset);
|
|
123
|
-
const renderClient = Object.create(value);
|
|
128
|
+
const renderClient = Object.create(value.sharedClient);
|
|
124
129
|
const read = (key)=>key === STORED_PERSON_PROPERTIES_KEY ? getFlagsContext()?.personProperties : value.kv.get(key);
|
|
125
130
|
const renderKv = {
|
|
126
131
|
...value.kv,
|
|
@@ -146,9 +151,9 @@ const createSurveys = (options, load)=>{
|
|
|
146
151
|
if (remoteEnabled && !disposed) manager?.startAutomaticDisplay?.();
|
|
147
152
|
}
|
|
148
153
|
});
|
|
149
|
-
await shared.setup(value);
|
|
154
|
+
await shared.setup(value.sharedClient);
|
|
150
155
|
if (disposed) return void shared.dispose();
|
|
151
|
-
teardownSubscription = client.
|
|
156
|
+
teardownSubscription = client.analytics?.onBeforeTeardown?.(()=>shared.handlePageUnload());
|
|
152
157
|
if ("u" > typeof window) window.addEventListener('pagehide', pagehide);
|
|
153
158
|
},
|
|
154
159
|
getSurveys: (callback, forceReload)=>run(callback, (notify)=>shared.getSurveys(notify, forceReload)),
|
|
@@ -215,7 +220,7 @@ const createSurveys = (options, load)=>{
|
|
|
215
220
|
disposed = true;
|
|
216
221
|
elementSelectors.clear();
|
|
217
222
|
try {
|
|
218
|
-
client?.
|
|
223
|
+
client?.autocapture?.setElementSelectors(new Set());
|
|
219
224
|
} catch (error) {
|
|
220
225
|
client?.logger.error('Failed to clear survey action selectors', error);
|
|
221
226
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { Disposable
|
|
1
|
+
import type { Disposable } from '@posthog/browser-common';
|
|
2
|
+
import type { BrowserExtension } from './browser-client';
|
|
2
3
|
import type { SurveyCallback, DisplaySurveyOptions, SurveyRenderReason } from './surveys-options';
|
|
3
|
-
export interface SurveysExtension extends
|
|
4
|
+
export interface SurveysExtension extends BrowserExtension {
|
|
4
5
|
getElementSelectors(): Set<string>;
|
|
5
6
|
getSurveys(callback: SurveyCallback, forceReload?: boolean): void;
|
|
6
7
|
getActiveMatchingSurveys(callback: SurveyCallback, forceReload?: boolean): void;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { FlagsConfiguration } from './flags-options';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ICoreCapabilities, BrowserExtensionAccess, BrowserExtension as Extension } from './browser-client';
|
|
3
3
|
import type { LogsConfiguration } from './logs-options';
|
|
4
4
|
import type { SurveysConfiguration } from './surveys-options';
|
|
5
5
|
import type { AutocaptureConfiguration } from './autocapture-options';
|
|
6
|
-
import type { AnalyticsConfiguration, AnalyticsOptions, AutomaticAnalyticsOptions, LoadStrategy } from './analytics-options';
|
|
7
|
-
import type { ApiResponse, CaptureOptions, Disposable,
|
|
6
|
+
import type { AnalyticsConfiguration, AnalyticsOptions, AutomaticAnalyticsOptions, LoadStrategy, PersonProfileMode } from './analytics-options';
|
|
7
|
+
import type { ApiResponse, CaptureOptions, Disposable, Listener, RemoteConfig, SendRequestInit, SessionContext } from '@posthog/browser-common';
|
|
8
8
|
export interface StorageLike {
|
|
9
9
|
getItem(key: string): string | null;
|
|
10
10
|
setItem(key: string, value: string): void;
|
|
@@ -57,22 +57,22 @@ export interface PostHogOptions {
|
|
|
57
57
|
/** Stop waiting for remote configuration after this duration in milliseconds. Defaults to 10,000. */
|
|
58
58
|
remoteConfigTimeoutMs?: number;
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
61
|
-
* Pass `false` to
|
|
60
|
+
* First-party analytics acquisition. Defaults to on-demand loading through resolution, product dependencies,
|
|
61
|
+
* or the initial pageview. Pass `false` to omit implicit analytics; explicit instances take precedence.
|
|
62
62
|
*/
|
|
63
63
|
analytics?: AnalyticsConfiguration;
|
|
64
|
-
/**
|
|
64
|
+
/** Acquire DOM autocapture from saved/fresh signals, or during initialization when configured explicitly. */
|
|
65
65
|
autocapture?: AutocaptureConfiguration;
|
|
66
66
|
/** Dynamically include flags by default. Explicit extensions take precedence over this option. */
|
|
67
67
|
flags?: FlagsConfiguration;
|
|
68
|
-
/**
|
|
68
|
+
/** Acquire surveys from saved/fresh enablement signals, or during initialization when configured explicitly. */
|
|
69
69
|
surveys?: SurveysConfiguration;
|
|
70
|
-
/**
|
|
70
|
+
/** Acquire logs from saved/fresh console signals, or during initialization when configured explicitly. */
|
|
71
71
|
logs?: LogsConfiguration;
|
|
72
|
-
/** Install extensions before the factory resolves.
|
|
72
|
+
/** Install extensions before the factory resolves. Explicit instances take precedence over automatic product options. */
|
|
73
73
|
extensions?: readonly Extension[];
|
|
74
74
|
}
|
|
75
|
-
/** Options for the
|
|
75
|
+
/** Options for the manually composed `@posthog/browser/core` entrypoint. */
|
|
76
76
|
export type CorePostHogOptions = Omit<PostHogOptions, 'analytics' | 'flags' | 'logs' | 'surveys' | 'autocapture'>;
|
|
77
77
|
/** Capture V1's terminal verdict for one reported event. */
|
|
78
78
|
export type CaptureOutcomeStatus = 'ok' | 'warning' | 'drop' | 'retry';
|
|
@@ -94,21 +94,15 @@ export interface CaptureSummary {
|
|
|
94
94
|
/** Operation-level failure, with any known partial results retained. Errors always set `allPersisted` to false. */
|
|
95
95
|
readonly error?: Error;
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
/** Consumer-facing SDK contract; product controls use their public interfaces. */
|
|
98
|
+
export interface IPostHog extends ICoreCapabilities, BrowserExtensionAccess, Disposable {
|
|
98
99
|
readonly onNewSession: Listener<NewSessionInfo>;
|
|
99
|
-
/** Sends one finalized event inline. Resolves with an outcome or `summary.error` instead of rejecting. */
|
|
100
|
-
captureImmediate(event: string, properties?: Record<string, unknown> | null, options?: CaptureOptions): Promise<CaptureSummary>;
|
|
101
|
-
identify(distinctId: string, set?: Record<string, unknown>, setOnce?: Record<string, unknown>): Promise<void>;
|
|
102
|
-
group(type: string, key: string, properties?: Record<string, unknown>): Promise<void>;
|
|
103
|
-
reset(): void;
|
|
104
100
|
flush(): Promise<void>;
|
|
105
101
|
shutdown(shutdownTimeoutMs?: number): Promise<void>;
|
|
106
102
|
dispose(): Promise<void>;
|
|
107
103
|
optIn(): void;
|
|
108
104
|
optOut(): void;
|
|
109
105
|
hasOptedOut(): boolean;
|
|
110
|
-
getExtension<T extends Extension>(token: ExtensionToken<T>): T | undefined;
|
|
111
|
-
getExtension<T extends Extension = Extension>(name: string): T | undefined;
|
|
112
106
|
getRemoteConfig(): Promise<RemoteConfig | undefined>;
|
|
113
107
|
}
|
|
114
|
-
export type { AnalyticsConfiguration, AnalyticsOptions, AutomaticAnalyticsOptions, LoadStrategy, ApiResponse, CaptureOptions, Disposable, Extension, RemoteConfig, SendRequestInit, SessionContext, };
|
|
108
|
+
export type { AnalyticsConfiguration, AnalyticsOptions, AutomaticAnalyticsOptions, LoadStrategy, PersonProfileMode, ApiResponse, CaptureOptions, Disposable, Extension, RemoteConfig, SendRequestInit, SessionContext, };
|
package/dist/utf8.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const utf8Bytes: (value: string) => number;
|
package/dist/utf8.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
const utf8Bytes = (value)=>{
|
|
31
|
+
let bytes = 0;
|
|
32
|
+
for(let index = 0; index < value.length; index++){
|
|
33
|
+
const code = value.charCodeAt(index);
|
|
34
|
+
if (code < 0x80) bytes++;
|
|
35
|
+
else if (code < 0x800) bytes += 2;
|
|
36
|
+
else if (code >= 0xd800 && code <= 0xdbff && value.charCodeAt(index + 1) >= 0xdc00) {
|
|
37
|
+
bytes += 4;
|
|
38
|
+
index++;
|
|
39
|
+
} else bytes += 3;
|
|
40
|
+
}
|
|
41
|
+
return bytes;
|
|
42
|
+
};
|
|
43
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
44
|
+
utf8Bytes: utf8Bytes
|
|
45
|
+
});
|
|
46
|
+
exports.utf8Bytes = __webpack_exports__.utf8Bytes;
|
|
47
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
48
|
+
"utf8Bytes"
|
|
49
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
50
|
+
Object.defineProperty(exports, '__esModule', {
|
|
51
|
+
value: true
|
|
52
|
+
});
|
package/dist/utf8.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const utf8Bytes = (value)=>{
|
|
2
|
+
let bytes = 0;
|
|
3
|
+
for(let index = 0; index < value.length; index++){
|
|
4
|
+
const code = value.charCodeAt(index);
|
|
5
|
+
if (code < 0x80) bytes++;
|
|
6
|
+
else if (code < 0x800) bytes += 2;
|
|
7
|
+
else if (code >= 0xd800 && code <= 0xdbff && value.charCodeAt(index + 1) >= 0xdc00) {
|
|
8
|
+
bytes += 4;
|
|
9
|
+
index++;
|
|
10
|
+
} else bytes += 3;
|
|
11
|
+
}
|
|
12
|
+
return bytes;
|
|
13
|
+
};
|
|
14
|
+
export { utf8Bytes };
|
package/dist/version.js
CHANGED
package/dist/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = "0.
|
|
1
|
+
const version = "0.2.0";
|
|
2
2
|
export { version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A small, extension-based PostHog client for modern browsers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@posthog/browser-common": "^0.
|
|
59
|
-
"@posthog/types": "^1.
|
|
58
|
+
"@posthog/browser-common": "^0.11.0",
|
|
59
|
+
"@posthog/types": "^1.425.1"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@playwright/test": "1.52.0",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"typescript": "7.0.2",
|
|
67
67
|
"typescript-legacy": "npm:typescript@5.8.2",
|
|
68
68
|
"vitest": "^1.6.1",
|
|
69
|
-
"@posthog-tooling/
|
|
70
|
-
"@posthog-tooling/
|
|
69
|
+
"@posthog-tooling/tsconfig-base": "1.1.1",
|
|
70
|
+
"@posthog-tooling/sdk-mock-server": "0.0.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"clean": "rimraf dist dist-cdn",
|