posthog-js-lite 2.4.0 → 2.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/CHANGELOG.md +5 -0
- package/lib/index.cjs.js +35 -8
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +20 -3
- package/lib/index.esm.js +35 -8
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +17 -2
- package/lib/posthog-core/src/types.d.ts +3 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -30,7 +30,9 @@ declare enum PostHogPersistedProperty {
|
|
|
30
30
|
SessionId = "session_id",
|
|
31
31
|
SessionLastTimestamp = "session_timestamp",
|
|
32
32
|
PersonProperties = "person_properties",
|
|
33
|
-
GroupProperties = "group_properties"
|
|
33
|
+
GroupProperties = "group_properties",
|
|
34
|
+
InstalledAppBuild = "installed_app_build",
|
|
35
|
+
InstalledAppVersion = "installed_app_version"
|
|
34
36
|
}
|
|
35
37
|
declare type PostHogFetchOptions = {
|
|
36
38
|
method: 'GET' | 'POST' | 'PUT' | 'PATCH';
|
|
@@ -173,6 +175,7 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
173
175
|
private flagCallReported;
|
|
174
176
|
protected _decideResponsePromise?: Promise<PostHogDecideResponse | undefined>;
|
|
175
177
|
protected _sessionExpirationTimeSeconds: number;
|
|
178
|
+
protected sessionProps: PostHogEventProperties;
|
|
176
179
|
constructor(apiKey: string, options?: PosthogCoreOptions);
|
|
177
180
|
protected setupBootstrap(options?: Partial<PosthogCoreOptions>): void;
|
|
178
181
|
private get props();
|
|
@@ -182,15 +185,19 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
182
185
|
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
183
186
|
reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
|
|
184
187
|
protected getCommonEventProperties(): any;
|
|
185
|
-
|
|
188
|
+
enrichProperties(properties?: PostHogEventProperties): any;
|
|
186
189
|
getSessionId(): string | undefined;
|
|
187
190
|
resetSessionId(): void;
|
|
188
191
|
getAnonymousId(): string;
|
|
189
192
|
getDistinctId(): string;
|
|
193
|
+
unregister(property: string): void;
|
|
190
194
|
register(properties: {
|
|
191
195
|
[key: string]: any;
|
|
192
196
|
}): void;
|
|
193
|
-
|
|
197
|
+
registerForSession(properties: {
|
|
198
|
+
[key: string]: any;
|
|
199
|
+
}): void;
|
|
200
|
+
unregisterForSession(property: string): void;
|
|
194
201
|
/***
|
|
195
202
|
*** TRACKING
|
|
196
203
|
***/
|
|
@@ -211,9 +218,19 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
211
218
|
/***
|
|
212
219
|
* PROPERTIES
|
|
213
220
|
***/
|
|
221
|
+
setPersonPropertiesForFlags(properties: {
|
|
222
|
+
[type: string]: string;
|
|
223
|
+
}): this;
|
|
224
|
+
resetPersonPropertiesForFlags(): void;
|
|
225
|
+
/** @deprecated - Renamed to setPersonPropertiesForFlags */
|
|
214
226
|
personProperties(properties: {
|
|
215
227
|
[type: string]: string;
|
|
216
228
|
}): this;
|
|
229
|
+
setGroupPropertiesForFlags(properties: {
|
|
230
|
+
[type: string]: Record<string, string>;
|
|
231
|
+
}): this;
|
|
232
|
+
resetGroupPropertiesForFlags(): void;
|
|
233
|
+
/** @deprecated - Renamed to setGroupPropertiesForFlags */
|
|
217
234
|
groupProperties(properties: {
|
|
218
235
|
[type: string]: Record<string, string>;
|
|
219
236
|
}): this;
|
package/lib/index.esm.js
CHANGED
|
@@ -154,6 +154,8 @@ var PostHogPersistedProperty;
|
|
|
154
154
|
PostHogPersistedProperty["SessionLastTimestamp"] = "session_timestamp";
|
|
155
155
|
PostHogPersistedProperty["PersonProperties"] = "person_properties";
|
|
156
156
|
PostHogPersistedProperty["GroupProperties"] = "group_properties";
|
|
157
|
+
PostHogPersistedProperty["InstalledAppBuild"] = "installed_app_build";
|
|
158
|
+
PostHogPersistedProperty["InstalledAppVersion"] = "installed_app_version";
|
|
157
159
|
})(PostHogPersistedProperty || (PostHogPersistedProperty = {}));
|
|
158
160
|
|
|
159
161
|
function assert(truthyValue, message) {
|
|
@@ -712,7 +714,10 @@ var PostHogFetchHttpError = /** @class */ (function (_super) {
|
|
|
712
714
|
var PostHogFetchNetworkError = /** @class */ (function (_super) {
|
|
713
715
|
__extends(PostHogFetchNetworkError, _super);
|
|
714
716
|
function PostHogFetchNetworkError(error) {
|
|
715
|
-
var _this =
|
|
717
|
+
var _this =
|
|
718
|
+
// TRICKY: "cause" is a newer property but is just ignored otherwise. Cast to any to ignore the type issue.
|
|
719
|
+
// @ts-ignore
|
|
720
|
+
_super.call(this, 'Network error while fetching PostHog', error instanceof Error ? { cause: error } : {}) || this;
|
|
716
721
|
_this.error = error;
|
|
717
722
|
_this.name = 'PostHogFetchNetworkError';
|
|
718
723
|
return _this;
|
|
@@ -1162,6 +1167,7 @@ var PostHogCore = /** @class */ (function (_super) {
|
|
|
1162
1167
|
var disableGeoipOption = (_a = options === null || options === void 0 ? void 0 : options.disableGeoip) !== null && _a !== void 0 ? _a : false;
|
|
1163
1168
|
_this = _super.call(this, apiKey, __assign(__assign({}, options), { disableGeoip: disableGeoipOption })) || this;
|
|
1164
1169
|
_this.flagCallReported = {};
|
|
1170
|
+
_this.sessionProps = {};
|
|
1165
1171
|
_this.sendFeatureFlagEvent = (_b = options === null || options === void 0 ? void 0 : options.sendFeatureFlagEvent) !== null && _b !== void 0 ? _b : true;
|
|
1166
1172
|
_this._sessionExpirationTimeSeconds = (_c = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _c !== void 0 ? _c : 1800; // 30 minutes
|
|
1167
1173
|
return _this;
|
|
@@ -1203,6 +1209,7 @@ var PostHogCore = /** @class */ (function (_super) {
|
|
|
1203
1209
|
});
|
|
1204
1210
|
PostHogCore.prototype.clearProps = function () {
|
|
1205
1211
|
this.props = undefined;
|
|
1212
|
+
this.sessionProps = {};
|
|
1206
1213
|
};
|
|
1207
1214
|
PostHogCore.prototype.on = function (event, cb) {
|
|
1208
1215
|
return this._events.on(event, cb);
|
|
@@ -1230,7 +1237,7 @@ var PostHogCore = /** @class */ (function (_super) {
|
|
|
1230
1237
|
return __assign(__assign({ $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties), _super.prototype.getCommonEventProperties.call(this));
|
|
1231
1238
|
};
|
|
1232
1239
|
PostHogCore.prototype.enrichProperties = function (properties) {
|
|
1233
|
-
return __assign(__assign(__assign(__assign({}, this.props), (properties || {})), this.getCommonEventProperties()), { $session_id: this.getSessionId() });
|
|
1240
|
+
return __assign(__assign(__assign(__assign(__assign({}, this.props), this.sessionProps), (properties || {})), this.getCommonEventProperties()), { $session_id: this.getSessionId() });
|
|
1234
1241
|
};
|
|
1235
1242
|
PostHogCore.prototype.getSessionId = function () {
|
|
1236
1243
|
var sessionId = this.getPersistedProperty(PostHogPersistedProperty.SessionId);
|
|
@@ -1256,13 +1263,19 @@ var PostHogCore = /** @class */ (function (_super) {
|
|
|
1256
1263
|
PostHogCore.prototype.getDistinctId = function () {
|
|
1257
1264
|
return this.getPersistedProperty(PostHogPersistedProperty.DistinctId) || this.getAnonymousId();
|
|
1258
1265
|
};
|
|
1266
|
+
PostHogCore.prototype.unregister = function (property) {
|
|
1267
|
+
delete this.props[property];
|
|
1268
|
+
this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
|
|
1269
|
+
};
|
|
1259
1270
|
PostHogCore.prototype.register = function (properties) {
|
|
1260
1271
|
this.props = __assign(__assign({}, this.props), properties);
|
|
1261
1272
|
this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
|
|
1262
1273
|
};
|
|
1263
|
-
PostHogCore.prototype.
|
|
1264
|
-
|
|
1265
|
-
|
|
1274
|
+
PostHogCore.prototype.registerForSession = function (properties) {
|
|
1275
|
+
this.sessionProps = __assign(__assign({}, this.sessionProps), properties);
|
|
1276
|
+
};
|
|
1277
|
+
PostHogCore.prototype.unregisterForSession = function (property) {
|
|
1278
|
+
delete this.sessionProps[property];
|
|
1266
1279
|
};
|
|
1267
1280
|
/***
|
|
1268
1281
|
*** TRACKING
|
|
@@ -1342,13 +1355,20 @@ var PostHogCore = /** @class */ (function (_super) {
|
|
|
1342
1355
|
/***
|
|
1343
1356
|
* PROPERTIES
|
|
1344
1357
|
***/
|
|
1345
|
-
PostHogCore.prototype.
|
|
1358
|
+
PostHogCore.prototype.setPersonPropertiesForFlags = function (properties) {
|
|
1346
1359
|
// Get persisted person properties
|
|
1347
1360
|
var existingProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
|
|
1348
1361
|
this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, __assign(__assign({}, existingProperties), properties));
|
|
1349
1362
|
return this;
|
|
1350
1363
|
};
|
|
1351
|
-
PostHogCore.prototype.
|
|
1364
|
+
PostHogCore.prototype.resetPersonPropertiesForFlags = function () {
|
|
1365
|
+
this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, {});
|
|
1366
|
+
};
|
|
1367
|
+
/** @deprecated - Renamed to setPersonPropertiesForFlags */
|
|
1368
|
+
PostHogCore.prototype.personProperties = function (properties) {
|
|
1369
|
+
return this.setPersonPropertiesForFlags(properties);
|
|
1370
|
+
};
|
|
1371
|
+
PostHogCore.prototype.setGroupPropertiesForFlags = function (properties) {
|
|
1352
1372
|
// Get persisted group properties
|
|
1353
1373
|
var existingProperties = this.getPersistedProperty(PostHogPersistedProperty.GroupProperties) || {};
|
|
1354
1374
|
if (Object.keys(existingProperties).length !== 0) {
|
|
@@ -1360,6 +1380,13 @@ var PostHogCore = /** @class */ (function (_super) {
|
|
|
1360
1380
|
this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, __assign(__assign({}, existingProperties), properties));
|
|
1361
1381
|
return this;
|
|
1362
1382
|
};
|
|
1383
|
+
PostHogCore.prototype.resetGroupPropertiesForFlags = function () {
|
|
1384
|
+
this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, {});
|
|
1385
|
+
};
|
|
1386
|
+
/** @deprecated - Renamed to setGroupPropertiesForFlags */
|
|
1387
|
+
PostHogCore.prototype.groupProperties = function (properties) {
|
|
1388
|
+
return this.setGroupPropertiesForFlags(properties);
|
|
1389
|
+
};
|
|
1363
1390
|
/***
|
|
1364
1391
|
*** FEATURE FLAGS
|
|
1365
1392
|
***/
|
|
@@ -1551,7 +1578,7 @@ var PostHogCore = /** @class */ (function (_super) {
|
|
|
1551
1578
|
return PostHogCore;
|
|
1552
1579
|
}(PostHogCoreStateless));
|
|
1553
1580
|
|
|
1554
|
-
var version = "2.
|
|
1581
|
+
var version = "2.5.0";
|
|
1555
1582
|
|
|
1556
1583
|
function getContext(window) {
|
|
1557
1584
|
var context = {};
|