@posthog/browser 0.4.1 → 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.
- package/ARCHITECTURE.md +34 -46
- package/README.md +56 -63
- package/dist/composition/npm/core.d.ts +2 -3
- package/dist/composition/npm/core.js +2 -1
- package/dist/composition/npm/core.mjs +2 -1
- package/dist/composition/npm/index.d.ts +3 -4
- package/dist/composition/npm/index.js +2 -1
- package/dist/composition/npm/index.mjs +2 -1
- package/dist/composition/npm/root-composition.d.ts +4 -4
- package/dist/composition/npm/root-composition.js +0 -16
- package/dist/composition/npm/root-composition.mjs +0 -16
- package/dist/core/context/browser-client.d.ts +4 -35
- package/dist/core/extensions/registry.d.ts +15 -36
- package/dist/core/extensions/registry.js +67 -198
- package/dist/core/extensions/registry.mjs +67 -198
- package/dist/core/posthog.d.ts +3 -2
- package/dist/core/posthog.js +104 -161
- package/dist/core/posthog.mjs +105 -162
- package/dist/core/state/state.d.ts +1 -0
- package/dist/core/state/state.js +7 -0
- package/dist/core/state/state.mjs +5 -1
- package/dist/core/types.d.ts +50 -12
- package/dist/primitives/version.js +1 -1
- package/dist/primitives/version.mjs +1 -1
- package/dist/products/analytics/analytics-core.d.ts +76 -0
- package/dist/products/analytics/analytics-core.js +472 -0
- package/dist/products/analytics/analytics-core.mjs +425 -0
- package/dist/products/analytics/analytics-internal.d.ts +14 -36
- package/dist/products/analytics/analytics-internal.js +2 -10
- package/dist/products/analytics/analytics-internal.mjs +1 -3
- package/dist/products/analytics/analytics-options.d.ts +0 -9
- package/dist/products/analytics/analytics-options.js +1 -38
- package/dist/products/analytics/analytics-options.mjs +1 -17
- package/dist/products/analytics/groups.d.ts +8 -0
- package/dist/products/analytics/groups.js +84 -0
- package/dist/products/analytics/groups.mjs +40 -0
- package/dist/products/analytics/person.d.ts +11 -0
- package/dist/products/analytics/person.js +91 -0
- package/dist/products/analytics/person.mjs +41 -0
- package/dist/products/autocapture/autocapture.js +2 -6
- package/dist/products/autocapture/autocapture.mjs +2 -6
- package/dist/products/flags/flags-internal.d.ts +1 -2
- package/dist/products/flags/flags-token.d.ts +3 -2
- package/dist/products/flags/flags.js +2 -7
- package/dist/products/flags/flags.mjs +2 -7
- package/dist/products/logs/logs.js +2 -5
- package/dist/products/logs/logs.mjs +2 -5
- package/dist/products/surveys/surveys-extension.js +4 -21
- package/dist/products/surveys/surveys-extension.mjs +4 -21
- package/package.json +3 -8
- package/dist/products/analytics/analytics-api.d.ts +0 -32
- package/dist/products/analytics/analytics-api.js +0 -18
- package/dist/products/analytics/analytics-api.mjs +0 -1
- package/dist/products/analytics/analytics-buffer.d.ts +0 -4
- package/dist/products/analytics/analytics-buffer.js +0 -41
- package/dist/products/analytics/analytics-buffer.mjs +0 -3
- package/dist/products/analytics/analytics-extension.d.ts +0 -87
- package/dist/products/analytics/analytics-extension.js +0 -649
- package/dist/products/analytics/analytics-extension.mjs +0 -611
- package/dist/products/analytics/analytics.d.ts +0 -6
- package/dist/products/analytics/analytics.js +0 -42
- package/dist/products/analytics/analytics.mjs +0 -4
- package/dist/products/analytics/automatic-analytics.d.ts +0 -3
- package/dist/products/analytics/automatic-analytics.js +0 -44
- package/dist/products/analytics/automatic-analytics.mjs +0 -6
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
group: ()=>group,
|
|
32
|
+
groupIdentify: ()=>groupIdentify,
|
|
33
|
+
resetGroups: ()=>resetGroups
|
|
34
|
+
});
|
|
35
|
+
const external_analytics_core_js_namespaceObject = require("./analytics-core.js");
|
|
36
|
+
const isValidGroupKey = (value)=>(0, external_analytics_core_js_namespaceObject.isNonEmptyString)(value) || Number.isFinite(value);
|
|
37
|
+
const group = (posthog, type, key, properties)=>{
|
|
38
|
+
const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
|
|
39
|
+
if (!analytics || !(0, external_analytics_core_js_namespaceObject.isNonEmptyString)(type) || !(0, external_analytics_core_js_namespaceObject.isNonEmptyString)(key) || 'never' === analytics._personProfiles || !analytics._canMutate()) return;
|
|
40
|
+
const changed = analytics._core._state.group(type, key);
|
|
41
|
+
if (!changed && !properties) return;
|
|
42
|
+
analytics._groupPublisher.publish({
|
|
43
|
+
type,
|
|
44
|
+
key,
|
|
45
|
+
changed,
|
|
46
|
+
properties
|
|
47
|
+
});
|
|
48
|
+
if (!analytics._hasPersonProcessing()) return;
|
|
49
|
+
analytics.capture('$groupidentify', {
|
|
50
|
+
$group_type: type,
|
|
51
|
+
$group_key: key,
|
|
52
|
+
...properties ? {
|
|
53
|
+
$group_set: properties
|
|
54
|
+
} : {}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const groupIdentify = (posthog, type, key, properties = {}, options = {})=>{
|
|
58
|
+
const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
|
|
59
|
+
if (!analytics || analytics._disposed || !analytics._core._canMutate() || !analytics._core._canDeliver()) return;
|
|
60
|
+
if (!(0, external_analytics_core_js_namespaceObject.isNonEmptyString)(type) || !isValidGroupKey(key)) return void posthog.logger.warn('Group identify requires a non-empty type and a string or finite numeric key');
|
|
61
|
+
if (!analytics._core._state.prepare() || !analytics._requirePersonProcessing()) return;
|
|
62
|
+
analytics.capture('$groupidentify', {
|
|
63
|
+
$group_type: type,
|
|
64
|
+
$group_key: key,
|
|
65
|
+
$group_set: properties
|
|
66
|
+
}, options);
|
|
67
|
+
};
|
|
68
|
+
const resetGroups = (posthog)=>{
|
|
69
|
+
const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
|
|
70
|
+
if (!analytics?._canMutate()) return;
|
|
71
|
+
analytics._core._state.resetGroups();
|
|
72
|
+
analytics._groupsResetPublisher.publish(void 0);
|
|
73
|
+
};
|
|
74
|
+
exports.group = __webpack_exports__.group;
|
|
75
|
+
exports.groupIdentify = __webpack_exports__.groupIdentify;
|
|
76
|
+
exports.resetGroups = __webpack_exports__.resetGroups;
|
|
77
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
78
|
+
"group",
|
|
79
|
+
"groupIdentify",
|
|
80
|
+
"resetGroups"
|
|
81
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
82
|
+
Object.defineProperty(exports, '__esModule', {
|
|
83
|
+
value: true
|
|
84
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { analyticsOf, isNonEmptyString } from "./analytics-core.mjs";
|
|
2
|
+
const isValidGroupKey = (value)=>isNonEmptyString(value) || Number.isFinite(value);
|
|
3
|
+
const group = (posthog, type, key, properties)=>{
|
|
4
|
+
const analytics = analyticsOf(posthog);
|
|
5
|
+
if (!analytics || !isNonEmptyString(type) || !isNonEmptyString(key) || 'never' === analytics._personProfiles || !analytics._canMutate()) return;
|
|
6
|
+
const changed = analytics._core._state.group(type, key);
|
|
7
|
+
if (!changed && !properties) return;
|
|
8
|
+
analytics._groupPublisher.publish({
|
|
9
|
+
type,
|
|
10
|
+
key,
|
|
11
|
+
changed,
|
|
12
|
+
properties
|
|
13
|
+
});
|
|
14
|
+
if (!analytics._hasPersonProcessing()) return;
|
|
15
|
+
analytics.capture('$groupidentify', {
|
|
16
|
+
$group_type: type,
|
|
17
|
+
$group_key: key,
|
|
18
|
+
...properties ? {
|
|
19
|
+
$group_set: properties
|
|
20
|
+
} : {}
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const groupIdentify = (posthog, type, key, properties = {}, options = {})=>{
|
|
24
|
+
const analytics = analyticsOf(posthog);
|
|
25
|
+
if (!analytics || analytics._disposed || !analytics._core._canMutate() || !analytics._core._canDeliver()) return;
|
|
26
|
+
if (!isNonEmptyString(type) || !isValidGroupKey(key)) return void posthog.logger.warn('Group identify requires a non-empty type and a string or finite numeric key');
|
|
27
|
+
if (!analytics._core._state.prepare() || !analytics._requirePersonProcessing()) return;
|
|
28
|
+
analytics.capture('$groupidentify', {
|
|
29
|
+
$group_type: type,
|
|
30
|
+
$group_key: key,
|
|
31
|
+
$group_set: properties
|
|
32
|
+
}, options);
|
|
33
|
+
};
|
|
34
|
+
const resetGroups = (posthog)=>{
|
|
35
|
+
const analytics = analyticsOf(posthog);
|
|
36
|
+
if (!analytics?._canMutate()) return;
|
|
37
|
+
analytics._core._state.resetGroups();
|
|
38
|
+
analytics._groupsResetPublisher.publish(void 0);
|
|
39
|
+
};
|
|
40
|
+
export { group, groupIdentify, resetGroups };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IPostHog } from '../../core/types';
|
|
2
|
+
/** Enables person processing for the current identity without identifying it. */
|
|
3
|
+
export declare const createPersonProfile: (posthog: IPostHog) => void;
|
|
4
|
+
/** Sets person properties for the current identity. */
|
|
5
|
+
export declare const setPersonProperties: (posthog: IPostHog, set?: Record<string, unknown>, setOnce?: Record<string, unknown>) => void;
|
|
6
|
+
/** Removes person properties from the current identity. */
|
|
7
|
+
export declare const unsetPersonProperties: (posthog: IPostHog, names: string | readonly string[]) => void;
|
|
8
|
+
/** Marks the current person as an internal or test user. */
|
|
9
|
+
export declare const setInternalOrTestUser: (posthog: IPostHog) => void;
|
|
10
|
+
/** Links another distinct ID to the current person without changing the current identity. */
|
|
11
|
+
export declare const alias: (posthog: IPostHog, aliasId: string) => void;
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
alias: ()=>alias,
|
|
32
|
+
createPersonProfile: ()=>createPersonProfile,
|
|
33
|
+
setInternalOrTestUser: ()=>setInternalOrTestUser,
|
|
34
|
+
setPersonProperties: ()=>setPersonProperties,
|
|
35
|
+
unsetPersonProperties: ()=>unsetPersonProperties
|
|
36
|
+
});
|
|
37
|
+
const external_analytics_core_js_namespaceObject = require("./analytics-core.js");
|
|
38
|
+
const person_processing_js_namespaceObject = require("./properties/person-processing.js");
|
|
39
|
+
const createPersonProfile = (posthog)=>{
|
|
40
|
+
const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
|
|
41
|
+
if (!analytics?._canMutate() || analytics._hasPersonProcessing()) return;
|
|
42
|
+
const properties = (0, person_processing_js_namespaceObject.snapshotPersonProperties)(analytics._core._state.distinctId, {}, {});
|
|
43
|
+
if (properties) analytics._setPersonProperties(properties);
|
|
44
|
+
};
|
|
45
|
+
const setPersonProperties = (posthog, set, setOnce)=>{
|
|
46
|
+
const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
|
|
47
|
+
if (!analytics?._canMutate()) return;
|
|
48
|
+
const properties = (0, person_processing_js_namespaceObject.snapshotPersonProperties)(analytics._core._state.distinctId, set, setOnce);
|
|
49
|
+
if (!properties) return void posthog.logger.warn('Person properties must be JSON-serializable objects');
|
|
50
|
+
if (Object.keys(properties.set).length || Object.keys(properties.setOnce).length) analytics._setPersonProperties(properties);
|
|
51
|
+
};
|
|
52
|
+
const unsetPersonProperties = (posthog, names)=>{
|
|
53
|
+
const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
|
|
54
|
+
if (!analytics?._canMutate()) return;
|
|
55
|
+
const properties = (0, person_processing_js_namespaceObject.personPropertyNames)(names);
|
|
56
|
+
if (!properties.length || !analytics._requirePersonProcessing()) return;
|
|
57
|
+
analytics._lastPersonProperties = void 0;
|
|
58
|
+
analytics._changePropertiesPublisher.publish({
|
|
59
|
+
unset: properties
|
|
60
|
+
});
|
|
61
|
+
analytics._capture('$set', {
|
|
62
|
+
$unset: properties
|
|
63
|
+
}, {}, false, {
|
|
64
|
+
signature: void 0
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
const setInternalOrTestUser = (posthog)=>setPersonProperties(posthog, {
|
|
68
|
+
$internal_or_test_user: true
|
|
69
|
+
});
|
|
70
|
+
const alias = (posthog, aliasId)=>{
|
|
71
|
+
const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
|
|
72
|
+
if (!analytics || !(0, external_analytics_core_js_namespaceObject.isValidDistinctId)(aliasId) || !posthog.canCapture) return;
|
|
73
|
+
if (analytics._requirePersonProcessing()) analytics._capture('$create_alias', {
|
|
74
|
+
alias: aliasId
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
exports.alias = __webpack_exports__.alias;
|
|
78
|
+
exports.createPersonProfile = __webpack_exports__.createPersonProfile;
|
|
79
|
+
exports.setInternalOrTestUser = __webpack_exports__.setInternalOrTestUser;
|
|
80
|
+
exports.setPersonProperties = __webpack_exports__.setPersonProperties;
|
|
81
|
+
exports.unsetPersonProperties = __webpack_exports__.unsetPersonProperties;
|
|
82
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
83
|
+
"alias",
|
|
84
|
+
"createPersonProfile",
|
|
85
|
+
"setInternalOrTestUser",
|
|
86
|
+
"setPersonProperties",
|
|
87
|
+
"unsetPersonProperties"
|
|
88
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
89
|
+
Object.defineProperty(exports, '__esModule', {
|
|
90
|
+
value: true
|
|
91
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { analyticsOf, isValidDistinctId } from "./analytics-core.mjs";
|
|
2
|
+
import { personPropertyNames, snapshotPersonProperties } from "./properties/person-processing.mjs";
|
|
3
|
+
const createPersonProfile = (posthog)=>{
|
|
4
|
+
const analytics = analyticsOf(posthog);
|
|
5
|
+
if (!analytics?._canMutate() || analytics._hasPersonProcessing()) return;
|
|
6
|
+
const properties = snapshotPersonProperties(analytics._core._state.distinctId, {}, {});
|
|
7
|
+
if (properties) analytics._setPersonProperties(properties);
|
|
8
|
+
};
|
|
9
|
+
const setPersonProperties = (posthog, set, setOnce)=>{
|
|
10
|
+
const analytics = analyticsOf(posthog);
|
|
11
|
+
if (!analytics?._canMutate()) return;
|
|
12
|
+
const properties = snapshotPersonProperties(analytics._core._state.distinctId, set, setOnce);
|
|
13
|
+
if (!properties) return void posthog.logger.warn('Person properties must be JSON-serializable objects');
|
|
14
|
+
if (Object.keys(properties.set).length || Object.keys(properties.setOnce).length) analytics._setPersonProperties(properties);
|
|
15
|
+
};
|
|
16
|
+
const unsetPersonProperties = (posthog, names)=>{
|
|
17
|
+
const analytics = analyticsOf(posthog);
|
|
18
|
+
if (!analytics?._canMutate()) return;
|
|
19
|
+
const properties = personPropertyNames(names);
|
|
20
|
+
if (!properties.length || !analytics._requirePersonProcessing()) return;
|
|
21
|
+
analytics._lastPersonProperties = void 0;
|
|
22
|
+
analytics._changePropertiesPublisher.publish({
|
|
23
|
+
unset: properties
|
|
24
|
+
});
|
|
25
|
+
analytics._capture('$set', {
|
|
26
|
+
$unset: properties
|
|
27
|
+
}, {}, false, {
|
|
28
|
+
signature: void 0
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const setInternalOrTestUser = (posthog)=>setPersonProperties(posthog, {
|
|
32
|
+
$internal_or_test_user: true
|
|
33
|
+
});
|
|
34
|
+
const alias = (posthog, aliasId)=>{
|
|
35
|
+
const analytics = analyticsOf(posthog);
|
|
36
|
+
if (!analytics || !isValidDistinctId(aliasId) || !posthog.canCapture) return;
|
|
37
|
+
if (analytics._requirePersonProcessing()) analytics._capture('$create_alias', {
|
|
38
|
+
alias: aliasId
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export { alias, createPersonProfile, setInternalOrTestUser, setPersonProperties, unsetPersonProperties };
|
|
@@ -92,15 +92,11 @@ const autocapture = (options = {})=>{
|
|
|
92
92
|
});
|
|
93
93
|
const extension = {
|
|
94
94
|
name: 'autocapture',
|
|
95
|
-
|
|
96
|
-
autocapture: shared
|
|
97
|
-
},
|
|
98
|
-
async setup (client) {
|
|
99
|
-
await client.resolveExtension('analytics');
|
|
95
|
+
setup (client) {
|
|
100
96
|
if (disposed) return;
|
|
101
97
|
const selectors = client.surveys?.getElementSelectors?.();
|
|
102
98
|
if (selectors) extension.setElementSelectors(selectors);
|
|
103
|
-
shared.setup(client
|
|
99
|
+
shared.setup(client);
|
|
104
100
|
},
|
|
105
101
|
setElementSelectors: (selectors)=>shared.setElementSelectors(new Set(selectors)),
|
|
106
102
|
dispose: ()=>{
|
|
@@ -60,15 +60,11 @@ const autocapture = (options = {})=>{
|
|
|
60
60
|
});
|
|
61
61
|
const extension = {
|
|
62
62
|
name: 'autocapture',
|
|
63
|
-
|
|
64
|
-
autocapture: shared
|
|
65
|
-
},
|
|
66
|
-
async setup (client) {
|
|
67
|
-
await client.resolveExtension('analytics');
|
|
63
|
+
setup (client) {
|
|
68
64
|
if (disposed) return;
|
|
69
65
|
const selectors = client.surveys?.getElementSelectors?.();
|
|
70
66
|
if (selectors) extension.setElementSelectors(selectors);
|
|
71
|
-
shared.setup(client
|
|
67
|
+
shared.setup(client);
|
|
72
68
|
},
|
|
73
69
|
setElementSelectors: (selectors)=>shared.setElementSelectors(new Set(selectors)),
|
|
74
70
|
dispose: ()=>{
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { FeatureFlags } from './flags-token';
|
|
2
|
-
/** SDK-specific flags configuration
|
|
2
|
+
/** SDK-specific flags configuration read by surveys. Person properties are read from the shared client store. */
|
|
3
3
|
export interface FlagsExtension extends FeatureFlags {
|
|
4
4
|
getSurveyContext(): {
|
|
5
5
|
remoteEvaluation: boolean;
|
|
6
|
-
personProperties: Record<string, unknown> | undefined;
|
|
7
6
|
};
|
|
8
7
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Disposable, ExtensionToken } from '@posthog/browser-common';
|
|
2
2
|
import type { FeatureFlagResult, FeatureFlagsReloadResult, FlagsCallback, JsonType } from './flags-options';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BrowserExtension } from '../../core/context/browser-client';
|
|
4
|
+
import type { IPostHog } from '../../core/types';
|
|
4
5
|
export interface FeatureFlags extends BrowserExtension {
|
|
5
|
-
setup(client:
|
|
6
|
+
setup(client: IPostHog): void | Promise<void>;
|
|
6
7
|
getFeatureFlag(key: string): FeatureFlagResult | undefined;
|
|
7
8
|
/** Refresh remotely and await its outcome. Calls during an active evaluation wait for a follow-up request. */
|
|
8
9
|
reloadFeatureFlags(): Promise<FeatureFlagsReloadResult>;
|
|
@@ -31,7 +31,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
FeatureFlagsExtension: ()=>external_flags_token_js_namespaceObject.FeatureFlagsExtension,
|
|
32
32
|
flags: ()=>flags
|
|
33
33
|
});
|
|
34
|
-
const constants_namespaceObject = require("@posthog/browser-common/constants");
|
|
35
34
|
const feature_flags_namespaceObject = require("@posthog/browser-common/feature-flags");
|
|
36
35
|
const extension_tokens_namespaceObject = require("@posthog/browser-common/extension-tokens");
|
|
37
36
|
const external_flags_token_js_namespaceObject = require("./flags-token.js");
|
|
@@ -63,18 +62,14 @@ const flags = (options = {})=>{
|
|
|
63
62
|
const extension = {
|
|
64
63
|
name: external_flags_token_js_namespaceObject.FeatureFlagsExtension,
|
|
65
64
|
bindings: {
|
|
66
|
-
featureFlags: shared,
|
|
67
65
|
[extension_tokens_namespaceObject.FeatureFlagsCommonExtension]: shared
|
|
68
66
|
},
|
|
69
67
|
getSurveyContext: ()=>({
|
|
70
|
-
remoteEvaluation: !config.featureFlagsDisabled
|
|
71
|
-
personProperties: client?.kv.get(constants_namespaceObject.STORED_PERSON_PROPERTIES_KEY)
|
|
68
|
+
remoteEvaluation: !config.featureFlagsDisabled
|
|
72
69
|
}),
|
|
73
70
|
setup: async (value)=>{
|
|
74
71
|
client = value;
|
|
75
|
-
await
|
|
76
|
-
if (disposed) return;
|
|
77
|
-
await shared.setup(value.sharedClient);
|
|
72
|
+
await shared.setup(value);
|
|
78
73
|
if (disposed) return;
|
|
79
74
|
subscriptions.push(value.onIdentify(({ distinctId, previousDistinctId, wasIdentified })=>{
|
|
80
75
|
if (distinctId !== previousDistinctId) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { STORED_PERSON_PROPERTIES_KEY } from "@posthog/browser-common/constants";
|
|
2
1
|
import { PostHogFeatureFlags } from "@posthog/browser-common/feature-flags";
|
|
3
2
|
import { FeatureFlagsCommonExtension } from "@posthog/browser-common/extension-tokens";
|
|
4
3
|
import { FeatureFlagsExtension } from "./flags-token.mjs";
|
|
@@ -30,18 +29,14 @@ const flags = (options = {})=>{
|
|
|
30
29
|
const extension = {
|
|
31
30
|
name: FeatureFlagsExtension,
|
|
32
31
|
bindings: {
|
|
33
|
-
featureFlags: shared,
|
|
34
32
|
[FeatureFlagsCommonExtension]: shared
|
|
35
33
|
},
|
|
36
34
|
getSurveyContext: ()=>({
|
|
37
|
-
remoteEvaluation: !config.featureFlagsDisabled
|
|
38
|
-
personProperties: client?.kv.get(STORED_PERSON_PROPERTIES_KEY)
|
|
35
|
+
remoteEvaluation: !config.featureFlagsDisabled
|
|
39
36
|
}),
|
|
40
37
|
setup: async (value)=>{
|
|
41
38
|
client = value;
|
|
42
|
-
await
|
|
43
|
-
if (disposed) return;
|
|
44
|
-
await shared.setup(value.sharedClient);
|
|
39
|
+
await shared.setup(value);
|
|
45
40
|
if (disposed) return;
|
|
46
41
|
subscriptions.push(value.onIdentify(({ distinctId, previousDistinctId, wasIdentified })=>{
|
|
47
42
|
if (distinctId !== previousDistinctId) {
|
|
@@ -91,18 +91,15 @@ const logs = (options = {})=>{
|
|
|
91
91
|
};
|
|
92
92
|
return {
|
|
93
93
|
name: 'logs',
|
|
94
|
-
bindings: {
|
|
95
|
-
logs: shared
|
|
96
|
-
},
|
|
97
94
|
setup: async (value)=>{
|
|
98
|
-
environment.client = value
|
|
95
|
+
environment.client = value;
|
|
99
96
|
try {
|
|
100
97
|
environment.browserWindow = globalThis.window;
|
|
101
98
|
} catch {}
|
|
102
99
|
subscriptions.push(value.onReset(()=>shared.reset()), value.onConsentChange(({ current })=>{
|
|
103
100
|
if ('denied' === current) shared.reset();
|
|
104
101
|
}));
|
|
105
|
-
await shared.setup(value
|
|
102
|
+
await shared.setup(value);
|
|
106
103
|
if (environment.disposed) return;
|
|
107
104
|
environment.browserWindow?.addEventListener('pagehide', pagehide);
|
|
108
105
|
},
|
|
@@ -59,18 +59,15 @@ const logs = (options = {})=>{
|
|
|
59
59
|
};
|
|
60
60
|
return {
|
|
61
61
|
name: 'logs',
|
|
62
|
-
bindings: {
|
|
63
|
-
logs: shared
|
|
64
|
-
},
|
|
65
62
|
setup: async (value)=>{
|
|
66
|
-
environment.client = value
|
|
63
|
+
environment.client = value;
|
|
67
64
|
try {
|
|
68
65
|
environment.browserWindow = globalThis.window;
|
|
69
66
|
} catch {}
|
|
70
67
|
subscriptions.push(value.onReset(()=>shared.reset()), value.onConsentChange(({ current })=>{
|
|
71
68
|
if ('denied' === current) shared.reset();
|
|
72
69
|
}));
|
|
73
|
-
await shared.setup(value
|
|
70
|
+
await shared.setup(value);
|
|
74
71
|
if (environment.disposed) return;
|
|
75
72
|
environment.browserWindow?.addEventListener('pagehide', pagehide);
|
|
76
73
|
},
|
|
@@ -30,11 +30,11 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
createSurveys: ()=>createSurveys
|
|
32
32
|
});
|
|
33
|
-
const constants_namespaceObject = require("@posthog/browser-common/constants");
|
|
34
33
|
const surveys_namespaceObject = require("@posthog/browser-common/surveys");
|
|
35
34
|
const survey_utils_namespaceObject = require("@posthog/browser-common/utils/survey-utils");
|
|
36
35
|
const survey_event_receiver_namespaceObject = require("@posthog/browser-common/survey-event-receiver");
|
|
37
36
|
const url_targeting_utils_namespaceObject = require("@posthog/browser-common/utils/url-targeting-utils");
|
|
37
|
+
const analytics_core_js_namespaceObject = require("../analytics/analytics-core.js");
|
|
38
38
|
const external_surveys_options_js_namespaceObject = require("./surveys-options.js");
|
|
39
39
|
const createSurveys = (options, load)=>{
|
|
40
40
|
const config = (0, external_surveys_options_js_namespaceObject.snapshotSurveysOptions)(options);
|
|
@@ -147,30 +147,13 @@ const createSurveys = (options, load)=>{
|
|
|
147
147
|
};
|
|
148
148
|
return {
|
|
149
149
|
name: 'surveys',
|
|
150
|
-
bindings: {
|
|
151
|
-
surveys: shared
|
|
152
|
-
},
|
|
153
150
|
setup: async (value)=>{
|
|
154
151
|
client = value;
|
|
155
|
-
await value.resolveExtension('analytics');
|
|
156
|
-
if (disposed) return;
|
|
157
152
|
await value.kv.initialize();
|
|
158
153
|
if (disposed) return;
|
|
159
154
|
resetSubscription = value.onReset(reset);
|
|
160
|
-
const renderClient = Object.create(value.sharedClient);
|
|
161
|
-
const read = (key)=>key === constants_namespaceObject.STORED_PERSON_PROPERTIES_KEY ? getFlagsContext()?.personProperties : value.kv.get(key);
|
|
162
|
-
const renderKv = {
|
|
163
|
-
...value.kv,
|
|
164
|
-
get: (keys)=>'string' == typeof keys ? read(keys) : Object.fromEntries(keys.map((key)=>[
|
|
165
|
-
key,
|
|
166
|
-
read(key)
|
|
167
|
-
]))
|
|
168
|
-
};
|
|
169
|
-
Object.defineProperty(renderClient, 'kv', {
|
|
170
|
-
value: renderKv
|
|
171
|
-
});
|
|
172
155
|
runtimeHost = {
|
|
173
|
-
client:
|
|
156
|
+
client: value,
|
|
174
157
|
get config () {
|
|
175
158
|
return source.get();
|
|
176
159
|
},
|
|
@@ -183,9 +166,9 @@ const createSurveys = (options, load)=>{
|
|
|
183
166
|
if (remoteEnabled && !disposed) manager?.startAutomaticDisplay?.();
|
|
184
167
|
}
|
|
185
168
|
});
|
|
186
|
-
await shared.setup(value
|
|
169
|
+
await shared.setup(value);
|
|
187
170
|
if (disposed) return void shared.dispose();
|
|
188
|
-
teardownSubscription =
|
|
171
|
+
teardownSubscription = (0, analytics_core_js_namespaceObject.analyticsOf)(value)?.onBeforeTeardown(()=>shared.handlePageUnload());
|
|
189
172
|
if ("u" > typeof window) window.addEventListener('pagehide', pagehide);
|
|
190
173
|
},
|
|
191
174
|
getSurveys: (callback, forceReload)=>run(callback, (notify)=>shared.getSurveys(notify, forceReload)),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { STORED_PERSON_PROPERTIES_KEY } from "@posthog/browser-common/constants";
|
|
2
1
|
import { PostHogSurveys } from "@posthog/browser-common/surveys";
|
|
3
2
|
import { DEFAULT_DISPLAY_SURVEY_OPTIONS } from "@posthog/browser-common/utils/survey-utils";
|
|
4
3
|
import { SurveyEventReceiver } from "@posthog/browser-common/survey-event-receiver";
|
|
5
4
|
import { getTargetingUrl } from "@posthog/browser-common/utils/url-targeting-utils";
|
|
5
|
+
import { analyticsOf } from "../analytics/analytics-core.mjs";
|
|
6
6
|
import { snapshotSurveysOptions } from "./surveys-options.mjs";
|
|
7
7
|
const createSurveys = (options, load)=>{
|
|
8
8
|
const config = snapshotSurveysOptions(options);
|
|
@@ -115,30 +115,13 @@ const createSurveys = (options, load)=>{
|
|
|
115
115
|
};
|
|
116
116
|
return {
|
|
117
117
|
name: 'surveys',
|
|
118
|
-
bindings: {
|
|
119
|
-
surveys: shared
|
|
120
|
-
},
|
|
121
118
|
setup: async (value)=>{
|
|
122
119
|
client = value;
|
|
123
|
-
await value.resolveExtension('analytics');
|
|
124
|
-
if (disposed) return;
|
|
125
120
|
await value.kv.initialize();
|
|
126
121
|
if (disposed) return;
|
|
127
122
|
resetSubscription = value.onReset(reset);
|
|
128
|
-
const renderClient = Object.create(value.sharedClient);
|
|
129
|
-
const read = (key)=>key === STORED_PERSON_PROPERTIES_KEY ? getFlagsContext()?.personProperties : value.kv.get(key);
|
|
130
|
-
const renderKv = {
|
|
131
|
-
...value.kv,
|
|
132
|
-
get: (keys)=>'string' == typeof keys ? read(keys) : Object.fromEntries(keys.map((key)=>[
|
|
133
|
-
key,
|
|
134
|
-
read(key)
|
|
135
|
-
]))
|
|
136
|
-
};
|
|
137
|
-
Object.defineProperty(renderClient, 'kv', {
|
|
138
|
-
value: renderKv
|
|
139
|
-
});
|
|
140
123
|
runtimeHost = {
|
|
141
|
-
client:
|
|
124
|
+
client: value,
|
|
142
125
|
get config () {
|
|
143
126
|
return source.get();
|
|
144
127
|
},
|
|
@@ -151,9 +134,9 @@ const createSurveys = (options, load)=>{
|
|
|
151
134
|
if (remoteEnabled && !disposed) manager?.startAutomaticDisplay?.();
|
|
152
135
|
}
|
|
153
136
|
});
|
|
154
|
-
await shared.setup(value
|
|
137
|
+
await shared.setup(value);
|
|
155
138
|
if (disposed) return void shared.dispose();
|
|
156
|
-
teardownSubscription =
|
|
139
|
+
teardownSubscription = analyticsOf(value)?.onBeforeTeardown(()=>shared.handlePageUnload());
|
|
157
140
|
if ("u" > typeof window) window.addEventListener('pagehide', pagehide);
|
|
158
141
|
},
|
|
159
142
|
getSurveys: (callback, forceReload)=>run(callback, (notify)=>shared.getSurveys(notify, forceReload)),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A small, extension-based PostHog client for modern browsers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,11 +33,6 @@
|
|
|
33
33
|
"require": "./dist/products/flags/flags.js",
|
|
34
34
|
"import": "./dist/products/flags/flags.mjs"
|
|
35
35
|
},
|
|
36
|
-
"./analytics": {
|
|
37
|
-
"types": "./dist/products/analytics/analytics.d.ts",
|
|
38
|
-
"require": "./dist/products/analytics/analytics.js",
|
|
39
|
-
"import": "./dist/products/analytics/analytics.mjs"
|
|
40
|
-
},
|
|
41
36
|
"./logs": {
|
|
42
37
|
"types": "./dist/products/logs/logs.d.ts",
|
|
43
38
|
"import": "./dist/products/logs/logs.mjs",
|
|
@@ -55,8 +50,8 @@
|
|
|
55
50
|
}
|
|
56
51
|
},
|
|
57
52
|
"dependencies": {
|
|
58
|
-
"@posthog/browser-common": "^0.
|
|
59
|
-
"@posthog/types": "^1.
|
|
53
|
+
"@posthog/browser-common": "^0.13.1",
|
|
54
|
+
"@posthog/types": "^1.427.1"
|
|
60
55
|
},
|
|
61
56
|
"devDependencies": {
|
|
62
57
|
"@playwright/test": "1.52.0",
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { CaptureOptions, CapturedEventInfo, Disposable, Listener } from '@posthog/browser-common';
|
|
2
|
-
import type { BrowserExtension } from '../../core/context/browser-client';
|
|
3
|
-
import type { CaptureSummary } from '../../core/types';
|
|
4
|
-
/** Application-facing analytics operations on one installed product instance. */
|
|
5
|
-
export interface IAnalytics extends BrowserExtension {
|
|
6
|
-
readonly isRateLimited: boolean;
|
|
7
|
-
readonly onEvent: Listener<CapturedEventInfo>;
|
|
8
|
-
/**
|
|
9
|
-
* Synchronous capture. False signals rate-limit backpressure; true does not acknowledge admission or delivery.
|
|
10
|
-
* Consent, filtering, invalid properties and queue limits can suppress an event while returning true.
|
|
11
|
-
*/
|
|
12
|
-
capture(event: string, properties?: Record<string, unknown> | null, options?: CaptureOptions): boolean;
|
|
13
|
-
captureImmediate(event: string, properties?: Record<string, unknown> | null, options?: CaptureOptions): Promise<CaptureSummary>;
|
|
14
|
-
identify(distinctId: string, set?: Record<string, unknown>, setOnce?: Record<string, unknown>): Promise<void>;
|
|
15
|
-
alias(alias: string): void;
|
|
16
|
-
group(type: string, key: string, properties?: Record<string, unknown>): Promise<void>;
|
|
17
|
-
groupIdentify(type: string, key: string | number, properties?: Record<string, unknown>, options?: CaptureOptions): void;
|
|
18
|
-
resetGroups(): void;
|
|
19
|
-
reset(): void;
|
|
20
|
-
createPersonProfile(): void;
|
|
21
|
-
setPersonProperties(set?: Record<string, unknown>, setOnce?: Record<string, unknown>): void;
|
|
22
|
-
unsetPersonProperties(names: string | readonly string[]): void;
|
|
23
|
-
setInternalOrTestUser(): void;
|
|
24
|
-
register(properties: Record<string, unknown>): void;
|
|
25
|
-
registerOnce(properties: Record<string, unknown>, defaultValue?: unknown): void;
|
|
26
|
-
registerForSession(properties: Record<string, unknown>): void;
|
|
27
|
-
unregisterForSession(property: string): void;
|
|
28
|
-
unregister(property: string): void;
|
|
29
|
-
getProperty(property: string): unknown;
|
|
30
|
-
registerDynamicEventProperties(producer: () => Record<string, unknown>): Disposable;
|
|
31
|
-
flush(): Promise<void>;
|
|
32
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.r = (exports1)=>{
|
|
5
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
-
value: 'Module'
|
|
7
|
-
});
|
|
8
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
-
value: true
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
})();
|
|
13
|
-
var __webpack_exports__ = {};
|
|
14
|
-
__webpack_require__.r(__webpack_exports__);
|
|
15
|
-
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
-
Object.defineProperty(exports, '__esModule', {
|
|
17
|
-
value: true
|
|
18
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { AnalyticsDeliveryFactory, IAnalyticsExtension } from './analytics-internal';
|
|
2
|
-
import type { AutomaticAnalyticsOptions } from './analytics-options';
|
|
3
|
-
/** Creates one analytics instance, with delivery supplied statically or loaded later. */
|
|
4
|
-
export declare const createAnalyticsExtension: (options?: AutomaticAnalyticsOptions, load?: () => Promise<AnalyticsDeliveryFactory>, deliveryFactory?: AnalyticsDeliveryFactory) => IAnalyticsExtension;
|