posthog-react-native 2.0.0-alpha9 → 2.0.0
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 +131 -94
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +16 -7
- package/lib/index.esm.js +130 -94
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/eventemitter.d.ts +2 -2
- package/lib/posthog-core/src/index.d.ts +6 -3
- package/lib/posthog-core/src/storage-memory.d.ts +6 -0
- package/lib/posthog-core/src/types.d.ts +2 -1
- package/lib/posthog-core/src/utils.d.ts +0 -1
- package/lib/posthog-react-native/src/optional-imports.d.ts +0 -4
- package/lib/posthog-react-native/src/posthog-rn.d.ts +5 -1
- package/lib/posthog-react-native/src/types.d.ts +1 -0
- package/package.json +6 -14
package/lib/index.d.ts
CHANGED
|
@@ -9,13 +9,13 @@ declare type PosthogCoreOptions = {
|
|
|
9
9
|
enable?: boolean;
|
|
10
10
|
sendFeatureFlagEvent?: boolean;
|
|
11
11
|
preloadFeatureFlags?: boolean;
|
|
12
|
-
decidePollInterval?: number;
|
|
13
12
|
fetchRetryCount?: number;
|
|
14
13
|
fetchRetryDelay?: number;
|
|
15
14
|
sessionExpirationTimeSeconds?: number;
|
|
16
15
|
captureMode?: 'json' | 'form';
|
|
17
16
|
};
|
|
18
17
|
declare enum PostHogPersistedProperty {
|
|
18
|
+
AnonymousId = "anonymous_id",
|
|
19
19
|
DistinctId = "distinct_id",
|
|
20
20
|
Props = "props",
|
|
21
21
|
FeatureFlags = "feature_flags",
|
|
@@ -37,6 +37,7 @@ declare type PostHogFetchOptions = {
|
|
|
37
37
|
declare type PostHogFetchResponse = {
|
|
38
38
|
status: number;
|
|
39
39
|
text: () => Promise<string>;
|
|
40
|
+
json: () => Promise<any>;
|
|
40
41
|
};
|
|
41
42
|
declare type PostHogEventProperties = {
|
|
42
43
|
[key: string]: any;
|
|
@@ -75,10 +76,10 @@ interface RetriableOptions {
|
|
|
75
76
|
|
|
76
77
|
declare class SimpleEventEmitter {
|
|
77
78
|
events: {
|
|
78
|
-
[key: string]: ((
|
|
79
|
+
[key: string]: ((...args: any[]) => void)[];
|
|
79
80
|
};
|
|
80
81
|
constructor();
|
|
81
|
-
on(event: string, listener: (
|
|
82
|
+
on(event: string, listener: (...args: any[]) => void): () => void;
|
|
82
83
|
emit(event: string, payload: any): void;
|
|
83
84
|
}
|
|
84
85
|
|
|
@@ -90,11 +91,10 @@ declare abstract class PostHogCore {
|
|
|
90
91
|
private captureMode;
|
|
91
92
|
private sendFeatureFlagEvent;
|
|
92
93
|
private flagCallReported;
|
|
94
|
+
private removeDebugCallback?;
|
|
93
95
|
protected _events: SimpleEventEmitter;
|
|
94
96
|
protected _flushTimer?: any;
|
|
95
97
|
protected _decideResponsePromise?: Promise<PostHogDecideResponse>;
|
|
96
|
-
protected _decideTimer?: any;
|
|
97
|
-
protected _decidePollInterval: number;
|
|
98
98
|
protected _retryOptions: RetriableOptions;
|
|
99
99
|
protected _sessionExpirationTimeSeconds: number;
|
|
100
100
|
abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
|
|
@@ -112,10 +112,13 @@ declare abstract class PostHogCore {
|
|
|
112
112
|
get optedOut(): boolean;
|
|
113
113
|
optIn(): void;
|
|
114
114
|
optOut(): void;
|
|
115
|
-
on(event: string, cb: (
|
|
115
|
+
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
116
116
|
reset(): void;
|
|
117
|
+
debug(enabled?: boolean): void;
|
|
117
118
|
private buildPayload;
|
|
118
119
|
getSessionId(): string | undefined;
|
|
120
|
+
resetSessionId(): void;
|
|
121
|
+
getAnonymousId(): string;
|
|
119
122
|
getDistinctId(): string;
|
|
120
123
|
register(properties: {
|
|
121
124
|
[key: string]: any;
|
|
@@ -148,6 +151,7 @@ declare abstract class PostHogCore {
|
|
|
148
151
|
isFeatureEnabled(key: string, defaultResult?: boolean): boolean;
|
|
149
152
|
reloadFeatureFlagsAsync(): Promise<PostHogDecideResponse['featureFlags']>;
|
|
150
153
|
onFeatureFlags(cb: (flags: PostHogDecideResponse['featureFlags']) => void): () => void;
|
|
154
|
+
onFeatureFlag(key: string, cb: (value: string | boolean) => void): () => void;
|
|
151
155
|
overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): void;
|
|
152
156
|
/***
|
|
153
157
|
*** QUEUEING AND FLUSHING
|
|
@@ -160,8 +164,12 @@ declare abstract class PostHogCore {
|
|
|
160
164
|
shutdown(): void;
|
|
161
165
|
}
|
|
162
166
|
|
|
163
|
-
declare type PostHogOptions = PosthogCoreOptions
|
|
167
|
+
declare type PostHogOptions = PosthogCoreOptions & {
|
|
168
|
+
persistence?: 'memory' | 'file';
|
|
169
|
+
};
|
|
164
170
|
declare class PostHog extends PostHogCore {
|
|
171
|
+
private _persistence;
|
|
172
|
+
private _memoryStorage;
|
|
165
173
|
static initAsync(): Promise<void>;
|
|
166
174
|
constructor(apiKey: string, options?: PostHogOptions);
|
|
167
175
|
getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
|
|
@@ -186,6 +194,7 @@ declare type PostHogAutocaptureOptions = {
|
|
|
186
194
|
noCaptureProp?: string;
|
|
187
195
|
maxElementsCaptured?: number;
|
|
188
196
|
ignoreLabels?: string[];
|
|
197
|
+
propsToCapture?: string[];
|
|
189
198
|
navigation?: PostHogAutocaptureNavigationTrackerOptions;
|
|
190
199
|
};
|
|
191
200
|
|
package/lib/index.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Platform, Dimensions, AppState, View } from 'react-native';
|
|
2
2
|
import * as ExpoApplication from 'expo-application';
|
|
3
3
|
import * as ExpoDevice from 'expo-device';
|
|
4
|
+
import * as ExpoLocalization from 'expo-localization';
|
|
4
5
|
import * as FileSystem from 'expo-file-system';
|
|
5
6
|
import React, { useRef, useEffect, useState, useCallback } from 'react';
|
|
6
7
|
|
|
@@ -137,6 +138,7 @@ function __generator(thisArg, body) {
|
|
|
137
138
|
|
|
138
139
|
var PostHogPersistedProperty;
|
|
139
140
|
(function (PostHogPersistedProperty) {
|
|
141
|
+
PostHogPersistedProperty["AnonymousId"] = "anonymous_id";
|
|
140
142
|
PostHogPersistedProperty["DistinctId"] = "distinct_id";
|
|
141
143
|
PostHogPersistedProperty["Props"] = "props";
|
|
142
144
|
PostHogPersistedProperty["FeatureFlags"] = "feature_flags";
|
|
@@ -162,7 +164,7 @@ function retriable(fn, props) {
|
|
|
162
164
|
return __generator(this, function (_d) {
|
|
163
165
|
switch (_d.label) {
|
|
164
166
|
case 0:
|
|
165
|
-
_a = props.retryCount, retryCount = _a === void 0 ? 3 : _a, _b = props.retryDelay, retryDelay = _b === void 0 ?
|
|
167
|
+
_a = props.retryCount, retryCount = _a === void 0 ? 3 : _a, _b = props.retryDelay, retryDelay = _b === void 0 ? 5000 : _b, _c = props.retryCheck, retryCheck = _c === void 0 ? function () { return true; } : _c;
|
|
166
168
|
lastError = null;
|
|
167
169
|
i = 0;
|
|
168
170
|
_d.label = 1;
|
|
@@ -676,13 +678,14 @@ var SimpleEventEmitter = /** @class */ (function () {
|
|
|
676
678
|
};
|
|
677
679
|
};
|
|
678
680
|
SimpleEventEmitter.prototype.emit = function (event, payload) {
|
|
679
|
-
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
for (var _i = 0, _a = this.events[event]; _i < _a.length; _i++) {
|
|
681
|
+
for (var _i = 0, _a = this.events[event] || []; _i < _a.length; _i++) {
|
|
683
682
|
var listener = _a[_i];
|
|
684
683
|
listener(payload);
|
|
685
684
|
}
|
|
685
|
+
for (var _b = 0, _c = this.events['*'] || []; _b < _c.length; _b++) {
|
|
686
|
+
var listener = _c[_b];
|
|
687
|
+
listener(event, payload);
|
|
688
|
+
}
|
|
686
689
|
};
|
|
687
690
|
return SimpleEventEmitter;
|
|
688
691
|
}());
|
|
@@ -690,7 +693,7 @@ var SimpleEventEmitter = /** @class */ (function () {
|
|
|
690
693
|
var PostHogCore = /** @class */ (function () {
|
|
691
694
|
function PostHogCore(apiKey, options) {
|
|
692
695
|
var _this = this;
|
|
693
|
-
var _a, _b, _c, _d, _e
|
|
696
|
+
var _a, _b, _c, _d, _e;
|
|
694
697
|
this.flagCallReported = {};
|
|
695
698
|
// internal
|
|
696
699
|
this._events = new SimpleEventEmitter();
|
|
@@ -701,14 +704,13 @@ var PostHogCore = /** @class */ (function () {
|
|
|
701
704
|
this.flushInterval = (_a = options === null || options === void 0 ? void 0 : options.flushInterval) !== null && _a !== void 0 ? _a : 10000;
|
|
702
705
|
this.captureMode = (options === null || options === void 0 ? void 0 : options.captureMode) || 'form';
|
|
703
706
|
this.sendFeatureFlagEvent = (_b = options === null || options === void 0 ? void 0 : options.sendFeatureFlagEvent) !== null && _b !== void 0 ? _b : true;
|
|
704
|
-
this._decidePollInterval = Math.max(0, (_c = options === null || options === void 0 ? void 0 : options.decidePollInterval) !== null && _c !== void 0 ? _c : 30000);
|
|
705
707
|
// If enable is explicitly set to false we override the optout
|
|
706
708
|
this._optoutOverride = (options === null || options === void 0 ? void 0 : options.enable) === false;
|
|
707
709
|
this._retryOptions = {
|
|
708
|
-
retryCount: (
|
|
709
|
-
retryDelay: (
|
|
710
|
+
retryCount: (_c = options === null || options === void 0 ? void 0 : options.fetchRetryCount) !== null && _c !== void 0 ? _c : 3,
|
|
711
|
+
retryDelay: (_d = options === null || options === void 0 ? void 0 : options.fetchRetryDelay) !== null && _d !== void 0 ? _d : 3000,
|
|
710
712
|
};
|
|
711
|
-
this._sessionExpirationTimeSeconds = (
|
|
713
|
+
this._sessionExpirationTimeSeconds = (_e = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _e !== void 0 ? _e : 1800; // 30 minutes
|
|
712
714
|
// NOTE: It is important we don't initiate anything in the constructor as some async IO may still be underway on the parent
|
|
713
715
|
if ((options === null || options === void 0 ? void 0 : options.preloadFeatureFlags) !== false) {
|
|
714
716
|
safeSetTimeout(function () {
|
|
@@ -760,7 +762,14 @@ var PostHogCore = /** @class */ (function () {
|
|
|
760
762
|
for (var key in PostHogPersistedProperty) {
|
|
761
763
|
this.setPersistedProperty(PostHogPersistedProperty[key], null);
|
|
762
764
|
}
|
|
763
|
-
|
|
765
|
+
};
|
|
766
|
+
PostHogCore.prototype.debug = function (enabled) {
|
|
767
|
+
var _a;
|
|
768
|
+
if (enabled === void 0) { enabled = true; }
|
|
769
|
+
(_a = this.removeDebugCallback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
770
|
+
if (enabled) {
|
|
771
|
+
this.removeDebugCallback = this.on('*', function (event, payload) { return console.log('PostHog Debug', event, payload); });
|
|
772
|
+
}
|
|
764
773
|
};
|
|
765
774
|
PostHogCore.prototype.buildPayload = function (payload) {
|
|
766
775
|
return {
|
|
@@ -779,13 +788,19 @@ var PostHogCore = /** @class */ (function () {
|
|
|
779
788
|
this.setPersistedProperty(PostHogPersistedProperty.SessionLastTimestamp, Date.now());
|
|
780
789
|
return sessionId;
|
|
781
790
|
};
|
|
782
|
-
PostHogCore.prototype.
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
791
|
+
PostHogCore.prototype.resetSessionId = function () {
|
|
792
|
+
this.setPersistedProperty(PostHogPersistedProperty.SessionId, null);
|
|
793
|
+
};
|
|
794
|
+
PostHogCore.prototype.getAnonymousId = function () {
|
|
795
|
+
var anonId = this.getPersistedProperty(PostHogPersistedProperty.AnonymousId);
|
|
796
|
+
if (!anonId) {
|
|
797
|
+
anonId = generateUUID(globalThis);
|
|
798
|
+
this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, anonId);
|
|
787
799
|
}
|
|
788
|
-
return
|
|
800
|
+
return anonId;
|
|
801
|
+
};
|
|
802
|
+
PostHogCore.prototype.getDistinctId = function () {
|
|
803
|
+
return this.getPersistedProperty(PostHogPersistedProperty.DistinctId) || this.getAnonymousId();
|
|
789
804
|
};
|
|
790
805
|
PostHogCore.prototype.register = function (properties) {
|
|
791
806
|
this.props = __assign(__assign({}, this.props), properties);
|
|
@@ -799,27 +814,28 @@ var PostHogCore = /** @class */ (function () {
|
|
|
799
814
|
*** TRACKING
|
|
800
815
|
***/
|
|
801
816
|
PostHogCore.prototype.identify = function (distinctId, properties) {
|
|
802
|
-
|
|
817
|
+
var previousDistinctId = this.getDistinctId();
|
|
818
|
+
distinctId = distinctId || previousDistinctId;
|
|
803
819
|
if (properties === null || properties === void 0 ? void 0 : properties.$groups) {
|
|
804
820
|
this.groups(properties.$groups);
|
|
805
821
|
}
|
|
806
822
|
var payload = __assign(__assign({}, this.buildPayload({
|
|
807
823
|
distinct_id: distinctId,
|
|
808
824
|
event: '$identify',
|
|
809
|
-
properties: __assign(__assign({}, (properties || {})), { $anon_distinct_id: this.
|
|
825
|
+
properties: __assign(__assign({}, (properties || {})), { $anon_distinct_id: this.getAnonymousId() }),
|
|
810
826
|
})), { $set: properties });
|
|
811
|
-
if (distinctId !==
|
|
827
|
+
if (distinctId !== previousDistinctId) {
|
|
828
|
+
// We keep the AnonymousId to be used by decide calls and identify to link the previousId
|
|
829
|
+
this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, previousDistinctId);
|
|
812
830
|
this.setPersistedProperty(PostHogPersistedProperty.DistinctId, distinctId);
|
|
831
|
+
if (this.getFeatureFlags()) {
|
|
832
|
+
void this.reloadFeatureFlagsAsync();
|
|
833
|
+
}
|
|
813
834
|
}
|
|
814
835
|
this.enqueue('identify', payload);
|
|
815
836
|
return this;
|
|
816
837
|
};
|
|
817
838
|
PostHogCore.prototype.capture = function (event, properties) {
|
|
818
|
-
// NOTE: Legacy nodejs implementation uses groups
|
|
819
|
-
if (properties && properties['groups']) {
|
|
820
|
-
properties.$groups = properties.groups;
|
|
821
|
-
delete properties.groups;
|
|
822
|
-
}
|
|
823
839
|
if (properties === null || properties === void 0 ? void 0 : properties.$groups) {
|
|
824
840
|
this.groups(properties.$groups);
|
|
825
841
|
}
|
|
@@ -858,7 +874,7 @@ var PostHogCore = /** @class */ (function () {
|
|
|
858
874
|
this.register({
|
|
859
875
|
$groups: __assign(__assign({}, existingGroups), groups),
|
|
860
876
|
});
|
|
861
|
-
if (Object.keys(groups).find(function (type) { return existingGroups[type] !== groups[type]; }) && this.
|
|
877
|
+
if (Object.keys(groups).find(function (type) { return existingGroups[type] !== groups[type]; }) && this.getFeatureFlags()) {
|
|
862
878
|
void this.reloadFeatureFlagsAsync();
|
|
863
879
|
}
|
|
864
880
|
return this;
|
|
@@ -902,16 +918,24 @@ var PostHogCore = /** @class */ (function () {
|
|
|
902
918
|
fetchOptions = {
|
|
903
919
|
method: 'POST',
|
|
904
920
|
headers: { 'Content-Type': 'application/json' },
|
|
905
|
-
body: JSON.stringify({
|
|
921
|
+
body: JSON.stringify({
|
|
922
|
+
token: this.apiKey,
|
|
923
|
+
distinct_id: distinctId,
|
|
924
|
+
$anon_distinct_id: this.getAnonymousId(),
|
|
925
|
+
groups: groups,
|
|
926
|
+
}),
|
|
906
927
|
};
|
|
907
928
|
this._decideResponsePromise = this.fetchWithRetry(url, fetchOptions)
|
|
908
929
|
.then(function (r) { return r.json(); })
|
|
909
930
|
.then(function (res) {
|
|
910
931
|
if (res.featureFlags) {
|
|
911
932
|
_this.setPersistedProperty(PostHogPersistedProperty.FeatureFlags, res.featureFlags);
|
|
933
|
+
_this._events.emit('featureflags', res.featureFlags);
|
|
912
934
|
}
|
|
913
|
-
_this._events.emit('featureflags', res.featureFlags);
|
|
914
935
|
return res;
|
|
936
|
+
})
|
|
937
|
+
.finally(function () {
|
|
938
|
+
_this._decideResponsePromise = undefined;
|
|
915
939
|
});
|
|
916
940
|
return [2 /*return*/, this._decideResponsePromise];
|
|
917
941
|
});
|
|
@@ -960,27 +984,16 @@ var PostHogCore = /** @class */ (function () {
|
|
|
960
984
|
};
|
|
961
985
|
PostHogCore.prototype.reloadFeatureFlagsAsync = function () {
|
|
962
986
|
return __awaiter(this, void 0, void 0, function () {
|
|
963
|
-
var _this = this;
|
|
964
987
|
return __generator(this, function (_a) {
|
|
965
988
|
switch (_a.label) {
|
|
966
|
-
case 0:
|
|
967
|
-
clearTimeout(this._decideTimer);
|
|
968
|
-
if (this._decidePollInterval) {
|
|
969
|
-
this._decideTimer = safeSetTimeout(function () { return _this.reloadFeatureFlagsAsync(); }, this._decidePollInterval);
|
|
970
|
-
}
|
|
971
|
-
this._decideResponsePromise = undefined;
|
|
972
|
-
return [4 /*yield*/, this.decideAsync()];
|
|
989
|
+
case 0: return [4 /*yield*/, this.decideAsync()];
|
|
973
990
|
case 1: return [2 /*return*/, (_a.sent()).featureFlags];
|
|
974
991
|
}
|
|
975
992
|
});
|
|
976
993
|
});
|
|
977
994
|
};
|
|
978
|
-
// When listening to feature flags polling is active
|
|
979
995
|
PostHogCore.prototype.onFeatureFlags = function (cb) {
|
|
980
996
|
var _this = this;
|
|
981
|
-
if (!this._decideTimer) {
|
|
982
|
-
void this.reloadFeatureFlagsAsync();
|
|
983
|
-
}
|
|
984
997
|
return this.on('featureflags', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
985
998
|
var flags;
|
|
986
999
|
return __generator(this, function (_a) {
|
|
@@ -992,6 +1005,19 @@ var PostHogCore = /** @class */ (function () {
|
|
|
992
1005
|
});
|
|
993
1006
|
}); });
|
|
994
1007
|
};
|
|
1008
|
+
PostHogCore.prototype.onFeatureFlag = function (key, cb) {
|
|
1009
|
+
var _this = this;
|
|
1010
|
+
return this.on('featureflags', function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1011
|
+
var flagResponse;
|
|
1012
|
+
return __generator(this, function (_a) {
|
|
1013
|
+
flagResponse = this.getFeatureFlag(key);
|
|
1014
|
+
if (flagResponse !== undefined) {
|
|
1015
|
+
cb(flagResponse);
|
|
1016
|
+
}
|
|
1017
|
+
return [2 /*return*/];
|
|
1018
|
+
});
|
|
1019
|
+
}); });
|
|
1020
|
+
};
|
|
995
1021
|
PostHogCore.prototype.overrideFeatureFlag = function (flags) {
|
|
996
1022
|
if (flags === null) {
|
|
997
1023
|
return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, null);
|
|
@@ -1099,7 +1125,6 @@ var PostHogCore = /** @class */ (function () {
|
|
|
1099
1125
|
return __generator(this, function (_a) {
|
|
1100
1126
|
switch (_a.label) {
|
|
1101
1127
|
case 0:
|
|
1102
|
-
clearTimeout(this._decideTimer);
|
|
1103
1128
|
clearTimeout(this._flushTimer);
|
|
1104
1129
|
return [4 /*yield*/, this.flushAsync()];
|
|
1105
1130
|
case 1:
|
|
@@ -1115,6 +1140,19 @@ var PostHogCore = /** @class */ (function () {
|
|
|
1115
1140
|
return PostHogCore;
|
|
1116
1141
|
}());
|
|
1117
1142
|
|
|
1143
|
+
var PostHogMemoryStorage = /** @class */ (function () {
|
|
1144
|
+
function PostHogMemoryStorage() {
|
|
1145
|
+
this._memoryStorage = {};
|
|
1146
|
+
}
|
|
1147
|
+
PostHogMemoryStorage.prototype.getProperty = function (key) {
|
|
1148
|
+
return this._memoryStorage[key];
|
|
1149
|
+
};
|
|
1150
|
+
PostHogMemoryStorage.prototype.setProperty = function (key, value) {
|
|
1151
|
+
this._memoryStorage[key] = value !== null ? value : undefined;
|
|
1152
|
+
};
|
|
1153
|
+
return PostHogMemoryStorage;
|
|
1154
|
+
}());
|
|
1155
|
+
|
|
1118
1156
|
var getLegacyValues = function () {
|
|
1119
1157
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
1120
1158
|
var posthogFileDirectory, posthogDistinctIdFile, posthogAnonymousIdFile, res, _a, _b, _c, _d, _e, _f;
|
|
@@ -1299,36 +1337,7 @@ var preloadSemiAsyncStorage = function () {
|
|
|
1299
1337
|
return _preloadSemiAsyncStoragePromise;
|
|
1300
1338
|
};
|
|
1301
1339
|
|
|
1302
|
-
var
|
|
1303
|
-
var _OptionalExpoLocalization = undefined;
|
|
1304
|
-
var _OptionalExpoNetwork = undefined;
|
|
1305
|
-
|
|
1306
|
-
var warn = function (name) {
|
|
1307
|
-
console.warn("PostHog: Missing ".concat(name, " optional dependency. Some functions may not work as expected..."));
|
|
1308
|
-
};
|
|
1309
|
-
|
|
1310
|
-
try {
|
|
1311
|
-
_OptionalReactNativeNavigation = require('@react-navigation/native');
|
|
1312
|
-
} catch (e) {
|
|
1313
|
-
warn('@react-navigation/native');
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
try {
|
|
1317
|
-
_OptionalExpoLocalization = require('expo-localization');
|
|
1318
|
-
} catch (e) {
|
|
1319
|
-
warn('expo-localization');
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
try {
|
|
1323
|
-
_OptionalExpoNetwork = require('expo-network');
|
|
1324
|
-
} catch (e) {
|
|
1325
|
-
warn('expo-network');
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
var OptionalReactNativeNavigation = _OptionalReactNativeNavigation;
|
|
1329
|
-
var OptionalExpoLocalization = _OptionalExpoLocalization;
|
|
1330
|
-
|
|
1331
|
-
var version = "2.0.0-alpha9";
|
|
1340
|
+
var version = "2.0.0";
|
|
1332
1341
|
|
|
1333
1342
|
var PostHog =
|
|
1334
1343
|
/** @class */
|
|
@@ -1338,16 +1347,19 @@ function (_super) {
|
|
|
1338
1347
|
function PostHog(apiKey, options) {
|
|
1339
1348
|
var _this = _super.call(this, apiKey, options) || this;
|
|
1340
1349
|
|
|
1350
|
+
_this._memoryStorage = new PostHogMemoryStorage();
|
|
1351
|
+
_this._persistence = options === null || options === void 0 ? void 0 : options.persistence;
|
|
1341
1352
|
AppState.addEventListener('change', function () {
|
|
1342
1353
|
_this.flush();
|
|
1343
1354
|
}); // Ensure the async storage has been preloaded (this call is cached)
|
|
1344
1355
|
// It is possible that the old library was used so we try to get the legacy distinctID
|
|
1345
1356
|
|
|
1346
1357
|
void preloadSemiAsyncStorage().then(function () {
|
|
1347
|
-
if (!SemiAsyncStorage.getItem(PostHogPersistedProperty.
|
|
1358
|
+
if (!SemiAsyncStorage.getItem(PostHogPersistedProperty.AnonymousId)) {
|
|
1348
1359
|
getLegacyValues().then(function (legacyValues) {
|
|
1349
1360
|
if (legacyValues === null || legacyValues === void 0 ? void 0 : legacyValues.distinctId) {
|
|
1350
1361
|
SemiAsyncStorage.setItem(PostHogPersistedProperty.DistinctId, legacyValues.distinctId);
|
|
1362
|
+
SemiAsyncStorage.setItem(PostHogPersistedProperty.AnonymousId, legacyValues.anonymousId);
|
|
1351
1363
|
}
|
|
1352
1364
|
});
|
|
1353
1365
|
}
|
|
@@ -1360,10 +1372,18 @@ function (_super) {
|
|
|
1360
1372
|
};
|
|
1361
1373
|
|
|
1362
1374
|
PostHog.prototype.getPersistedProperty = function (key) {
|
|
1375
|
+
if (this._persistence === 'memory') {
|
|
1376
|
+
return this._memoryStorage.getProperty(key);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1363
1379
|
return SemiAsyncStorage.getItem(key) || undefined;
|
|
1364
1380
|
};
|
|
1365
1381
|
|
|
1366
1382
|
PostHog.prototype.setPersistedProperty = function (key, value) {
|
|
1383
|
+
if (this._persistence === 'memory') {
|
|
1384
|
+
return this._memoryStorage.getProperty(key);
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1367
1387
|
return value !== null ? SemiAsyncStorage.setItem(key, value) : SemiAsyncStorage.removeItem(key);
|
|
1368
1388
|
};
|
|
1369
1389
|
|
|
@@ -1380,29 +1400,24 @@ function (_super) {
|
|
|
1380
1400
|
};
|
|
1381
1401
|
|
|
1382
1402
|
PostHog.prototype.getCustomUserAgent = function () {
|
|
1383
|
-
// TODO
|
|
1384
1403
|
return;
|
|
1385
1404
|
};
|
|
1386
1405
|
|
|
1387
1406
|
PostHog.prototype.getCommonEventProperties = function () {
|
|
1388
1407
|
return __assign(__assign({}, _super.prototype.getCommonEventProperties.call(this)), {
|
|
1389
1408
|
$app_build: '1',
|
|
1390
|
-
$app_name: ExpoApplication
|
|
1391
|
-
$app_namespace: ExpoApplication
|
|
1392
|
-
$app_version: ExpoApplication
|
|
1393
|
-
|
|
1394
|
-
$
|
|
1395
|
-
|
|
1396
|
-
$
|
|
1397
|
-
|
|
1398
|
-
$
|
|
1399
|
-
// "$network_cellular": false,
|
|
1400
|
-
// "$network_wifi": true,
|
|
1401
|
-
$os_name: ExpoDevice === null || ExpoDevice === void 0 ? void 0 : ExpoDevice.osName,
|
|
1402
|
-
$os_version: ExpoDevice === null || ExpoDevice === void 0 ? void 0 : ExpoDevice.osVersion,
|
|
1409
|
+
$app_name: ExpoApplication.applicationName,
|
|
1410
|
+
$app_namespace: ExpoApplication.applicationId,
|
|
1411
|
+
$app_version: ExpoApplication.nativeApplicationVersion,
|
|
1412
|
+
$device_manufacturer: ExpoDevice.manufacturer,
|
|
1413
|
+
$device_name: ExpoDevice.modelName,
|
|
1414
|
+
$device_type: Platform.OS,
|
|
1415
|
+
$locale: ExpoLocalization.locale,
|
|
1416
|
+
$os_name: ExpoDevice.osName,
|
|
1417
|
+
$os_version: ExpoDevice.osVersion,
|
|
1403
1418
|
$screen_height: Dimensions.get('screen').height,
|
|
1404
1419
|
$screen_width: Dimensions.get('screen').width,
|
|
1405
|
-
$timezone:
|
|
1420
|
+
$timezone: ExpoLocalization.timezone
|
|
1406
1421
|
});
|
|
1407
1422
|
}; // Custom methods
|
|
1408
1423
|
|
|
@@ -1460,6 +1475,20 @@ function useLifecycleTracker(client) {
|
|
|
1460
1475
|
}, [posthog]);
|
|
1461
1476
|
}
|
|
1462
1477
|
|
|
1478
|
+
var _OptionalReactNativeNavigation = undefined;
|
|
1479
|
+
|
|
1480
|
+
var warn = function (name) {
|
|
1481
|
+
console.warn("PostHog: Missing ".concat(name, " optional dependency. Some functions may not work as expected..."));
|
|
1482
|
+
};
|
|
1483
|
+
|
|
1484
|
+
try {
|
|
1485
|
+
_OptionalReactNativeNavigation = require('@react-navigation/native');
|
|
1486
|
+
} catch (e) {
|
|
1487
|
+
warn('@react-navigation/native');
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
var OptionalReactNativeNavigation = _OptionalReactNativeNavigation;
|
|
1491
|
+
|
|
1463
1492
|
function _useNavigationTrackerDisabled() {
|
|
1464
1493
|
return;
|
|
1465
1494
|
}
|
|
@@ -1606,7 +1635,9 @@ var autocaptureFromTouchEvent = function (e, posthog, options) {
|
|
|
1606
1635
|
_e = options.maxElementsCaptured,
|
|
1607
1636
|
maxElementsCaptured = _e === void 0 ? 20 : _e,
|
|
1608
1637
|
_f = options.ignoreLabels,
|
|
1609
|
-
ignoreLabels = _f === void 0 ? [] : _f
|
|
1638
|
+
ignoreLabels = _f === void 0 ? [] : _f,
|
|
1639
|
+
_g = options.propsToCapture,
|
|
1640
|
+
propsToCapture = _g === void 0 ? ['style', 'testID', 'accessibilityLabel', 'ph-label'] : _g;
|
|
1610
1641
|
|
|
1611
1642
|
if (!e._targetInst) {
|
|
1612
1643
|
return;
|
|
@@ -1621,8 +1652,19 @@ var autocaptureFromTouchEvent = function (e, posthog, options) {
|
|
|
1621
1652
|
};
|
|
1622
1653
|
var props = currentInst.memoizedProps;
|
|
1623
1654
|
|
|
1655
|
+
if (props === null || props === void 0 ? void 0 : props[noCaptureProp]) {
|
|
1656
|
+
return {
|
|
1657
|
+
value: void 0
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1624
1661
|
if (props) {
|
|
1662
|
+
// Capture only props we have said to capture. By default this is only "safe" props
|
|
1625
1663
|
Object.keys(props).forEach(function (key) {
|
|
1664
|
+
if (!propsToCapture.includes(key)) {
|
|
1665
|
+
return;
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1626
1668
|
var value = props[key];
|
|
1627
1669
|
|
|
1628
1670
|
if (key === 'style') {
|
|
@@ -1635,12 +1677,6 @@ var autocaptureFromTouchEvent = function (e, posthog, options) {
|
|
|
1635
1677
|
}
|
|
1636
1678
|
}
|
|
1637
1679
|
});
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
|
-
if (props === null || props === void 0 ? void 0 : props[noCaptureProp]) {
|
|
1641
|
-
return {
|
|
1642
|
-
value: void 0
|
|
1643
|
-
};
|
|
1644
1680
|
} // Try and find a sensible label
|
|
1645
1681
|
|
|
1646
1682
|
|