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/lib/index.esm.js CHANGED
@@ -1,8 +1,4 @@
1
1
  import { Platform, Dimensions, AppState, View } from 'react-native';
2
- import * as ExpoApplication from 'expo-application';
3
- import * as ExpoDevice from 'expo-device';
4
- import * as ExpoLocalization from 'expo-localization';
5
- import * as FileSystem from 'expo-file-system';
6
2
  import React, { useRef, useEffect, useState, useCallback } from 'react';
7
3
 
8
4
  /******************************************************************************
@@ -742,6 +738,26 @@ var PostHogCore = /** @class */ (function () {
742
738
  }
743
739
  return __assign({ $lib: this.getLibraryId(), $lib_version: this.getLibraryVersion(), $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties);
744
740
  };
741
+ PostHogCore.prototype.setupBootstrap = function (options) {
742
+ var _a, _b, _c, _d;
743
+ if ((_a = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _a === void 0 ? void 0 : _a.distinctId) {
744
+ if ((_b = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _b === void 0 ? void 0 : _b.isIdentifiedId) {
745
+ this.setPersistedProperty(PostHogPersistedProperty.DistinctId, options.bootstrap.distinctId);
746
+ }
747
+ else {
748
+ this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, options.bootstrap.distinctId);
749
+ }
750
+ }
751
+ if ((_c = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _c === void 0 ? void 0 : _c.featureFlags) {
752
+ var activeFlags = Object.keys(((_d = options.bootstrap) === null || _d === void 0 ? void 0 : _d.featureFlags) || {})
753
+ .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]); })
754
+ .reduce(function (res, key) {
755
+ var _a, _b;
756
+ 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);
757
+ }, {});
758
+ this.setKnownFeatureFlags(activeFlags);
759
+ }
760
+ };
745
761
  Object.defineProperty(PostHogCore.prototype, "props", {
746
762
  // NOTE: Props are lazy loaded from localstorage hence the complex getter setter logic
747
763
  get: function () {
@@ -985,8 +1001,7 @@ var PostHogCore = /** @class */ (function () {
985
1001
  .then(function (r) { return r.json(); })
986
1002
  .then(function (res) {
987
1003
  if (res.featureFlags) {
988
- _this.setPersistedProperty(PostHogPersistedProperty.FeatureFlags, res.featureFlags);
989
- _this._events.emit('featureflags', res.featureFlags);
1004
+ _this.setKnownFeatureFlags(res.featureFlags);
990
1005
  }
991
1006
  return res;
992
1007
  })
@@ -997,6 +1012,10 @@ var PostHogCore = /** @class */ (function () {
997
1012
  });
998
1013
  });
999
1014
  };
1015
+ PostHogCore.prototype.setKnownFeatureFlags = function (featureFlags) {
1016
+ this.setPersistedProperty(PostHogPersistedProperty.FeatureFlags, featureFlags);
1017
+ this._events.emit('featureflags', featureFlags);
1018
+ };
1000
1019
  PostHogCore.prototype.getFeatureFlag = function (key) {
1001
1020
  var featureFlags = this.getFeatureFlags();
1002
1021
  if (!featureFlags) {
@@ -1224,6 +1243,22 @@ var PostHogMemoryStorage = /** @class */ (function () {
1224
1243
  return PostHogMemoryStorage;
1225
1244
  }());
1226
1245
 
1246
+ var _OptionalExpoApplication = undefined;
1247
+
1248
+ try {
1249
+ _OptionalExpoApplication = require('expo-application');
1250
+ } catch (e) {}
1251
+
1252
+ var OptionalExpoApplication = _OptionalExpoApplication;
1253
+
1254
+ var _OptionalExpoFileSystem = undefined;
1255
+
1256
+ try {
1257
+ _OptionalExpoFileSystem = require('expo-file-system');
1258
+ } catch (e) {}
1259
+
1260
+ var OptionalExpoFileSystem = _OptionalExpoFileSystem;
1261
+
1227
1262
  var getLegacyValues = function () {
1228
1263
  return __awaiter(void 0, void 0, void 0, function () {
1229
1264
  var posthogFileDirectory, posthogDistinctIdFile, posthogAnonymousIdFile, res, _a, _b, _c, _d, _e, _f;
@@ -1231,10 +1266,18 @@ var getLegacyValues = function () {
1231
1266
  return __generator(this, function (_g) {
1232
1267
  switch (_g.label) {
1233
1268
  case 0:
1269
+ // NOTE: The old react-native lib stored data in files on the filesystem.
1270
+ // This function takes care of pulling the legacy IDs to ensure we are using them if already present
1271
+ if (!OptionalExpoFileSystem || !OptionalExpoApplication) {
1272
+ return [2
1273
+ /*return*/
1274
+ ];
1275
+ }
1276
+
1234
1277
  if (!(Platform.OS === 'ios')) return [3
1235
1278
  /*break*/
1236
1279
  , 8];
1237
- posthogFileDirectory = "".concat(FileSystem.documentDirectory, "../Library/Application%20Support/").concat(ExpoApplication.applicationId, "/");
1280
+ posthogFileDirectory = "".concat(OptionalExpoFileSystem.documentDirectory, "../Library/Application%20Support/").concat(OptionalExpoApplication.applicationId, "/");
1238
1281
  posthogDistinctIdFile = posthogFileDirectory + 'posthog.distinctId';
1239
1282
  posthogAnonymousIdFile = posthogFileDirectory + 'posthog.anonymousId';
1240
1283
  res = {
@@ -1250,7 +1293,7 @@ var getLegacyValues = function () {
1250
1293
  _c = (_b = JSON).parse;
1251
1294
  return [4
1252
1295
  /*yield*/
1253
- , FileSystem.readAsStringAsync(posthogDistinctIdFile)];
1296
+ , OptionalExpoFileSystem.readAsStringAsync(posthogDistinctIdFile)];
1254
1297
 
1255
1298
  case 2:
1256
1299
  _a.distinctId = _c.apply(_b, [_g.sent()])['posthog.distinctId'];
@@ -1271,7 +1314,7 @@ var getLegacyValues = function () {
1271
1314
  _f = (_e = JSON).parse;
1272
1315
  return [4
1273
1316
  /*yield*/
1274
- , FileSystem.readAsStringAsync(posthogAnonymousIdFile)];
1317
+ , OptionalExpoFileSystem.readAsStringAsync(posthogAnonymousIdFile)];
1275
1318
 
1276
1319
  case 5:
1277
1320
  _d.anonymousId = _f.apply(_e, [_g.sent()])['posthog.anonymousId'];
@@ -1300,115 +1343,222 @@ var getLegacyValues = function () {
1300
1343
  };
1301
1344
 
1302
1345
  var POSTHOG_STORAGE_KEY = '.posthog-rn.json';
1303
- var POSTHOG_STORAGE_VERSION = 'v1';
1304
-
1305
- var loadStorageAsync = function () {
1306
- return __awaiter(void 0, void 0, void 0, function () {
1307
- var uri, stringContent;
1308
- return __generator(this, function (_a) {
1309
- switch (_a.label) {
1310
- case 0:
1311
- uri = FileSystem.documentDirectory + POSTHOG_STORAGE_KEY;
1312
- _a.label = 1;
1346
+ var POSTHOG_STORAGE_VERSION = 'v1'; // NOTE: The core prefers a synchronous storage so we mimic this by pre-loading all keys
1313
1347
 
1314
- case 1:
1315
- _a.trys.push([1, 3,, 4]);
1348
+ var SemiAsyncStorage =
1349
+ /** @class */
1350
+ function () {
1351
+ function SemiAsyncStorage(asyncStorage) {
1352
+ this._memoryCache = {};
1353
+ this._asyncStorage = asyncStorage;
1354
+ }
1316
1355
 
1317
- return [4
1318
- /*yield*/
1319
- , FileSystem.readAsStringAsync(uri)];
1356
+ SemiAsyncStorage.prototype.preloadAsync = function () {
1357
+ var _this = this;
1320
1358
 
1321
- case 2:
1322
- stringContent = _a.sent();
1323
- return [2
1324
- /*return*/
1325
- , JSON.parse(stringContent).content];
1359
+ if (this._preloadSemiAsyncStoragePromise) {
1360
+ return this._preloadSemiAsyncStoragePromise;
1361
+ }
1326
1362
 
1327
- case 3:
1328
- _a.sent();
1329
- return [2
1330
- /*return*/
1331
- , {}];
1363
+ this._preloadSemiAsyncStoragePromise = this._asyncStorage.getItem(POSTHOG_STORAGE_KEY).then(function (res) {
1364
+ try {
1365
+ var data = res ? JSON.parse(res).content : {};
1332
1366
 
1333
- case 4:
1334
- return [2
1335
- /*return*/
1336
- ];
1367
+ for (var key in data) {
1368
+ _this._memoryCache[key] = _this._memoryCache[key] === undefined ? data[key] : _this._memoryCache[key];
1369
+ }
1370
+ } catch (e) {
1371
+ console.warn("PostHog failed to load persisted data from storage. This is likely because the storage format is. We'll reset the storage.", e);
1337
1372
  }
1338
1373
  });
1339
- });
1340
- };
1374
+ return this._preloadSemiAsyncStoragePromise;
1375
+ };
1341
1376
 
1342
- var persitStorageAsync = function (content) {
1343
- return __awaiter(void 0, void 0, void 0, function () {
1344
- var uri, data;
1345
- return __generator(this, function (_a) {
1346
- switch (_a.label) {
1347
- case 0:
1348
- uri = FileSystem.documentDirectory + POSTHOG_STORAGE_KEY;
1349
- data = {
1350
- version: POSTHOG_STORAGE_VERSION,
1351
- content: content
1352
- };
1353
- return [4
1354
- /*yield*/
1355
- , FileSystem.writeAsStringAsync(uri, JSON.stringify(data)).catch(function (e) {
1356
- console.error('PostHog failed to persist data to storage', e);
1357
- })];
1377
+ SemiAsyncStorage.prototype.persist = function () {
1378
+ var payload = {
1379
+ version: POSTHOG_STORAGE_VERSION,
1380
+ content: this._memoryCache
1381
+ };
1382
+ void this._asyncStorage.setItem(POSTHOG_STORAGE_KEY, JSON.stringify(payload));
1383
+ };
1358
1384
 
1359
- case 1:
1360
- _a.sent();
1385
+ SemiAsyncStorage.prototype.getItem = function (key) {
1386
+ return this._memoryCache[key];
1387
+ };
1361
1388
 
1362
- return [2
1363
- /*return*/
1364
- ];
1365
- }
1366
- });
1367
- });
1368
- }; // NOTE: The core prefers a synchronous storage so we mimic this by pre-loading all keys
1369
-
1370
-
1371
- var _memoryCache = {};
1372
- var SemiAsyncStorage = {
1373
- getItem: function (key) {
1374
- return _memoryCache[key];
1375
- },
1376
- setItem: function (key, value) {
1377
- _memoryCache[key] = value;
1378
- void persitStorageAsync(_memoryCache);
1379
- },
1380
- removeItem: function (key) {
1381
- delete _memoryCache[key];
1382
- void persitStorageAsync(_memoryCache);
1383
- },
1384
- clear: function () {
1385
- for (var key in _memoryCache) {
1386
- delete _memoryCache[key];
1389
+ SemiAsyncStorage.prototype.setItem = function (key, value) {
1390
+ this._memoryCache[key] = value;
1391
+ this.persist();
1392
+ };
1393
+
1394
+ SemiAsyncStorage.prototype.removeItem = function (key) {
1395
+ delete this._memoryCache[key];
1396
+ this.persist();
1397
+ };
1398
+
1399
+ SemiAsyncStorage.prototype.clear = function () {
1400
+ for (var key in this._memoryCache) {
1401
+ delete this._memoryCache[key];
1387
1402
  }
1388
1403
 
1389
- void persitStorageAsync(_memoryCache);
1390
- },
1391
- getAllKeys: function () {
1392
- return Object.keys(_memoryCache);
1393
- }
1404
+ this.persist();
1405
+ };
1406
+
1407
+ SemiAsyncStorage.prototype.getAllKeys = function () {
1408
+ return Object.keys(this._memoryCache);
1409
+ };
1410
+
1411
+ return SemiAsyncStorage;
1412
+ }();
1413
+
1414
+ var version = "2.2.0-alpha1";
1415
+
1416
+ var warn = function (name) {
1417
+ console.warn("PostHog: Missing ".concat(name, " optional dependency. Some functions may not work as expected..."));
1394
1418
  };
1395
1419
 
1396
- var _preloadSemiAsyncStoragePromise;
1420
+ var _OptionalAsyncStorage = undefined;
1421
+
1422
+ try {
1423
+ _OptionalAsyncStorage = require('@react-native-async-storage/async-storage').default;
1424
+ } catch (e) {
1425
+ warn('@react-native-async-storage/async-storage');
1426
+ }
1427
+
1428
+ var OptionalAsyncStorage = _OptionalAsyncStorage;
1429
+
1430
+ var _OptionalExpoDevice = undefined;
1431
+
1432
+ try {
1433
+ _OptionalExpoDevice = require('expo-device');
1434
+ } catch (e) {}
1435
+
1436
+ var OptionalExpoDevice = _OptionalExpoDevice;
1397
1437
 
1398
- var preloadSemiAsyncStorage = function () {
1399
- if (_preloadSemiAsyncStoragePromise) {
1400
- return _preloadSemiAsyncStoragePromise;
1438
+ var _OptionalExpoLocalization = undefined;
1439
+
1440
+ try {
1441
+ _OptionalExpoLocalization = require('expo-localization');
1442
+ } catch (e) {}
1443
+
1444
+ var OptionalExpoLocalization = _OptionalExpoLocalization;
1445
+
1446
+ var _OptionalReactNativeDeviceInfo = undefined;
1447
+
1448
+ try {
1449
+ _OptionalReactNativeDeviceInfo = require('react-native-device-info');
1450
+ } catch (e) {
1451
+ warn('react-native-device-info');
1452
+ }
1453
+
1454
+ var OptionalReactNativeDeviceInfo = _OptionalReactNativeDeviceInfo;
1455
+
1456
+ var getAppProperties = function () {
1457
+ var properties = {};
1458
+
1459
+ if (OptionalExpoApplication) {
1460
+ properties.$app_build = OptionalExpoApplication.nativeBuildVersion;
1461
+ properties.$app_name = OptionalExpoApplication.applicationName;
1462
+ properties.$app_namespace = OptionalExpoApplication.applicationId;
1463
+ properties.$app_version = OptionalExpoApplication.nativeApplicationVersion;
1401
1464
  }
1402
1465
 
1403
- _preloadSemiAsyncStoragePromise = loadStorageAsync().then(function (res) {
1404
- for (var key in res) {
1405
- _memoryCache[key] = res[key];
1406
- }
1407
- });
1408
- return _preloadSemiAsyncStoragePromise;
1466
+ if (OptionalExpoDevice) {
1467
+ properties.$device_manufacturer = OptionalExpoDevice.manufacturer;
1468
+ properties.$device_name = OptionalExpoDevice.modelName;
1469
+ properties.$os_name = OptionalExpoDevice.osName;
1470
+ properties.$os_version = OptionalExpoDevice.osVersion;
1471
+ }
1472
+
1473
+ if (OptionalExpoLocalization) {
1474
+ properties.$locale = OptionalExpoLocalization.locale;
1475
+ properties.$timezone = OptionalExpoLocalization.timezone;
1476
+ }
1477
+
1478
+ if (OptionalReactNativeDeviceInfo) {
1479
+ properties.$app_build = OptionalReactNativeDeviceInfo.getBuildIdSync();
1480
+ properties.$app_name = OptionalReactNativeDeviceInfo.getApplicationName();
1481
+ properties.$app_namespace = OptionalReactNativeDeviceInfo.getBundleId();
1482
+ properties.$app_version = OptionalReactNativeDeviceInfo.getVersion();
1483
+ properties.$device_manufacturer = OptionalReactNativeDeviceInfo.getManufacturerSync();
1484
+ properties.$device_name = OptionalReactNativeDeviceInfo.getDeviceNameSync();
1485
+ properties.$os_name = OptionalReactNativeDeviceInfo.getSystemName();
1486
+ properties.$os_version = OptionalReactNativeDeviceInfo.getSystemVersion();
1487
+ }
1488
+
1489
+ return properties;
1409
1490
  };
1491
+ var buildOptimisiticAsyncStorage = function () {
1492
+ if (OptionalExpoFileSystem) {
1493
+ var filesystem_1 = OptionalExpoFileSystem;
1494
+ return {
1495
+ getItem: function (key) {
1496
+ return __awaiter(this, void 0, void 0, function () {
1497
+ var uri, stringContent;
1498
+ return __generator(this, function (_a) {
1499
+ switch (_a.label) {
1500
+ case 0:
1501
+ uri = (filesystem_1.documentDirectory || '') + key;
1502
+ _a.label = 1;
1503
+
1504
+ case 1:
1505
+ _a.trys.push([1, 3,, 4]);
1506
+
1507
+ return [4
1508
+ /*yield*/
1509
+ , filesystem_1.readAsStringAsync(uri)];
1510
+
1511
+ case 2:
1512
+ stringContent = _a.sent();
1513
+ return [2
1514
+ /*return*/
1515
+ , stringContent];
1516
+
1517
+ case 3:
1518
+ _a.sent();
1519
+ return [2
1520
+ /*return*/
1521
+ , null];
1522
+
1523
+ case 4:
1524
+ return [2
1525
+ /*return*/
1526
+ ];
1527
+ }
1528
+ });
1529
+ });
1530
+ },
1531
+ setItem: function (key, value) {
1532
+ return __awaiter(this, void 0, void 0, function () {
1533
+ var uri;
1534
+ return __generator(this, function (_a) {
1535
+ switch (_a.label) {
1536
+ case 0:
1537
+ uri = (filesystem_1.documentDirectory || '') + key;
1538
+ return [4
1539
+ /*yield*/
1540
+ , filesystem_1.writeAsStringAsync(uri, value)];
1541
+
1542
+ case 1:
1543
+ _a.sent();
1544
+
1545
+ return [2
1546
+ /*return*/
1547
+ ];
1548
+ }
1549
+ });
1550
+ });
1551
+ }
1552
+ };
1553
+ }
1554
+
1555
+ if (OptionalAsyncStorage) {
1556
+ return OptionalAsyncStorage;
1557
+ }
1410
1558
 
1411
- var version = "2.0.0";
1559
+ console.log(OptionalAsyncStorage);
1560
+ throw new Error('PostHog: No storage available. Please install expo-filesystem or react-native-async-storage OR implement a custom storage provider.');
1561
+ };
1412
1562
 
1413
1563
  var PostHog =
1414
1564
  /** @class */
@@ -1419,27 +1569,51 @@ function (_super) {
1419
1569
  var _this = _super.call(this, apiKey, options) || this;
1420
1570
 
1421
1571
  _this._memoryStorage = new PostHogMemoryStorage();
1572
+ _this._appProperties = {};
1422
1573
  _this._persistence = options === null || options === void 0 ? void 0 : options.persistence;
1574
+ _this._appProperties = (options === null || options === void 0 ? void 0 : options.customAppProperties) || getAppProperties();
1575
+ _this._semiAsyncStorage = new SemiAsyncStorage((options === null || options === void 0 ? void 0 : options.customAsyncStorage) || buildOptimisiticAsyncStorage());
1423
1576
  AppState.addEventListener('change', function () {
1424
1577
  _this.flush();
1425
1578
  }); // Ensure the async storage has been preloaded (this call is cached)
1426
1579
  // It is possible that the old library was used so we try to get the legacy distinctID
1427
1580
 
1428
- void preloadSemiAsyncStorage().then(function () {
1429
- if (!SemiAsyncStorage.getItem(PostHogPersistedProperty.AnonymousId)) {
1581
+ void _this._semiAsyncStorage.preloadAsync().then(function () {
1582
+ _this.setupBootstrap(options);
1583
+
1584
+ if (!_this._semiAsyncStorage.getItem(PostHogPersistedProperty.AnonymousId)) {
1430
1585
  getLegacyValues().then(function (legacyValues) {
1431
1586
  if (legacyValues === null || legacyValues === void 0 ? void 0 : legacyValues.distinctId) {
1432
- SemiAsyncStorage.setItem(PostHogPersistedProperty.DistinctId, legacyValues.distinctId);
1433
- SemiAsyncStorage.setItem(PostHogPersistedProperty.AnonymousId, legacyValues.anonymousId);
1587
+ _this._semiAsyncStorage.setItem(PostHogPersistedProperty.DistinctId, legacyValues.distinctId);
1588
+
1589
+ _this._semiAsyncStorage.setItem(PostHogPersistedProperty.AnonymousId, legacyValues.anonymousId);
1434
1590
  }
1435
1591
  });
1436
1592
  }
1437
1593
  });
1438
1594
  return _this;
1439
1595
  }
1596
+ /** Await this method to ensure that all state has been loaded from the async provider */
1440
1597
 
1441
- PostHog.initAsync = function () {
1442
- return preloadSemiAsyncStorage();
1598
+
1599
+ PostHog.prototype.initAsync = function () {
1600
+ return __awaiter(this, void 0, void 0, function () {
1601
+ return __generator(this, function (_a) {
1602
+ switch (_a.label) {
1603
+ case 0:
1604
+ return [4
1605
+ /*yield*/
1606
+ , this._semiAsyncStorage];
1607
+
1608
+ case 1:
1609
+ _a.sent();
1610
+
1611
+ return [2
1612
+ /*return*/
1613
+ ];
1614
+ }
1615
+ });
1616
+ });
1443
1617
  };
1444
1618
 
1445
1619
  PostHog.prototype.getPersistedProperty = function (key) {
@@ -1447,15 +1621,15 @@ function (_super) {
1447
1621
  return this._memoryStorage.getProperty(key);
1448
1622
  }
1449
1623
 
1450
- return SemiAsyncStorage.getItem(key) || undefined;
1624
+ return this._semiAsyncStorage.getItem(key) || undefined;
1451
1625
  };
1452
1626
 
1453
1627
  PostHog.prototype.setPersistedProperty = function (key, value) {
1454
1628
  if (this._persistence === 'memory') {
1455
- return this._memoryStorage.getProperty(key);
1629
+ return this._memoryStorage.setProperty(key, value);
1456
1630
  }
1457
1631
 
1458
- return value !== null ? SemiAsyncStorage.setItem(key, value) : SemiAsyncStorage.removeItem(key);
1632
+ return value !== null ? this._semiAsyncStorage.setItem(key, value) : this._semiAsyncStorage.removeItem(key);
1459
1633
  };
1460
1634
 
1461
1635
  PostHog.prototype.fetch = function (url, options) {
@@ -1475,20 +1649,10 @@ function (_super) {
1475
1649
  };
1476
1650
 
1477
1651
  PostHog.prototype.getCommonEventProperties = function () {
1478
- return __assign(__assign({}, _super.prototype.getCommonEventProperties.call(this)), {
1479
- $app_build: '1',
1480
- $app_name: ExpoApplication.applicationName,
1481
- $app_namespace: ExpoApplication.applicationId,
1482
- $app_version: ExpoApplication.nativeApplicationVersion,
1483
- $device_manufacturer: ExpoDevice.manufacturer,
1484
- $device_name: ExpoDevice.modelName,
1652
+ return __assign(__assign(__assign({}, _super.prototype.getCommonEventProperties.call(this)), this._appProperties), {
1485
1653
  $device_type: Platform.OS,
1486
- $locale: ExpoLocalization.locale,
1487
- $os_name: ExpoDevice.osName,
1488
- $os_version: ExpoDevice.osVersion,
1489
1654
  $screen_height: Dimensions.get('screen').height,
1490
- $screen_width: Dimensions.get('screen').width,
1491
- $timezone: ExpoLocalization.timezone
1655
+ $screen_width: Dimensions.get('screen').width
1492
1656
  });
1493
1657
  }; // Custom methods
1494
1658
 
@@ -1501,9 +1665,6 @@ function (_super) {
1501
1665
 
1502
1666
  return PostHog;
1503
1667
  }(PostHogCore);
1504
- // is used
1505
-
1506
- void PostHog.initAsync();
1507
1668
 
1508
1669
  var PostHogContext = /*#__PURE__*/React.createContext({
1509
1670
  client: undefined
@@ -1548,10 +1709,6 @@ function useLifecycleTracker(client) {
1548
1709
 
1549
1710
  var _OptionalReactNativeNavigation = undefined;
1550
1711
 
1551
- var warn = function (name) {
1552
- console.warn("PostHog: Missing ".concat(name, " optional dependency. Some functions may not work as expected..."));
1553
- };
1554
-
1555
1712
  try {
1556
1713
  _OptionalReactNativeNavigation = require('@react-navigation/native');
1557
1714
  } catch (e) {
@@ -1776,14 +1933,20 @@ var autocaptureFromTouchEvent = function (e, posthog, options) {
1776
1933
  }
1777
1934
  };
1778
1935
 
1779
- function PostHogHooks(_a) {
1936
+ function PostHogNavigationHook(_a) {
1780
1937
  var options = _a.options;
1781
1938
  useNavigationTracker(options === null || options === void 0 ? void 0 : options.navigation);
1939
+ return null;
1940
+ }
1941
+
1942
+ function PostHogLifecycleHook() {
1782
1943
  useLifecycleTracker();
1783
1944
  return null;
1784
1945
  }
1785
1946
 
1786
1947
  var PostHogProvider = function (_a) {
1948
+ var _b, _c;
1949
+
1787
1950
  var children = _a.children,
1788
1951
  client = _a.client,
1789
1952
  options = _a.options,
@@ -1796,10 +1959,13 @@ var PostHogProvider = function (_a) {
1796
1959
  posthogRef.current = client ? client : apiKey ? new PostHog(apiKey, options) : undefined;
1797
1960
  }
1798
1961
 
1799
- var autocaptureEnabled = !!autocapture;
1800
1962
  var autocaptureOptions = autocapture && typeof autocapture !== 'boolean' ? autocapture : {};
1801
1963
  var posthog = posthogRef.current;
1802
1964
  var captureTouches = posthog && (autocapture === true || (autocaptureOptions === null || autocaptureOptions === void 0 ? void 0 : autocaptureOptions.captureTouches));
1965
+ 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
1966
+
1967
+ 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
1968
+
1803
1969
  var onTouch = useCallback(function (type, e) {
1804
1970
  // TODO: Improve this to ensure we only capture presses and not just ends of a drag for example
1805
1971
  if (!captureTouches) {
@@ -1809,8 +1975,7 @@ var PostHogProvider = function (_a) {
1809
1975
  if (type === 'end') {
1810
1976
  autocaptureFromTouchEvent(e, posthog, autocaptureOptions);
1811
1977
  }
1812
- }, [posthog, autocapture]); // TODO: Improve this to ensure we only capture presses and not just ends of a drag for example
1813
-
1978
+ }, [posthog, autocapture]);
1814
1979
  return /*#__PURE__*/React.createElement(View, {
1815
1980
  "ph-label": "PostHogProvider",
1816
1981
  style: style || {
@@ -1823,9 +1988,9 @@ var PostHogProvider = function (_a) {
1823
1988
  value: {
1824
1989
  client: posthogRef.current
1825
1990
  }
1826
- }, autocaptureEnabled ? /*#__PURE__*/React.createElement(PostHogHooks, {
1991
+ }, /*#__PURE__*/React.createElement(React.Fragment, null, captureScreens ? /*#__PURE__*/React.createElement(PostHogNavigationHook, {
1827
1992
  options: autocaptureOptions
1828
- }) : null, children));
1993
+ }) : null, captureLifecycle ? /*#__PURE__*/React.createElement(PostHogLifecycleHook, null) : null), children));
1829
1994
  };
1830
1995
 
1831
1996
  export { PostHog, PostHogProvider, PostHog as default, useFeatureFlag, useFeatureFlags, useLifecycleTracker, useNavigationTracker, usePostHog };