posthog-react-native 2.1.3 → 2.1.4
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/lib/index.cjs.js +50 -17
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +11 -1
- package/lib/index.esm.js +50 -17
- 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/lib/posthog-react-native/src/types.d.ts +2 -0
- package/package.json +2 -2
package/lib/index.cjs.js
CHANGED
|
@@ -772,6 +772,26 @@ var PostHogCore = /** @class */ (function () {
|
|
|
772
772
|
}
|
|
773
773
|
return __assign({ $lib: this.getLibraryId(), $lib_version: this.getLibraryVersion(), $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties);
|
|
774
774
|
};
|
|
775
|
+
PostHogCore.prototype.setupBootstrap = function (options) {
|
|
776
|
+
var _a, _b, _c, _d;
|
|
777
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _a === void 0 ? void 0 : _a.distinctId) {
|
|
778
|
+
if ((_b = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _b === void 0 ? void 0 : _b.isIdentifiedId) {
|
|
779
|
+
this.setPersistedProperty(PostHogPersistedProperty.DistinctId, options.bootstrap.distinctId);
|
|
780
|
+
}
|
|
781
|
+
else {
|
|
782
|
+
this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, options.bootstrap.distinctId);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if ((_c = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _c === void 0 ? void 0 : _c.featureFlags) {
|
|
786
|
+
var activeFlags = Object.keys(((_d = options.bootstrap) === null || _d === void 0 ? void 0 : _d.featureFlags) || {})
|
|
787
|
+
.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]); })
|
|
788
|
+
.reduce(function (res, key) {
|
|
789
|
+
var _a, _b;
|
|
790
|
+
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);
|
|
791
|
+
}, {});
|
|
792
|
+
this.setKnownFeatureFlags(activeFlags);
|
|
793
|
+
}
|
|
794
|
+
};
|
|
775
795
|
Object.defineProperty(PostHogCore.prototype, "props", {
|
|
776
796
|
// NOTE: Props are lazy loaded from localstorage hence the complex getter setter logic
|
|
777
797
|
get: function () {
|
|
@@ -1015,8 +1035,7 @@ var PostHogCore = /** @class */ (function () {
|
|
|
1015
1035
|
.then(function (r) { return r.json(); })
|
|
1016
1036
|
.then(function (res) {
|
|
1017
1037
|
if (res.featureFlags) {
|
|
1018
|
-
_this.
|
|
1019
|
-
_this._events.emit('featureflags', res.featureFlags);
|
|
1038
|
+
_this.setKnownFeatureFlags(res.featureFlags);
|
|
1020
1039
|
}
|
|
1021
1040
|
return res;
|
|
1022
1041
|
})
|
|
@@ -1027,6 +1046,10 @@ var PostHogCore = /** @class */ (function () {
|
|
|
1027
1046
|
});
|
|
1028
1047
|
});
|
|
1029
1048
|
};
|
|
1049
|
+
PostHogCore.prototype.setKnownFeatureFlags = function (featureFlags) {
|
|
1050
|
+
this.setPersistedProperty(PostHogPersistedProperty.FeatureFlags, featureFlags);
|
|
1051
|
+
this._events.emit('featureflags', featureFlags);
|
|
1052
|
+
};
|
|
1030
1053
|
PostHogCore.prototype.getFeatureFlag = function (key) {
|
|
1031
1054
|
var featureFlags = this.getFeatureFlags();
|
|
1032
1055
|
if (!featureFlags) {
|
|
@@ -1338,7 +1361,7 @@ var loadStorageAsync = function () {
|
|
|
1338
1361
|
return __generator(this, function (_a) {
|
|
1339
1362
|
switch (_a.label) {
|
|
1340
1363
|
case 0:
|
|
1341
|
-
uri = FileSystem__namespace.documentDirectory + POSTHOG_STORAGE_KEY;
|
|
1364
|
+
uri = (FileSystem__namespace.documentDirectory || '') + POSTHOG_STORAGE_KEY;
|
|
1342
1365
|
_a.label = 1;
|
|
1343
1366
|
|
|
1344
1367
|
case 1:
|
|
@@ -1369,13 +1392,13 @@ var loadStorageAsync = function () {
|
|
|
1369
1392
|
});
|
|
1370
1393
|
};
|
|
1371
1394
|
|
|
1372
|
-
var
|
|
1395
|
+
var persistStorageAsync = function (content) {
|
|
1373
1396
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
1374
1397
|
var uri, data;
|
|
1375
1398
|
return __generator(this, function (_a) {
|
|
1376
1399
|
switch (_a.label) {
|
|
1377
1400
|
case 0:
|
|
1378
|
-
uri = FileSystem__namespace.documentDirectory + POSTHOG_STORAGE_KEY;
|
|
1401
|
+
uri = (FileSystem__namespace.documentDirectory || '') + POSTHOG_STORAGE_KEY;
|
|
1379
1402
|
data = {
|
|
1380
1403
|
version: POSTHOG_STORAGE_VERSION,
|
|
1381
1404
|
content: content
|
|
@@ -1405,18 +1428,18 @@ var SemiAsyncStorage = {
|
|
|
1405
1428
|
},
|
|
1406
1429
|
setItem: function (key, value) {
|
|
1407
1430
|
_memoryCache[key] = value;
|
|
1408
|
-
void
|
|
1431
|
+
void persistStorageAsync(_memoryCache);
|
|
1409
1432
|
},
|
|
1410
1433
|
removeItem: function (key) {
|
|
1411
1434
|
delete _memoryCache[key];
|
|
1412
|
-
void
|
|
1435
|
+
void persistStorageAsync(_memoryCache);
|
|
1413
1436
|
},
|
|
1414
1437
|
clear: function () {
|
|
1415
1438
|
for (var key in _memoryCache) {
|
|
1416
1439
|
delete _memoryCache[key];
|
|
1417
1440
|
}
|
|
1418
1441
|
|
|
1419
|
-
void
|
|
1442
|
+
void persistStorageAsync(_memoryCache);
|
|
1420
1443
|
},
|
|
1421
1444
|
getAllKeys: function () {
|
|
1422
1445
|
return Object.keys(_memoryCache);
|
|
@@ -1432,13 +1455,13 @@ var preloadSemiAsyncStorage = function () {
|
|
|
1432
1455
|
|
|
1433
1456
|
_preloadSemiAsyncStoragePromise = loadStorageAsync().then(function (res) {
|
|
1434
1457
|
for (var key in res) {
|
|
1435
|
-
_memoryCache[key] = res[key];
|
|
1458
|
+
_memoryCache[key] = _memoryCache[key] === undefined ? res[key] : _memoryCache[key];
|
|
1436
1459
|
}
|
|
1437
1460
|
});
|
|
1438
1461
|
return _preloadSemiAsyncStoragePromise;
|
|
1439
1462
|
};
|
|
1440
1463
|
|
|
1441
|
-
var version = "2.
|
|
1464
|
+
var version = "2.1.4";
|
|
1442
1465
|
|
|
1443
1466
|
var PostHog =
|
|
1444
1467
|
/** @class */
|
|
@@ -1456,6 +1479,8 @@ function (_super) {
|
|
|
1456
1479
|
// It is possible that the old library was used so we try to get the legacy distinctID
|
|
1457
1480
|
|
|
1458
1481
|
void preloadSemiAsyncStorage().then(function () {
|
|
1482
|
+
_this.setupBootstrap(options);
|
|
1483
|
+
|
|
1459
1484
|
if (!SemiAsyncStorage.getItem(PostHogPersistedProperty.AnonymousId)) {
|
|
1460
1485
|
getLegacyValues().then(function (legacyValues) {
|
|
1461
1486
|
if (legacyValues === null || legacyValues === void 0 ? void 0 : legacyValues.distinctId) {
|
|
@@ -1482,7 +1507,7 @@ function (_super) {
|
|
|
1482
1507
|
|
|
1483
1508
|
PostHog.prototype.setPersistedProperty = function (key, value) {
|
|
1484
1509
|
if (this._persistence === 'memory') {
|
|
1485
|
-
return this._memoryStorage.
|
|
1510
|
+
return this._memoryStorage.setProperty(key, value);
|
|
1486
1511
|
}
|
|
1487
1512
|
|
|
1488
1513
|
return value !== null ? SemiAsyncStorage.setItem(key, value) : SemiAsyncStorage.removeItem(key);
|
|
@@ -1806,14 +1831,20 @@ var autocaptureFromTouchEvent = function (e, posthog, options) {
|
|
|
1806
1831
|
}
|
|
1807
1832
|
};
|
|
1808
1833
|
|
|
1809
|
-
function
|
|
1834
|
+
function PostHogNavigationHook(_a) {
|
|
1810
1835
|
var options = _a.options;
|
|
1811
1836
|
useNavigationTracker(options === null || options === void 0 ? void 0 : options.navigation);
|
|
1837
|
+
return null;
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
function PostHogLifecycleHook() {
|
|
1812
1841
|
useLifecycleTracker();
|
|
1813
1842
|
return null;
|
|
1814
1843
|
}
|
|
1815
1844
|
|
|
1816
1845
|
var PostHogProvider = function (_a) {
|
|
1846
|
+
var _b, _c;
|
|
1847
|
+
|
|
1817
1848
|
var children = _a.children,
|
|
1818
1849
|
client = _a.client,
|
|
1819
1850
|
options = _a.options,
|
|
@@ -1826,10 +1857,13 @@ var PostHogProvider = function (_a) {
|
|
|
1826
1857
|
posthogRef.current = client ? client : apiKey ? new PostHog(apiKey, options) : undefined;
|
|
1827
1858
|
}
|
|
1828
1859
|
|
|
1829
|
-
var autocaptureEnabled = !!autocapture;
|
|
1830
1860
|
var autocaptureOptions = autocapture && typeof autocapture !== 'boolean' ? autocapture : {};
|
|
1831
1861
|
var posthog = posthogRef.current;
|
|
1832
1862
|
var captureTouches = posthog && (autocapture === true || (autocaptureOptions === null || autocaptureOptions === void 0 ? void 0 : autocaptureOptions.captureTouches));
|
|
1863
|
+
var captureScreens = posthog && (autocapture === true || ((_b = autocaptureOptions === null || autocaptureOptions === void 0 ? void 0 : autocaptureOptions.captureScreens) !== null && _b !== void 0 ? _b : true)); // Default to true if not set
|
|
1864
|
+
|
|
1865
|
+
var captureLifecycle = posthog && (autocapture === true || ((_c = autocaptureOptions === null || autocaptureOptions === void 0 ? void 0 : autocaptureOptions.captureLifecycleEvents) !== null && _c !== void 0 ? _c : true)); // Default to true if not set
|
|
1866
|
+
|
|
1833
1867
|
var onTouch = React.useCallback(function (type, e) {
|
|
1834
1868
|
// TODO: Improve this to ensure we only capture presses and not just ends of a drag for example
|
|
1835
1869
|
if (!captureTouches) {
|
|
@@ -1839,8 +1873,7 @@ var PostHogProvider = function (_a) {
|
|
|
1839
1873
|
if (type === 'end') {
|
|
1840
1874
|
autocaptureFromTouchEvent(e, posthog, autocaptureOptions);
|
|
1841
1875
|
}
|
|
1842
|
-
}, [posthog, autocapture]);
|
|
1843
|
-
|
|
1876
|
+
}, [posthog, autocapture]);
|
|
1844
1877
|
return /*#__PURE__*/React__default["default"].createElement(reactNative.View, {
|
|
1845
1878
|
"ph-label": "PostHogProvider",
|
|
1846
1879
|
style: style || {
|
|
@@ -1853,9 +1886,9 @@ var PostHogProvider = function (_a) {
|
|
|
1853
1886
|
value: {
|
|
1854
1887
|
client: posthogRef.current
|
|
1855
1888
|
}
|
|
1856
|
-
},
|
|
1889
|
+
}, /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, captureScreens ? /*#__PURE__*/React__default["default"].createElement(PostHogNavigationHook, {
|
|
1857
1890
|
options: autocaptureOptions
|
|
1858
|
-
}) : null, children));
|
|
1891
|
+
}) : null, captureLifecycle ? /*#__PURE__*/React__default["default"].createElement(PostHogLifecycleHook, null) : null), children));
|
|
1859
1892
|
};
|
|
1860
1893
|
|
|
1861
1894
|
exports.PostHog = PostHog;
|