posthog-react-native 2.1.3 → 2.2.0-alpha1
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 +19 -0
- package/lib/index.cjs.js +298 -155
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +58 -17
- package/lib/index.esm.js +298 -133
- package/lib/index.esm.js.map +1 -1
- package/lib/node_modules/tslib/tslib.es6.d.ts +35 -0
- 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/native-deps.d.ts +3 -0
- package/lib/posthog-react-native/src/optional/OptionalAsyncStorage.d.ts +1 -0
- package/lib/posthog-react-native/src/optional/OptionalExpoApplication.d.ts +2 -0
- package/lib/posthog-react-native/src/optional/OptionalExpoDevice.d.ts +2 -0
- package/lib/posthog-react-native/src/optional/OptionalExpoFileSystem.d.ts +2 -0
- package/lib/posthog-react-native/src/optional/OptionalExpoLocalization.d.ts +2 -0
- package/lib/posthog-react-native/src/optional/OptionalReactNativeDeviceInfo.d.ts +1 -0
- package/lib/posthog-react-native/src/{optional-imports.d.ts → optional/OptionalReactNativeNavigation.d.ts} +0 -0
- package/lib/posthog-react-native/src/optional/warning.d.ts +1 -0
- package/lib/posthog-react-native/src/posthog-rn.d.ts +7 -1
- package/lib/posthog-react-native/src/storage.d.ts +14 -8
- package/lib/posthog-react-native/src/types.d.ts +28 -0
- package/package.json +26 -5
- package/lib/posthog-react-native/src/posthog.d.ts +0 -14
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# 2.1.4 - 2022-10-28
|
|
2
|
+
|
|
3
|
+
Also include the fix in the compiled `lib` folder.
|
|
4
|
+
|
|
5
|
+
# 2.1.3 - 2022-10-27
|
|
6
|
+
|
|
7
|
+
Actually include the fix.
|
|
8
|
+
|
|
9
|
+
# 2.1.2 - 2022-10-27
|
|
10
|
+
|
|
11
|
+
Fix bug where all values set while stored data was being loaded would get overwritten once the data was done loading.
|
|
12
|
+
|
|
13
|
+
# 2.1.1 - 2022-09-09
|
|
14
|
+
|
|
15
|
+
Support for bootstrapping feature flags and distinctIDs. This allows you to initialise the library with a set of feature flags and distinctID that are immediately available.
|
|
16
|
+
|
|
17
|
+
# 2.1.0 - 2022-09-02
|
|
18
|
+
|
|
19
|
+
PosthogProvider `autocapture` can be configured with `captureLifecycleEvents: false` and `captureScreens: false` if you want do disable these autocapture elements. Both of these default to `true`
|
package/lib/index.cjs.js
CHANGED
|
@@ -3,36 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var reactNative = require('react-native');
|
|
6
|
-
var ExpoApplication = require('expo-application');
|
|
7
|
-
var ExpoDevice = require('expo-device');
|
|
8
|
-
var ExpoLocalization = require('expo-localization');
|
|
9
|
-
var FileSystem = require('expo-file-system');
|
|
10
6
|
var React = require('react');
|
|
11
7
|
|
|
12
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
9
|
|
|
14
|
-
function _interopNamespace(e) {
|
|
15
|
-
if (e && e.__esModule) return e;
|
|
16
|
-
var n = Object.create(null);
|
|
17
|
-
if (e) {
|
|
18
|
-
Object.keys(e).forEach(function (k) {
|
|
19
|
-
if (k !== 'default') {
|
|
20
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () { return e[k]; }
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
n["default"] = e;
|
|
29
|
-
return Object.freeze(n);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var ExpoApplication__namespace = /*#__PURE__*/_interopNamespace(ExpoApplication);
|
|
33
|
-
var ExpoDevice__namespace = /*#__PURE__*/_interopNamespace(ExpoDevice);
|
|
34
|
-
var ExpoLocalization__namespace = /*#__PURE__*/_interopNamespace(ExpoLocalization);
|
|
35
|
-
var FileSystem__namespace = /*#__PURE__*/_interopNamespace(FileSystem);
|
|
36
10
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
37
11
|
|
|
38
12
|
/******************************************************************************
|
|
@@ -772,6 +746,26 @@ var PostHogCore = /** @class */ (function () {
|
|
|
772
746
|
}
|
|
773
747
|
return __assign({ $lib: this.getLibraryId(), $lib_version: this.getLibraryVersion(), $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties);
|
|
774
748
|
};
|
|
749
|
+
PostHogCore.prototype.setupBootstrap = function (options) {
|
|
750
|
+
var _a, _b, _c, _d;
|
|
751
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _a === void 0 ? void 0 : _a.distinctId) {
|
|
752
|
+
if ((_b = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _b === void 0 ? void 0 : _b.isIdentifiedId) {
|
|
753
|
+
this.setPersistedProperty(PostHogPersistedProperty.DistinctId, options.bootstrap.distinctId);
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, options.bootstrap.distinctId);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
if ((_c = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _c === void 0 ? void 0 : _c.featureFlags) {
|
|
760
|
+
var activeFlags = Object.keys(((_d = options.bootstrap) === null || _d === void 0 ? void 0 : _d.featureFlags) || {})
|
|
761
|
+
.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]); })
|
|
762
|
+
.reduce(function (res, key) {
|
|
763
|
+
var _a, _b;
|
|
764
|
+
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);
|
|
765
|
+
}, {});
|
|
766
|
+
this.setKnownFeatureFlags(activeFlags);
|
|
767
|
+
}
|
|
768
|
+
};
|
|
775
769
|
Object.defineProperty(PostHogCore.prototype, "props", {
|
|
776
770
|
// NOTE: Props are lazy loaded from localstorage hence the complex getter setter logic
|
|
777
771
|
get: function () {
|
|
@@ -1015,8 +1009,7 @@ var PostHogCore = /** @class */ (function () {
|
|
|
1015
1009
|
.then(function (r) { return r.json(); })
|
|
1016
1010
|
.then(function (res) {
|
|
1017
1011
|
if (res.featureFlags) {
|
|
1018
|
-
_this.
|
|
1019
|
-
_this._events.emit('featureflags', res.featureFlags);
|
|
1012
|
+
_this.setKnownFeatureFlags(res.featureFlags);
|
|
1020
1013
|
}
|
|
1021
1014
|
return res;
|
|
1022
1015
|
})
|
|
@@ -1027,6 +1020,10 @@ var PostHogCore = /** @class */ (function () {
|
|
|
1027
1020
|
});
|
|
1028
1021
|
});
|
|
1029
1022
|
};
|
|
1023
|
+
PostHogCore.prototype.setKnownFeatureFlags = function (featureFlags) {
|
|
1024
|
+
this.setPersistedProperty(PostHogPersistedProperty.FeatureFlags, featureFlags);
|
|
1025
|
+
this._events.emit('featureflags', featureFlags);
|
|
1026
|
+
};
|
|
1030
1027
|
PostHogCore.prototype.getFeatureFlag = function (key) {
|
|
1031
1028
|
var featureFlags = this.getFeatureFlags();
|
|
1032
1029
|
if (!featureFlags) {
|
|
@@ -1254,6 +1251,22 @@ var PostHogMemoryStorage = /** @class */ (function () {
|
|
|
1254
1251
|
return PostHogMemoryStorage;
|
|
1255
1252
|
}());
|
|
1256
1253
|
|
|
1254
|
+
var _OptionalExpoApplication = undefined;
|
|
1255
|
+
|
|
1256
|
+
try {
|
|
1257
|
+
_OptionalExpoApplication = require('expo-application');
|
|
1258
|
+
} catch (e) {}
|
|
1259
|
+
|
|
1260
|
+
var OptionalExpoApplication = _OptionalExpoApplication;
|
|
1261
|
+
|
|
1262
|
+
var _OptionalExpoFileSystem = undefined;
|
|
1263
|
+
|
|
1264
|
+
try {
|
|
1265
|
+
_OptionalExpoFileSystem = require('expo-file-system');
|
|
1266
|
+
} catch (e) {}
|
|
1267
|
+
|
|
1268
|
+
var OptionalExpoFileSystem = _OptionalExpoFileSystem;
|
|
1269
|
+
|
|
1257
1270
|
var getLegacyValues = function () {
|
|
1258
1271
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
1259
1272
|
var posthogFileDirectory, posthogDistinctIdFile, posthogAnonymousIdFile, res, _a, _b, _c, _d, _e, _f;
|
|
@@ -1261,10 +1274,18 @@ var getLegacyValues = function () {
|
|
|
1261
1274
|
return __generator(this, function (_g) {
|
|
1262
1275
|
switch (_g.label) {
|
|
1263
1276
|
case 0:
|
|
1277
|
+
// NOTE: The old react-native lib stored data in files on the filesystem.
|
|
1278
|
+
// This function takes care of pulling the legacy IDs to ensure we are using them if already present
|
|
1279
|
+
if (!OptionalExpoFileSystem || !OptionalExpoApplication) {
|
|
1280
|
+
return [2
|
|
1281
|
+
/*return*/
|
|
1282
|
+
];
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1264
1285
|
if (!(reactNative.Platform.OS === 'ios')) return [3
|
|
1265
1286
|
/*break*/
|
|
1266
1287
|
, 8];
|
|
1267
|
-
posthogFileDirectory = "".concat(
|
|
1288
|
+
posthogFileDirectory = "".concat(OptionalExpoFileSystem.documentDirectory, "../Library/Application%20Support/").concat(OptionalExpoApplication.applicationId, "/");
|
|
1268
1289
|
posthogDistinctIdFile = posthogFileDirectory + 'posthog.distinctId';
|
|
1269
1290
|
posthogAnonymousIdFile = posthogFileDirectory + 'posthog.anonymousId';
|
|
1270
1291
|
res = {
|
|
@@ -1280,7 +1301,7 @@ var getLegacyValues = function () {
|
|
|
1280
1301
|
_c = (_b = JSON).parse;
|
|
1281
1302
|
return [4
|
|
1282
1303
|
/*yield*/
|
|
1283
|
-
,
|
|
1304
|
+
, OptionalExpoFileSystem.readAsStringAsync(posthogDistinctIdFile)];
|
|
1284
1305
|
|
|
1285
1306
|
case 2:
|
|
1286
1307
|
_a.distinctId = _c.apply(_b, [_g.sent()])['posthog.distinctId'];
|
|
@@ -1301,7 +1322,7 @@ var getLegacyValues = function () {
|
|
|
1301
1322
|
_f = (_e = JSON).parse;
|
|
1302
1323
|
return [4
|
|
1303
1324
|
/*yield*/
|
|
1304
|
-
,
|
|
1325
|
+
, OptionalExpoFileSystem.readAsStringAsync(posthogAnonymousIdFile)];
|
|
1305
1326
|
|
|
1306
1327
|
case 5:
|
|
1307
1328
|
_d.anonymousId = _f.apply(_e, [_g.sent()])['posthog.anonymousId'];
|
|
@@ -1330,115 +1351,222 @@ var getLegacyValues = function () {
|
|
|
1330
1351
|
};
|
|
1331
1352
|
|
|
1332
1353
|
var POSTHOG_STORAGE_KEY = '.posthog-rn.json';
|
|
1333
|
-
var POSTHOG_STORAGE_VERSION = 'v1';
|
|
1334
|
-
|
|
1335
|
-
var loadStorageAsync = function () {
|
|
1336
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
1337
|
-
var uri, stringContent;
|
|
1338
|
-
return __generator(this, function (_a) {
|
|
1339
|
-
switch (_a.label) {
|
|
1340
|
-
case 0:
|
|
1341
|
-
uri = FileSystem__namespace.documentDirectory + POSTHOG_STORAGE_KEY;
|
|
1342
|
-
_a.label = 1;
|
|
1354
|
+
var POSTHOG_STORAGE_VERSION = 'v1'; // NOTE: The core prefers a synchronous storage so we mimic this by pre-loading all keys
|
|
1343
1355
|
|
|
1344
|
-
|
|
1345
|
-
|
|
1356
|
+
var SemiAsyncStorage =
|
|
1357
|
+
/** @class */
|
|
1358
|
+
function () {
|
|
1359
|
+
function SemiAsyncStorage(asyncStorage) {
|
|
1360
|
+
this._memoryCache = {};
|
|
1361
|
+
this._asyncStorage = asyncStorage;
|
|
1362
|
+
}
|
|
1346
1363
|
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
, FileSystem__namespace.readAsStringAsync(uri)];
|
|
1364
|
+
SemiAsyncStorage.prototype.preloadAsync = function () {
|
|
1365
|
+
var _this = this;
|
|
1350
1366
|
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
/*return*/
|
|
1355
|
-
, JSON.parse(stringContent).content];
|
|
1367
|
+
if (this._preloadSemiAsyncStoragePromise) {
|
|
1368
|
+
return this._preloadSemiAsyncStoragePromise;
|
|
1369
|
+
}
|
|
1356
1370
|
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
/*return*/
|
|
1361
|
-
, {}];
|
|
1371
|
+
this._preloadSemiAsyncStoragePromise = this._asyncStorage.getItem(POSTHOG_STORAGE_KEY).then(function (res) {
|
|
1372
|
+
try {
|
|
1373
|
+
var data = res ? JSON.parse(res).content : {};
|
|
1362
1374
|
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1375
|
+
for (var key in data) {
|
|
1376
|
+
_this._memoryCache[key] = _this._memoryCache[key] === undefined ? data[key] : _this._memoryCache[key];
|
|
1377
|
+
}
|
|
1378
|
+
} catch (e) {
|
|
1379
|
+
console.warn("PostHog failed to load persisted data from storage. This is likely because the storage format is. We'll reset the storage.", e);
|
|
1367
1380
|
}
|
|
1368
1381
|
});
|
|
1369
|
-
|
|
1370
|
-
};
|
|
1382
|
+
return this._preloadSemiAsyncStoragePromise;
|
|
1383
|
+
};
|
|
1371
1384
|
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
data = {
|
|
1380
|
-
version: POSTHOG_STORAGE_VERSION,
|
|
1381
|
-
content: content
|
|
1382
|
-
};
|
|
1383
|
-
return [4
|
|
1384
|
-
/*yield*/
|
|
1385
|
-
, FileSystem__namespace.writeAsStringAsync(uri, JSON.stringify(data)).catch(function (e) {
|
|
1386
|
-
console.error('PostHog failed to persist data to storage', e);
|
|
1387
|
-
})];
|
|
1385
|
+
SemiAsyncStorage.prototype.persist = function () {
|
|
1386
|
+
var payload = {
|
|
1387
|
+
version: POSTHOG_STORAGE_VERSION,
|
|
1388
|
+
content: this._memoryCache
|
|
1389
|
+
};
|
|
1390
|
+
void this._asyncStorage.setItem(POSTHOG_STORAGE_KEY, JSON.stringify(payload));
|
|
1391
|
+
};
|
|
1388
1392
|
|
|
1389
|
-
|
|
1390
|
-
|
|
1393
|
+
SemiAsyncStorage.prototype.getItem = function (key) {
|
|
1394
|
+
return this._memoryCache[key];
|
|
1395
|
+
};
|
|
1391
1396
|
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
},
|
|
1406
|
-
setItem: function (key, value) {
|
|
1407
|
-
_memoryCache[key] = value;
|
|
1408
|
-
void persitStorageAsync(_memoryCache);
|
|
1409
|
-
},
|
|
1410
|
-
removeItem: function (key) {
|
|
1411
|
-
delete _memoryCache[key];
|
|
1412
|
-
void persitStorageAsync(_memoryCache);
|
|
1413
|
-
},
|
|
1414
|
-
clear: function () {
|
|
1415
|
-
for (var key in _memoryCache) {
|
|
1416
|
-
delete _memoryCache[key];
|
|
1397
|
+
SemiAsyncStorage.prototype.setItem = function (key, value) {
|
|
1398
|
+
this._memoryCache[key] = value;
|
|
1399
|
+
this.persist();
|
|
1400
|
+
};
|
|
1401
|
+
|
|
1402
|
+
SemiAsyncStorage.prototype.removeItem = function (key) {
|
|
1403
|
+
delete this._memoryCache[key];
|
|
1404
|
+
this.persist();
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
SemiAsyncStorage.prototype.clear = function () {
|
|
1408
|
+
for (var key in this._memoryCache) {
|
|
1409
|
+
delete this._memoryCache[key];
|
|
1417
1410
|
}
|
|
1418
1411
|
|
|
1419
|
-
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1412
|
+
this.persist();
|
|
1413
|
+
};
|
|
1414
|
+
|
|
1415
|
+
SemiAsyncStorage.prototype.getAllKeys = function () {
|
|
1416
|
+
return Object.keys(this._memoryCache);
|
|
1417
|
+
};
|
|
1418
|
+
|
|
1419
|
+
return SemiAsyncStorage;
|
|
1420
|
+
}();
|
|
1421
|
+
|
|
1422
|
+
var version = "2.2.0-alpha1";
|
|
1423
|
+
|
|
1424
|
+
var warn = function (name) {
|
|
1425
|
+
console.warn("PostHog: Missing ".concat(name, " optional dependency. Some functions may not work as expected..."));
|
|
1424
1426
|
};
|
|
1425
1427
|
|
|
1426
|
-
var
|
|
1428
|
+
var _OptionalAsyncStorage = undefined;
|
|
1429
|
+
|
|
1430
|
+
try {
|
|
1431
|
+
_OptionalAsyncStorage = require('@react-native-async-storage/async-storage').default;
|
|
1432
|
+
} catch (e) {
|
|
1433
|
+
warn('@react-native-async-storage/async-storage');
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
var OptionalAsyncStorage = _OptionalAsyncStorage;
|
|
1437
|
+
|
|
1438
|
+
var _OptionalExpoDevice = undefined;
|
|
1439
|
+
|
|
1440
|
+
try {
|
|
1441
|
+
_OptionalExpoDevice = require('expo-device');
|
|
1442
|
+
} catch (e) {}
|
|
1443
|
+
|
|
1444
|
+
var OptionalExpoDevice = _OptionalExpoDevice;
|
|
1445
|
+
|
|
1446
|
+
var _OptionalExpoLocalization = undefined;
|
|
1427
1447
|
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1448
|
+
try {
|
|
1449
|
+
_OptionalExpoLocalization = require('expo-localization');
|
|
1450
|
+
} catch (e) {}
|
|
1451
|
+
|
|
1452
|
+
var OptionalExpoLocalization = _OptionalExpoLocalization;
|
|
1453
|
+
|
|
1454
|
+
var _OptionalReactNativeDeviceInfo = undefined;
|
|
1455
|
+
|
|
1456
|
+
try {
|
|
1457
|
+
_OptionalReactNativeDeviceInfo = require('react-native-device-info');
|
|
1458
|
+
} catch (e) {
|
|
1459
|
+
warn('react-native-device-info');
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
var OptionalReactNativeDeviceInfo = _OptionalReactNativeDeviceInfo;
|
|
1463
|
+
|
|
1464
|
+
var getAppProperties = function () {
|
|
1465
|
+
var properties = {};
|
|
1466
|
+
|
|
1467
|
+
if (OptionalExpoApplication) {
|
|
1468
|
+
properties.$app_build = OptionalExpoApplication.nativeBuildVersion;
|
|
1469
|
+
properties.$app_name = OptionalExpoApplication.applicationName;
|
|
1470
|
+
properties.$app_namespace = OptionalExpoApplication.applicationId;
|
|
1471
|
+
properties.$app_version = OptionalExpoApplication.nativeApplicationVersion;
|
|
1431
1472
|
}
|
|
1432
1473
|
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1474
|
+
if (OptionalExpoDevice) {
|
|
1475
|
+
properties.$device_manufacturer = OptionalExpoDevice.manufacturer;
|
|
1476
|
+
properties.$device_name = OptionalExpoDevice.modelName;
|
|
1477
|
+
properties.$os_name = OptionalExpoDevice.osName;
|
|
1478
|
+
properties.$os_version = OptionalExpoDevice.osVersion;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
if (OptionalExpoLocalization) {
|
|
1482
|
+
properties.$locale = OptionalExpoLocalization.locale;
|
|
1483
|
+
properties.$timezone = OptionalExpoLocalization.timezone;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
if (OptionalReactNativeDeviceInfo) {
|
|
1487
|
+
properties.$app_build = OptionalReactNativeDeviceInfo.getBuildIdSync();
|
|
1488
|
+
properties.$app_name = OptionalReactNativeDeviceInfo.getApplicationName();
|
|
1489
|
+
properties.$app_namespace = OptionalReactNativeDeviceInfo.getBundleId();
|
|
1490
|
+
properties.$app_version = OptionalReactNativeDeviceInfo.getVersion();
|
|
1491
|
+
properties.$device_manufacturer = OptionalReactNativeDeviceInfo.getManufacturerSync();
|
|
1492
|
+
properties.$device_name = OptionalReactNativeDeviceInfo.getDeviceNameSync();
|
|
1493
|
+
properties.$os_name = OptionalReactNativeDeviceInfo.getSystemName();
|
|
1494
|
+
properties.$os_version = OptionalReactNativeDeviceInfo.getSystemVersion();
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
return properties;
|
|
1439
1498
|
};
|
|
1499
|
+
var buildOptimisiticAsyncStorage = function () {
|
|
1500
|
+
if (OptionalExpoFileSystem) {
|
|
1501
|
+
var filesystem_1 = OptionalExpoFileSystem;
|
|
1502
|
+
return {
|
|
1503
|
+
getItem: function (key) {
|
|
1504
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1505
|
+
var uri, stringContent;
|
|
1506
|
+
return __generator(this, function (_a) {
|
|
1507
|
+
switch (_a.label) {
|
|
1508
|
+
case 0:
|
|
1509
|
+
uri = (filesystem_1.documentDirectory || '') + key;
|
|
1510
|
+
_a.label = 1;
|
|
1511
|
+
|
|
1512
|
+
case 1:
|
|
1513
|
+
_a.trys.push([1, 3,, 4]);
|
|
1514
|
+
|
|
1515
|
+
return [4
|
|
1516
|
+
/*yield*/
|
|
1517
|
+
, filesystem_1.readAsStringAsync(uri)];
|
|
1518
|
+
|
|
1519
|
+
case 2:
|
|
1520
|
+
stringContent = _a.sent();
|
|
1521
|
+
return [2
|
|
1522
|
+
/*return*/
|
|
1523
|
+
, stringContent];
|
|
1524
|
+
|
|
1525
|
+
case 3:
|
|
1526
|
+
_a.sent();
|
|
1527
|
+
return [2
|
|
1528
|
+
/*return*/
|
|
1529
|
+
, null];
|
|
1530
|
+
|
|
1531
|
+
case 4:
|
|
1532
|
+
return [2
|
|
1533
|
+
/*return*/
|
|
1534
|
+
];
|
|
1535
|
+
}
|
|
1536
|
+
});
|
|
1537
|
+
});
|
|
1538
|
+
},
|
|
1539
|
+
setItem: function (key, value) {
|
|
1540
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1541
|
+
var uri;
|
|
1542
|
+
return __generator(this, function (_a) {
|
|
1543
|
+
switch (_a.label) {
|
|
1544
|
+
case 0:
|
|
1545
|
+
uri = (filesystem_1.documentDirectory || '') + key;
|
|
1546
|
+
return [4
|
|
1547
|
+
/*yield*/
|
|
1548
|
+
, filesystem_1.writeAsStringAsync(uri, value)];
|
|
1549
|
+
|
|
1550
|
+
case 1:
|
|
1551
|
+
_a.sent();
|
|
1552
|
+
|
|
1553
|
+
return [2
|
|
1554
|
+
/*return*/
|
|
1555
|
+
];
|
|
1556
|
+
}
|
|
1557
|
+
});
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1440
1562
|
|
|
1441
|
-
|
|
1563
|
+
if (OptionalAsyncStorage) {
|
|
1564
|
+
return OptionalAsyncStorage;
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
console.log(OptionalAsyncStorage);
|
|
1568
|
+
throw new Error('PostHog: No storage available. Please install expo-filesystem or react-native-async-storage OR implement a custom storage provider.');
|
|
1569
|
+
};
|
|
1442
1570
|
|
|
1443
1571
|
var PostHog =
|
|
1444
1572
|
/** @class */
|
|
@@ -1449,27 +1577,51 @@ function (_super) {
|
|
|
1449
1577
|
var _this = _super.call(this, apiKey, options) || this;
|
|
1450
1578
|
|
|
1451
1579
|
_this._memoryStorage = new PostHogMemoryStorage();
|
|
1580
|
+
_this._appProperties = {};
|
|
1452
1581
|
_this._persistence = options === null || options === void 0 ? void 0 : options.persistence;
|
|
1582
|
+
_this._appProperties = (options === null || options === void 0 ? void 0 : options.customAppProperties) || getAppProperties();
|
|
1583
|
+
_this._semiAsyncStorage = new SemiAsyncStorage((options === null || options === void 0 ? void 0 : options.customAsyncStorage) || buildOptimisiticAsyncStorage());
|
|
1453
1584
|
reactNative.AppState.addEventListener('change', function () {
|
|
1454
1585
|
_this.flush();
|
|
1455
1586
|
}); // Ensure the async storage has been preloaded (this call is cached)
|
|
1456
1587
|
// It is possible that the old library was used so we try to get the legacy distinctID
|
|
1457
1588
|
|
|
1458
|
-
void
|
|
1459
|
-
|
|
1589
|
+
void _this._semiAsyncStorage.preloadAsync().then(function () {
|
|
1590
|
+
_this.setupBootstrap(options);
|
|
1591
|
+
|
|
1592
|
+
if (!_this._semiAsyncStorage.getItem(PostHogPersistedProperty.AnonymousId)) {
|
|
1460
1593
|
getLegacyValues().then(function (legacyValues) {
|
|
1461
1594
|
if (legacyValues === null || legacyValues === void 0 ? void 0 : legacyValues.distinctId) {
|
|
1462
|
-
|
|
1463
|
-
|
|
1595
|
+
_this._semiAsyncStorage.setItem(PostHogPersistedProperty.DistinctId, legacyValues.distinctId);
|
|
1596
|
+
|
|
1597
|
+
_this._semiAsyncStorage.setItem(PostHogPersistedProperty.AnonymousId, legacyValues.anonymousId);
|
|
1464
1598
|
}
|
|
1465
1599
|
});
|
|
1466
1600
|
}
|
|
1467
1601
|
});
|
|
1468
1602
|
return _this;
|
|
1469
1603
|
}
|
|
1604
|
+
/** Await this method to ensure that all state has been loaded from the async provider */
|
|
1605
|
+
|
|
1606
|
+
|
|
1607
|
+
PostHog.prototype.initAsync = function () {
|
|
1608
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1609
|
+
return __generator(this, function (_a) {
|
|
1610
|
+
switch (_a.label) {
|
|
1611
|
+
case 0:
|
|
1612
|
+
return [4
|
|
1613
|
+
/*yield*/
|
|
1614
|
+
, this._semiAsyncStorage];
|
|
1615
|
+
|
|
1616
|
+
case 1:
|
|
1617
|
+
_a.sent();
|
|
1470
1618
|
|
|
1471
|
-
|
|
1472
|
-
|
|
1619
|
+
return [2
|
|
1620
|
+
/*return*/
|
|
1621
|
+
];
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
});
|
|
1473
1625
|
};
|
|
1474
1626
|
|
|
1475
1627
|
PostHog.prototype.getPersistedProperty = function (key) {
|
|
@@ -1477,15 +1629,15 @@ function (_super) {
|
|
|
1477
1629
|
return this._memoryStorage.getProperty(key);
|
|
1478
1630
|
}
|
|
1479
1631
|
|
|
1480
|
-
return
|
|
1632
|
+
return this._semiAsyncStorage.getItem(key) || undefined;
|
|
1481
1633
|
};
|
|
1482
1634
|
|
|
1483
1635
|
PostHog.prototype.setPersistedProperty = function (key, value) {
|
|
1484
1636
|
if (this._persistence === 'memory') {
|
|
1485
|
-
return this._memoryStorage.
|
|
1637
|
+
return this._memoryStorage.setProperty(key, value);
|
|
1486
1638
|
}
|
|
1487
1639
|
|
|
1488
|
-
return value !== null ?
|
|
1640
|
+
return value !== null ? this._semiAsyncStorage.setItem(key, value) : this._semiAsyncStorage.removeItem(key);
|
|
1489
1641
|
};
|
|
1490
1642
|
|
|
1491
1643
|
PostHog.prototype.fetch = function (url, options) {
|
|
@@ -1505,20 +1657,10 @@ function (_super) {
|
|
|
1505
1657
|
};
|
|
1506
1658
|
|
|
1507
1659
|
PostHog.prototype.getCommonEventProperties = function () {
|
|
1508
|
-
return __assign(__assign({}, _super.prototype.getCommonEventProperties.call(this)), {
|
|
1509
|
-
$app_build: '1',
|
|
1510
|
-
$app_name: ExpoApplication__namespace.applicationName,
|
|
1511
|
-
$app_namespace: ExpoApplication__namespace.applicationId,
|
|
1512
|
-
$app_version: ExpoApplication__namespace.nativeApplicationVersion,
|
|
1513
|
-
$device_manufacturer: ExpoDevice__namespace.manufacturer,
|
|
1514
|
-
$device_name: ExpoDevice__namespace.modelName,
|
|
1660
|
+
return __assign(__assign(__assign({}, _super.prototype.getCommonEventProperties.call(this)), this._appProperties), {
|
|
1515
1661
|
$device_type: reactNative.Platform.OS,
|
|
1516
|
-
$locale: ExpoLocalization__namespace.locale,
|
|
1517
|
-
$os_name: ExpoDevice__namespace.osName,
|
|
1518
|
-
$os_version: ExpoDevice__namespace.osVersion,
|
|
1519
1662
|
$screen_height: reactNative.Dimensions.get('screen').height,
|
|
1520
|
-
$screen_width: reactNative.Dimensions.get('screen').width
|
|
1521
|
-
$timezone: ExpoLocalization__namespace.timezone
|
|
1663
|
+
$screen_width: reactNative.Dimensions.get('screen').width
|
|
1522
1664
|
});
|
|
1523
1665
|
}; // Custom methods
|
|
1524
1666
|
|
|
@@ -1531,9 +1673,6 @@ function (_super) {
|
|
|
1531
1673
|
|
|
1532
1674
|
return PostHog;
|
|
1533
1675
|
}(PostHogCore);
|
|
1534
|
-
// is used
|
|
1535
|
-
|
|
1536
|
-
void PostHog.initAsync();
|
|
1537
1676
|
|
|
1538
1677
|
var PostHogContext = /*#__PURE__*/React__default["default"].createContext({
|
|
1539
1678
|
client: undefined
|
|
@@ -1578,10 +1717,6 @@ function useLifecycleTracker(client) {
|
|
|
1578
1717
|
|
|
1579
1718
|
var _OptionalReactNativeNavigation = undefined;
|
|
1580
1719
|
|
|
1581
|
-
var warn = function (name) {
|
|
1582
|
-
console.warn("PostHog: Missing ".concat(name, " optional dependency. Some functions may not work as expected..."));
|
|
1583
|
-
};
|
|
1584
|
-
|
|
1585
1720
|
try {
|
|
1586
1721
|
_OptionalReactNativeNavigation = require('@react-navigation/native');
|
|
1587
1722
|
} catch (e) {
|
|
@@ -1806,14 +1941,20 @@ var autocaptureFromTouchEvent = function (e, posthog, options) {
|
|
|
1806
1941
|
}
|
|
1807
1942
|
};
|
|
1808
1943
|
|
|
1809
|
-
function
|
|
1944
|
+
function PostHogNavigationHook(_a) {
|
|
1810
1945
|
var options = _a.options;
|
|
1811
1946
|
useNavigationTracker(options === null || options === void 0 ? void 0 : options.navigation);
|
|
1947
|
+
return null;
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
function PostHogLifecycleHook() {
|
|
1812
1951
|
useLifecycleTracker();
|
|
1813
1952
|
return null;
|
|
1814
1953
|
}
|
|
1815
1954
|
|
|
1816
1955
|
var PostHogProvider = function (_a) {
|
|
1956
|
+
var _b, _c;
|
|
1957
|
+
|
|
1817
1958
|
var children = _a.children,
|
|
1818
1959
|
client = _a.client,
|
|
1819
1960
|
options = _a.options,
|
|
@@ -1826,10 +1967,13 @@ var PostHogProvider = function (_a) {
|
|
|
1826
1967
|
posthogRef.current = client ? client : apiKey ? new PostHog(apiKey, options) : undefined;
|
|
1827
1968
|
}
|
|
1828
1969
|
|
|
1829
|
-
var autocaptureEnabled = !!autocapture;
|
|
1830
1970
|
var autocaptureOptions = autocapture && typeof autocapture !== 'boolean' ? autocapture : {};
|
|
1831
1971
|
var posthog = posthogRef.current;
|
|
1832
1972
|
var captureTouches = posthog && (autocapture === true || (autocaptureOptions === null || autocaptureOptions === void 0 ? void 0 : autocaptureOptions.captureTouches));
|
|
1973
|
+
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
|
|
1974
|
+
|
|
1975
|
+
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
|
|
1976
|
+
|
|
1833
1977
|
var onTouch = React.useCallback(function (type, e) {
|
|
1834
1978
|
// TODO: Improve this to ensure we only capture presses and not just ends of a drag for example
|
|
1835
1979
|
if (!captureTouches) {
|
|
@@ -1839,8 +1983,7 @@ var PostHogProvider = function (_a) {
|
|
|
1839
1983
|
if (type === 'end') {
|
|
1840
1984
|
autocaptureFromTouchEvent(e, posthog, autocaptureOptions);
|
|
1841
1985
|
}
|
|
1842
|
-
}, [posthog, autocapture]);
|
|
1843
|
-
|
|
1986
|
+
}, [posthog, autocapture]);
|
|
1844
1987
|
return /*#__PURE__*/React__default["default"].createElement(reactNative.View, {
|
|
1845
1988
|
"ph-label": "PostHogProvider",
|
|
1846
1989
|
style: style || {
|
|
@@ -1853,9 +1996,9 @@ var PostHogProvider = function (_a) {
|
|
|
1853
1996
|
value: {
|
|
1854
1997
|
client: posthogRef.current
|
|
1855
1998
|
}
|
|
1856
|
-
},
|
|
1999
|
+
}, /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, captureScreens ? /*#__PURE__*/React__default["default"].createElement(PostHogNavigationHook, {
|
|
1857
2000
|
options: autocaptureOptions
|
|
1858
|
-
}) : null, children));
|
|
2001
|
+
}) : null, captureLifecycle ? /*#__PURE__*/React__default["default"].createElement(PostHogLifecycleHook, null) : null), children));
|
|
1859
2002
|
};
|
|
1860
2003
|
|
|
1861
2004
|
exports.PostHog = PostHog;
|