posthog-react-native 2.1.1 → 2.1.2

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.d.ts CHANGED
@@ -9,11 +9,6 @@ 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
- };
17
12
  fetchRetryCount?: number;
18
13
  fetchRetryDelay?: number;
19
14
  sessionExpirationTimeSeconds?: number;
@@ -39,8 +34,7 @@ declare type PostHogFetchOptions = {
39
34
  headers: {
40
35
  [key: string]: string;
41
36
  };
42
- body?: string;
43
- signal?: AbortSignal;
37
+ body: string;
44
38
  };
45
39
  declare type PostHogFetchResponse = {
46
40
  status: number;
@@ -114,7 +108,6 @@ declare abstract class PostHogCore {
114
108
  private _optoutOverride;
115
109
  constructor(apiKey: string, options?: PosthogCoreOptions);
116
110
  protected getCommonEventProperties(): any;
117
- protected setupBootstrap(options?: Partial<PosthogCoreOptions>): void;
118
111
  private get props();
119
112
  private set props(value);
120
113
  private clearProps;
@@ -165,7 +158,6 @@ declare abstract class PostHogCore {
165
158
  ***/
166
159
  private decideAsync;
167
160
  private _decideAsync;
168
- private setKnownFeatureFlags;
169
161
  getFeatureFlag(key: string): boolean | string | undefined;
170
162
  getFeatureFlags(): PostHogDecideResponse['featureFlags'] | undefined;
171
163
  isFeatureEnabled(key: string): boolean | undefined;
@@ -218,9 +210,7 @@ declare type PostHogAutocaptureOptions = {
218
210
  maxElementsCaptured?: number;
219
211
  ignoreLabels?: string[];
220
212
  propsToCapture?: string[];
221
- captureScreens?: boolean;
222
213
  navigation?: PostHogAutocaptureNavigationTrackerOptions;
223
- captureLifecycleEvents?: boolean;
224
214
  };
225
215
 
226
216
  declare function _useNavigationTracker(options?: PostHogAutocaptureNavigationTrackerOptions, client?: PostHog): void;
package/lib/index.esm.js CHANGED
@@ -742,26 +742,6 @@ 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
- };
765
745
  Object.defineProperty(PostHogCore.prototype, "props", {
766
746
  // NOTE: Props are lazy loaded from localstorage hence the complex getter setter logic
767
747
  get: function () {
@@ -1005,7 +985,8 @@ var PostHogCore = /** @class */ (function () {
1005
985
  .then(function (r) { return r.json(); })
1006
986
  .then(function (res) {
1007
987
  if (res.featureFlags) {
1008
- _this.setKnownFeatureFlags(res.featureFlags);
988
+ _this.setPersistedProperty(PostHogPersistedProperty.FeatureFlags, res.featureFlags);
989
+ _this._events.emit('featureflags', res.featureFlags);
1009
990
  }
1010
991
  return res;
1011
992
  })
@@ -1016,10 +997,6 @@ var PostHogCore = /** @class */ (function () {
1016
997
  });
1017
998
  });
1018
999
  };
1019
- PostHogCore.prototype.setKnownFeatureFlags = function (featureFlags) {
1020
- this.setPersistedProperty(PostHogPersistedProperty.FeatureFlags, featureFlags);
1021
- this._events.emit('featureflags', featureFlags);
1022
- };
1023
1000
  PostHogCore.prototype.getFeatureFlag = function (key) {
1024
1001
  var featureFlags = this.getFeatureFlags();
1025
1002
  if (!featureFlags) {
@@ -1331,7 +1308,7 @@ var loadStorageAsync = function () {
1331
1308
  return __generator(this, function (_a) {
1332
1309
  switch (_a.label) {
1333
1310
  case 0:
1334
- uri = (FileSystem.documentDirectory || '') + POSTHOG_STORAGE_KEY;
1311
+ uri = FileSystem.documentDirectory + POSTHOG_STORAGE_KEY;
1335
1312
  _a.label = 1;
1336
1313
 
1337
1314
  case 1:
@@ -1368,7 +1345,7 @@ var persitStorageAsync = function (content) {
1368
1345
  return __generator(this, function (_a) {
1369
1346
  switch (_a.label) {
1370
1347
  case 0:
1371
- uri = (FileSystem.documentDirectory || '') + POSTHOG_STORAGE_KEY;
1348
+ uri = FileSystem.documentDirectory + POSTHOG_STORAGE_KEY;
1372
1349
  data = {
1373
1350
  version: POSTHOG_STORAGE_VERSION,
1374
1351
  content: content
@@ -1431,7 +1408,7 @@ var preloadSemiAsyncStorage = function () {
1431
1408
  return _preloadSemiAsyncStoragePromise;
1432
1409
  };
1433
1410
 
1434
- var version = "2.1.1";
1411
+ var version = "2.0.0";
1435
1412
 
1436
1413
  var PostHog =
1437
1414
  /** @class */
@@ -1449,8 +1426,6 @@ function (_super) {
1449
1426
  // It is possible that the old library was used so we try to get the legacy distinctID
1450
1427
 
1451
1428
  void preloadSemiAsyncStorage().then(function () {
1452
- _this.setupBootstrap(options);
1453
-
1454
1429
  if (!SemiAsyncStorage.getItem(PostHogPersistedProperty.AnonymousId)) {
1455
1430
  getLegacyValues().then(function (legacyValues) {
1456
1431
  if (legacyValues === null || legacyValues === void 0 ? void 0 : legacyValues.distinctId) {
@@ -1477,7 +1452,7 @@ function (_super) {
1477
1452
 
1478
1453
  PostHog.prototype.setPersistedProperty = function (key, value) {
1479
1454
  if (this._persistence === 'memory') {
1480
- return this._memoryStorage.setProperty(key, value);
1455
+ return this._memoryStorage.getProperty(key);
1481
1456
  }
1482
1457
 
1483
1458
  return value !== null ? SemiAsyncStorage.setItem(key, value) : SemiAsyncStorage.removeItem(key);
@@ -1801,20 +1776,14 @@ var autocaptureFromTouchEvent = function (e, posthog, options) {
1801
1776
  }
1802
1777
  };
1803
1778
 
1804
- function PostHogNavigationHook(_a) {
1779
+ function PostHogHooks(_a) {
1805
1780
  var options = _a.options;
1806
1781
  useNavigationTracker(options === null || options === void 0 ? void 0 : options.navigation);
1807
- return null;
1808
- }
1809
-
1810
- function PostHogLifecycleHook() {
1811
1782
  useLifecycleTracker();
1812
1783
  return null;
1813
1784
  }
1814
1785
 
1815
1786
  var PostHogProvider = function (_a) {
1816
- var _b, _c;
1817
-
1818
1787
  var children = _a.children,
1819
1788
  client = _a.client,
1820
1789
  options = _a.options,
@@ -1827,13 +1796,10 @@ var PostHogProvider = function (_a) {
1827
1796
  posthogRef.current = client ? client : apiKey ? new PostHog(apiKey, options) : undefined;
1828
1797
  }
1829
1798
 
1799
+ var autocaptureEnabled = !!autocapture;
1830
1800
  var autocaptureOptions = autocapture && typeof autocapture !== 'boolean' ? autocapture : {};
1831
1801
  var posthog = posthogRef.current;
1832
1802
  var captureTouches = posthog && (autocapture === true || (autocaptureOptions === null || autocaptureOptions === void 0 ? void 0 : autocaptureOptions.captureTouches));
1833
- 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
1834
-
1835
- 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
1836
-
1837
1803
  var onTouch = useCallback(function (type, e) {
1838
1804
  // TODO: Improve this to ensure we only capture presses and not just ends of a drag for example
1839
1805
  if (!captureTouches) {
@@ -1843,7 +1809,8 @@ var PostHogProvider = function (_a) {
1843
1809
  if (type === 'end') {
1844
1810
  autocaptureFromTouchEvent(e, posthog, autocaptureOptions);
1845
1811
  }
1846
- }, [posthog, autocapture]);
1812
+ }, [posthog, autocapture]); // TODO: Improve this to ensure we only capture presses and not just ends of a drag for example
1813
+
1847
1814
  return /*#__PURE__*/React.createElement(View, {
1848
1815
  "ph-label": "PostHogProvider",
1849
1816
  style: style || {
@@ -1856,9 +1823,9 @@ var PostHogProvider = function (_a) {
1856
1823
  value: {
1857
1824
  client: posthogRef.current
1858
1825
  }
1859
- }, /*#__PURE__*/React.createElement(React.Fragment, null, captureScreens ? /*#__PURE__*/React.createElement(PostHogNavigationHook, {
1826
+ }, autocaptureEnabled ? /*#__PURE__*/React.createElement(PostHogHooks, {
1860
1827
  options: autocaptureOptions
1861
- }) : null, captureLifecycle ? /*#__PURE__*/React.createElement(PostHogLifecycleHook, null) : null), children));
1828
+ }) : null, children));
1862
1829
  };
1863
1830
 
1864
1831
  export { PostHog, PostHogProvider, PostHog as default, useFeatureFlag, useFeatureFlags, useLifecycleTracker, useNavigationTracker, usePostHog };