posthog-react-native 2.1.0 → 2.1.1
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 +3 -0
- package/lib/index.cjs.js +31 -6
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +9 -1
- package/lib/index.esm.js +31 -6
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +2 -0
- package/lib/posthog-core/src/types.d.ts +7 -1
- package/package.json +5 -4
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ declare type PosthogCoreOptions = {
|
|
|
9
9
|
enable?: boolean;
|
|
10
10
|
sendFeatureFlagEvent?: boolean;
|
|
11
11
|
preloadFeatureFlags?: boolean;
|
|
12
|
+
bootstrap?: {
|
|
13
|
+
distinctId?: string;
|
|
14
|
+
isIdentifiedId?: boolean;
|
|
15
|
+
featureFlags?: Record<string, boolean | string>;
|
|
16
|
+
};
|
|
12
17
|
fetchRetryCount?: number;
|
|
13
18
|
fetchRetryDelay?: number;
|
|
14
19
|
sessionExpirationTimeSeconds?: number;
|
|
@@ -34,7 +39,8 @@ declare type PostHogFetchOptions = {
|
|
|
34
39
|
headers: {
|
|
35
40
|
[key: string]: string;
|
|
36
41
|
};
|
|
37
|
-
body
|
|
42
|
+
body?: string;
|
|
43
|
+
signal?: AbortSignal;
|
|
38
44
|
};
|
|
39
45
|
declare type PostHogFetchResponse = {
|
|
40
46
|
status: number;
|
|
@@ -108,6 +114,7 @@ declare abstract class PostHogCore {
|
|
|
108
114
|
private _optoutOverride;
|
|
109
115
|
constructor(apiKey: string, options?: PosthogCoreOptions);
|
|
110
116
|
protected getCommonEventProperties(): any;
|
|
117
|
+
protected setupBootstrap(options?: Partial<PosthogCoreOptions>): void;
|
|
111
118
|
private get props();
|
|
112
119
|
private set props(value);
|
|
113
120
|
private clearProps;
|
|
@@ -158,6 +165,7 @@ declare abstract class PostHogCore {
|
|
|
158
165
|
***/
|
|
159
166
|
private decideAsync;
|
|
160
167
|
private _decideAsync;
|
|
168
|
+
private setKnownFeatureFlags;
|
|
161
169
|
getFeatureFlag(key: string): boolean | string | undefined;
|
|
162
170
|
getFeatureFlags(): PostHogDecideResponse['featureFlags'] | undefined;
|
|
163
171
|
isFeatureEnabled(key: string): boolean | undefined;
|
package/lib/index.esm.js
CHANGED
|
@@ -742,6 +742,26 @@ var PostHogCore = /** @class */ (function () {
|
|
|
742
742
|
}
|
|
743
743
|
return __assign({ $lib: this.getLibraryId(), $lib_version: this.getLibraryVersion(), $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties);
|
|
744
744
|
};
|
|
745
|
+
PostHogCore.prototype.setupBootstrap = function (options) {
|
|
746
|
+
var _a, _b, _c, _d;
|
|
747
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _a === void 0 ? void 0 : _a.distinctId) {
|
|
748
|
+
if ((_b = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _b === void 0 ? void 0 : _b.isIdentifiedId) {
|
|
749
|
+
this.setPersistedProperty(PostHogPersistedProperty.DistinctId, options.bootstrap.distinctId);
|
|
750
|
+
}
|
|
751
|
+
else {
|
|
752
|
+
this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, options.bootstrap.distinctId);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
if ((_c = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _c === void 0 ? void 0 : _c.featureFlags) {
|
|
756
|
+
var activeFlags = Object.keys(((_d = options.bootstrap) === null || _d === void 0 ? void 0 : _d.featureFlags) || {})
|
|
757
|
+
.filter(function (flag) { var _a, _b; return !!((_b = (_a = options.bootstrap) === null || _a === void 0 ? void 0 : _a.featureFlags) === null || _b === void 0 ? void 0 : _b[flag]); })
|
|
758
|
+
.reduce(function (res, key) {
|
|
759
|
+
var _a, _b;
|
|
760
|
+
return ((res[key] = ((_b = (_a = options.bootstrap) === null || _a === void 0 ? void 0 : _a.featureFlags) === null || _b === void 0 ? void 0 : _b[key]) || false), res);
|
|
761
|
+
}, {});
|
|
762
|
+
this.setKnownFeatureFlags(activeFlags);
|
|
763
|
+
}
|
|
764
|
+
};
|
|
745
765
|
Object.defineProperty(PostHogCore.prototype, "props", {
|
|
746
766
|
// NOTE: Props are lazy loaded from localstorage hence the complex getter setter logic
|
|
747
767
|
get: function () {
|
|
@@ -985,8 +1005,7 @@ var PostHogCore = /** @class */ (function () {
|
|
|
985
1005
|
.then(function (r) { return r.json(); })
|
|
986
1006
|
.then(function (res) {
|
|
987
1007
|
if (res.featureFlags) {
|
|
988
|
-
_this.
|
|
989
|
-
_this._events.emit('featureflags', res.featureFlags);
|
|
1008
|
+
_this.setKnownFeatureFlags(res.featureFlags);
|
|
990
1009
|
}
|
|
991
1010
|
return res;
|
|
992
1011
|
})
|
|
@@ -997,6 +1016,10 @@ var PostHogCore = /** @class */ (function () {
|
|
|
997
1016
|
});
|
|
998
1017
|
});
|
|
999
1018
|
};
|
|
1019
|
+
PostHogCore.prototype.setKnownFeatureFlags = function (featureFlags) {
|
|
1020
|
+
this.setPersistedProperty(PostHogPersistedProperty.FeatureFlags, featureFlags);
|
|
1021
|
+
this._events.emit('featureflags', featureFlags);
|
|
1022
|
+
};
|
|
1000
1023
|
PostHogCore.prototype.getFeatureFlag = function (key) {
|
|
1001
1024
|
var featureFlags = this.getFeatureFlags();
|
|
1002
1025
|
if (!featureFlags) {
|
|
@@ -1308,7 +1331,7 @@ var loadStorageAsync = function () {
|
|
|
1308
1331
|
return __generator(this, function (_a) {
|
|
1309
1332
|
switch (_a.label) {
|
|
1310
1333
|
case 0:
|
|
1311
|
-
uri = FileSystem.documentDirectory + POSTHOG_STORAGE_KEY;
|
|
1334
|
+
uri = (FileSystem.documentDirectory || '') + POSTHOG_STORAGE_KEY;
|
|
1312
1335
|
_a.label = 1;
|
|
1313
1336
|
|
|
1314
1337
|
case 1:
|
|
@@ -1345,7 +1368,7 @@ var persitStorageAsync = function (content) {
|
|
|
1345
1368
|
return __generator(this, function (_a) {
|
|
1346
1369
|
switch (_a.label) {
|
|
1347
1370
|
case 0:
|
|
1348
|
-
uri = FileSystem.documentDirectory + POSTHOG_STORAGE_KEY;
|
|
1371
|
+
uri = (FileSystem.documentDirectory || '') + POSTHOG_STORAGE_KEY;
|
|
1349
1372
|
data = {
|
|
1350
1373
|
version: POSTHOG_STORAGE_VERSION,
|
|
1351
1374
|
content: content
|
|
@@ -1408,7 +1431,7 @@ var preloadSemiAsyncStorage = function () {
|
|
|
1408
1431
|
return _preloadSemiAsyncStoragePromise;
|
|
1409
1432
|
};
|
|
1410
1433
|
|
|
1411
|
-
var version = "2.1.
|
|
1434
|
+
var version = "2.1.1";
|
|
1412
1435
|
|
|
1413
1436
|
var PostHog =
|
|
1414
1437
|
/** @class */
|
|
@@ -1426,6 +1449,8 @@ function (_super) {
|
|
|
1426
1449
|
// It is possible that the old library was used so we try to get the legacy distinctID
|
|
1427
1450
|
|
|
1428
1451
|
void preloadSemiAsyncStorage().then(function () {
|
|
1452
|
+
_this.setupBootstrap(options);
|
|
1453
|
+
|
|
1429
1454
|
if (!SemiAsyncStorage.getItem(PostHogPersistedProperty.AnonymousId)) {
|
|
1430
1455
|
getLegacyValues().then(function (legacyValues) {
|
|
1431
1456
|
if (legacyValues === null || legacyValues === void 0 ? void 0 : legacyValues.distinctId) {
|
|
@@ -1452,7 +1477,7 @@ function (_super) {
|
|
|
1452
1477
|
|
|
1453
1478
|
PostHog.prototype.setPersistedProperty = function (key, value) {
|
|
1454
1479
|
if (this._persistence === 'memory') {
|
|
1455
|
-
return this._memoryStorage.
|
|
1480
|
+
return this._memoryStorage.setProperty(key, value);
|
|
1456
1481
|
}
|
|
1457
1482
|
|
|
1458
1483
|
return value !== null ? SemiAsyncStorage.setItem(key, value) : SemiAsyncStorage.removeItem(key);
|