posthog-react-native 1.1.3 → 2.0.0-alpha10

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.
Files changed (129) hide show
  1. package/README.md +9 -0
  2. package/lib/index.cjs.js +1773 -0
  3. package/lib/index.cjs.js.map +1 -0
  4. package/lib/index.d.ts +214 -0
  5. package/lib/index.esm.js +1737 -0
  6. package/lib/index.esm.js.map +1 -0
  7. package/lib/node_modules/tslib/tslib.es6.d.ts +35 -0
  8. package/lib/posthog-core/src/eventemitter.d.ts +8 -0
  9. package/lib/posthog-core/src/index.d.ts +87 -0
  10. package/lib/posthog-core/src/lz-string.d.ts +8 -0
  11. package/lib/posthog-core/src/types.d.ts +68 -0
  12. package/lib/posthog-core/src/utils.d.ts +13 -0
  13. package/lib/posthog-react-native/index.d.ts +10 -0
  14. package/lib/posthog-react-native/src/PostHogProvider.d.ts +13 -0
  15. package/lib/posthog-react-native/src/PosthogContext.d.ts +5 -0
  16. package/lib/posthog-react-native/src/autocapture.d.ts +3 -0
  17. package/lib/posthog-react-native/src/hooks/useFeatureFlag.d.ts +1 -0
  18. package/lib/posthog-react-native/src/hooks/useFeatureFlags.d.ts +3 -0
  19. package/lib/posthog-react-native/src/hooks/useLifecycleTracker.d.ts +2 -0
  20. package/lib/posthog-react-native/src/hooks/useNavigationTracker.d.ts +5 -0
  21. package/lib/posthog-react-native/src/hooks/usePostHog.d.ts +2 -0
  22. package/lib/posthog-react-native/src/legacy.d.ts +4 -0
  23. package/lib/posthog-react-native/src/optional-imports.d.ts +6 -0
  24. package/lib/posthog-react-native/src/posthog-rn.d.ts +14 -0
  25. package/lib/posthog-react-native/src/storage.d.ts +8 -0
  26. package/lib/posthog-react-native/src/types.d.ts +12 -0
  27. package/package.json +35 -51
  28. package/RNPostHog.podspec +0 -21
  29. package/android/build.gradle +0 -46
  30. package/android/src/main/AndroidManifest.xml +0 -1
  31. package/android/src/main/java/com/posthog/reactnative/core/RNPostHogModule.kt +0 -249
  32. package/android/src/main/java/com/posthog/reactnative/core/RNPostHogPackage.kt +0 -44
  33. package/build/cjs/__mocks__/bridge.d.ts +0 -14
  34. package/build/cjs/__mocks__/bridge.js +0 -15
  35. package/build/cjs/__mocks__/bridge.js.map +0 -1
  36. package/build/cjs/__tests__/bridge.spec.d.ts +0 -1
  37. package/build/cjs/__tests__/bridge.spec.js +0 -19
  38. package/build/cjs/__tests__/bridge.spec.js.map +0 -1
  39. package/build/cjs/__tests__/configuration.spec.d.ts +0 -1
  40. package/build/cjs/__tests__/configuration.spec.js +0 -131
  41. package/build/cjs/__tests__/configuration.spec.js.map +0 -1
  42. package/build/cjs/__tests__/index.spec.d.ts +0 -1
  43. package/build/cjs/__tests__/index.spec.js +0 -9
  44. package/build/cjs/__tests__/index.spec.js.map +0 -1
  45. package/build/cjs/__tests__/posthog.spec.d.ts +0 -1
  46. package/build/cjs/__tests__/posthog.spec.js +0 -192
  47. package/build/cjs/__tests__/posthog.spec.js.map +0 -1
  48. package/build/cjs/bridge.d.ts +0 -50
  49. package/build/cjs/bridge.js +0 -9
  50. package/build/cjs/bridge.js.map +0 -1
  51. package/build/cjs/configuration.d.ts +0 -3
  52. package/build/cjs/configuration.js +0 -94
  53. package/build/cjs/configuration.js.map +0 -1
  54. package/build/cjs/index.d.ts +0 -5
  55. package/build/cjs/index.js +0 -6
  56. package/build/cjs/index.js.map +0 -1
  57. package/build/cjs/make-pkg.d.ts +0 -1
  58. package/build/cjs/make-pkg.js +0 -5
  59. package/build/cjs/make-pkg.js.map +0 -1
  60. package/build/cjs/middleware.d.ts +0 -41
  61. package/build/cjs/middleware.js +0 -114
  62. package/build/cjs/middleware.js.map +0 -1
  63. package/build/cjs/posthog.d.ts +0 -228
  64. package/build/cjs/posthog.js +0 -309
  65. package/build/cjs/posthog.js.map +0 -1
  66. package/build/cjs/utils.d.ts +0 -1
  67. package/build/cjs/utils.js +0 -7
  68. package/build/cjs/utils.js.map +0 -1
  69. package/build/cjs/wrapper.d.ts +0 -22
  70. package/build/cjs/wrapper.js +0 -114
  71. package/build/cjs/wrapper.js.map +0 -1
  72. package/build/esm/__mocks__/bridge.d.ts +0 -14
  73. package/build/esm/__mocks__/bridge.js +0 -13
  74. package/build/esm/__mocks__/bridge.js.map +0 -1
  75. package/build/esm/__tests__/bridge.spec.d.ts +0 -1
  76. package/build/esm/__tests__/bridge.spec.js +0 -19
  77. package/build/esm/__tests__/bridge.spec.js.map +0 -1
  78. package/build/esm/__tests__/configuration.spec.d.ts +0 -1
  79. package/build/esm/__tests__/configuration.spec.js +0 -129
  80. package/build/esm/__tests__/configuration.spec.js.map +0 -1
  81. package/build/esm/__tests__/index.spec.d.ts +0 -1
  82. package/build/esm/__tests__/index.spec.js +0 -7
  83. package/build/esm/__tests__/index.spec.js.map +0 -1
  84. package/build/esm/__tests__/posthog.spec.d.ts +0 -1
  85. package/build/esm/__tests__/posthog.spec.js +0 -190
  86. package/build/esm/__tests__/posthog.spec.js.map +0 -1
  87. package/build/esm/bridge.d.ts +0 -50
  88. package/build/esm/bridge.js +0 -7
  89. package/build/esm/bridge.js.map +0 -1
  90. package/build/esm/configuration.d.ts +0 -3
  91. package/build/esm/configuration.js +0 -92
  92. package/build/esm/configuration.js.map +0 -1
  93. package/build/esm/index.d.ts +0 -5
  94. package/build/esm/index.js +0 -4
  95. package/build/esm/index.js.map +0 -1
  96. package/build/esm/make-pkg.d.ts +0 -1
  97. package/build/esm/make-pkg.js +0 -3
  98. package/build/esm/make-pkg.js.map +0 -1
  99. package/build/esm/middleware.d.ts +0 -41
  100. package/build/esm/middleware.js +0 -112
  101. package/build/esm/middleware.js.map +0 -1
  102. package/build/esm/posthog.d.ts +0 -228
  103. package/build/esm/posthog.js +0 -307
  104. package/build/esm/posthog.js.map +0 -1
  105. package/build/esm/utils.d.ts +0 -1
  106. package/build/esm/utils.js +0 -4
  107. package/build/esm/utils.js.map +0 -1
  108. package/build/esm/wrapper.d.ts +0 -22
  109. package/build/esm/wrapper.js +0 -112
  110. package/build/esm/wrapper.js.map +0 -1
  111. package/build/package.json +0 -3
  112. package/ios/RNPostHog/RNPostHog.h +0 -9
  113. package/ios/RNPostHog/RNPostHog.m +0 -128
  114. package/ios/RNPostHog.xcodeproj/project.pbxproj +0 -336
  115. package/ios/RNPostHog.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  116. package/src/__mocks__/bridge.ts +0 -12
  117. package/src/__tests__/bridge.spec.ts +0 -23
  118. package/src/__tests__/configuration.spec.ts +0 -79
  119. package/src/__tests__/index.spec.ts +0 -7
  120. package/src/__tests__/posthog.spec.ts +0 -106
  121. package/src/bridge.ts +0 -61
  122. package/src/configuration.ts +0 -61
  123. package/src/index.ts +0 -5
  124. package/src/make-pkg.ts +0 -3
  125. package/src/middleware.ts +0 -128
  126. package/src/modules.d.ts +0 -2
  127. package/src/posthog.ts +0 -305
  128. package/src/utils.ts +0 -3
  129. package/src/wrapper.ts +0 -61
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- var utils_1 = require("./utils");
39
- var MiddlewareChain = /** @class */ (function () {
40
- function MiddlewareChain(wrapper) {
41
- this.wrapper = wrapper;
42
- this.middlewares = [];
43
- }
44
- MiddlewareChain.prototype.add = function (middleware) {
45
- this.middlewares.push(middleware);
46
- };
47
- MiddlewareChain.prototype.run = function (type, data) {
48
- return __awaiter(this, void 0, void 0, function () {
49
- var payload;
50
- return __generator(this, function (_a) {
51
- switch (_a.label) {
52
- case 0: return [4 /*yield*/, this.exec(type, data)];
53
- case 1:
54
- payload = _a.sent();
55
- switch (payload.type) {
56
- case 'alias':
57
- return [2 /*return*/, this.wrapper.run('alias', function (alias) { return alias(payload.data.alias); })];
58
- case 'identify':
59
- return [2 /*return*/, this.wrapper.run('identify', function (identify) { return identify(payload.data.distinctId, payload.data.properties); })];
60
- case 'screen':
61
- return [2 /*return*/, this.wrapper.run('screen', function (screen) { return screen(payload.data.screen, payload.data.properties); })];
62
- case 'capture':
63
- return [2 /*return*/, this.wrapper.run('capture', function (capture) { return capture(payload.data.event, payload.data.properties); })];
64
- default:
65
- return [2 /*return*/, utils_1.assertNever(payload)];
66
- }
67
- return [2 /*return*/];
68
- }
69
- });
70
- });
71
- };
72
- MiddlewareChain.prototype.exec = function (type, data, index) {
73
- if (index === void 0) { index = 0; }
74
- return __awaiter(this, void 0, void 0, function () {
75
- var middlewares, middleware, ctx, called;
76
- var _this = this;
77
- return __generator(this, function (_a) {
78
- middlewares = this.middlewares;
79
- middleware = middlewares[index];
80
- ctx = {};
81
- if (index >= middlewares.length || !middleware) {
82
- return [2 /*return*/, makePayload(type, data)];
83
- }
84
- called = false;
85
- return [2 /*return*/, new Promise(function (resolve, reject) {
86
- return Promise.resolve(middleware.call(middleware, makePayload(type, data, function (nextProps) {
87
- if (nextProps === void 0) { nextProps = data; }
88
- if (called) {
89
- throw new Error('middleware.payload.next() can only be called one time');
90
- }
91
- called = true;
92
- _this.exec(type, nextProps, index + 1)
93
- .then(resolve)
94
- .catch(reject);
95
- }))).catch(reject);
96
- })];
97
- });
98
- });
99
- };
100
- return MiddlewareChain;
101
- }());
102
- exports.MiddlewareChain = MiddlewareChain;
103
- var notImplemented = function (name) { return function () {
104
- throw new Error("." + name + "() not implemented");
105
- }; };
106
- var makePayload = function (type, data, next) {
107
- if (next === void 0) { next = notImplemented('next'); }
108
- return ({
109
- data: data,
110
- next: next,
111
- type: type
112
- });
113
- };
114
- //# sourceMappingURL=middleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAAqC;AAoDrC;IAGC,yBAA6B,OAA2B;QAA3B,YAAO,GAAP,OAAO,CAAoB;QAFvC,gBAAW,GAAiB,EAAE,CAAA;IAEY,CAAC;IAErD,6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A;QACJ,IAAI,MAAA;KACE,CAAA;AAJP,CAIO,CAAA"}
@@ -1,228 +0,0 @@
1
- import { JsonMap } from './bridge';
2
- import { Middleware } from './middleware';
3
- import { ErrorHandler } from './wrapper';
4
- export declare module PostHog {
5
- interface Configuration {
6
- /**
7
- * Which PostHog host to send events to.
8
- *
9
- * `https://app.posthog.com` by default
10
- */
11
- host?: string;
12
- /**
13
- * Whether the posthog client should automatically make a screen call when a
14
- * view controller is added to a view hierarchy.
15
- * Because the iOS underlying implementation uses method swizzling,
16
- * we recommend initializing the posthog client as early as possible.
17
- *
18
- * Disabled by default.
19
- */
20
- recordScreenViews?: boolean;
21
- /**
22
- * Whether the posthog client should automatically capture application lifecycle events, such as
23
- * "Application Installed", "Application Updated" and "Application Opened".
24
- *
25
- * Disabled by default.
26
- */
27
- captureApplicationLifecycleEvents?: boolean;
28
- /**
29
- * Whether the posthog client should automatically capture deep links. You'll still need to call the
30
- * continueUserActivity and openURL methods on the posthog client.
31
- *
32
- * Disabled by default.
33
- */
34
- captureDeepLinks?: boolean;
35
- /**
36
- * Register a set of integrations to be used with this PostHog instance.
37
- */
38
- debug?: boolean;
39
- /**
40
- * The number of queued events that the posthog client should flush at.
41
- * Setting this to `1` will not queue any events and will use more battery.
42
- *
43
- * `20` by default.
44
- */
45
- flushAt?: number;
46
- /**
47
- * The amount of time to wait before each tick of the flush timer, in seconds.
48
- * Smaller values will make events delivered in a more real-time manner and also use more battery.
49
- * A value smaller than 10 seconds will seriously degrade overall performance.
50
- *
51
- * `30` seconds by default.
52
- */
53
- flushInterval?: number;
54
- /**
55
- * iOS specific settings.
56
- */
57
- ios?: {
58
- /**
59
- * Whether the posthog client should use location services.
60
- * If `true` and the host app hasn't asked for permission to use location services then the user will be
61
- * presented with an alert view asking to do so. `false` by default. If `true`, please make sure to add a
62
- * description for `NSLocationAlwaysUsageDescription` in your `Info.plist` explaining why your app is
63
- * accessing Location APIs.
64
- *
65
- * Disabled by default.
66
- */
67
- shouldUseLocationServices?: boolean;
68
- /**
69
- * The maximum number of items to queue before starting to drop old ones. This should be a value greater
70
- * than zero, the behaviour is undefined otherwise. `1000` by default.
71
- *
72
- * `1000` by default.
73
- */
74
- maxQueueSize?: number;
75
- /**
76
- * Whether the posthog client should record bluetooth information. If `true`, please make sure to add a
77
- * description for `NSBluetoothPeripheralUsageDescription` in your `Info.plist` explaining explaining why
78
- * your app is accessing Bluetooth APIs. `false` by default.
79
- *
80
- * Disabled by default.
81
- */
82
- shouldUseBluetooth?: boolean;
83
- /**
84
- * Whether the posthog client should automatically capture in-app purchases from the App Store
85
- *
86
- * Disabled by default.
87
- */
88
- captureInAppPurchases?: boolean;
89
- /**
90
- * Whether the posthog client should automatically capture push notifications.
91
- *
92
- * Disabled by default.
93
- */
94
- capturePushNotifications?: boolean;
95
- };
96
- /**
97
- * Android specific settings.
98
- */
99
- android?: {
100
- /**
101
- * Whether the posthog client should client the device identifier.
102
- * The device identifier is obtained using :
103
- * - `android.provider.Settings.Secure.ANDROID_ID`
104
- * - `android.os.Build.SERIAL`
105
- * - or Telephony Identifier retrieved via TelephonyManager as available
106
- *
107
- * Enabled by default.
108
- */
109
- collectDeviceId?: boolean;
110
- };
111
- }
112
- class Client {
113
- /**
114
- * Whether the client is ready to send events to PostHog.
115
- *
116
- * This becomes `true` when `.setup()` succeeds.
117
- * All calls will be queued until it becomes `true`.
118
- */
119
- readonly ready = false;
120
- private readonly wrapper;
121
- private readonly handlers;
122
- private readonly middlewares;
123
- /**
124
- * Catch React-Native bridge errors
125
- *
126
- * These errors are emitted when calling the native counterpart.
127
- * This only applies to methods with no return value (`Promise<void>`),
128
- * methods like `getAnonymousId` do reject promises.
129
- */
130
- catch(handler: ErrorHandler): this;
131
- middleware(middleware: Middleware): this;
132
- /**
133
- * Use the native configuration.
134
- *
135
- * You'll need to call this method when you configure PostHog's singleton
136
- * using the native API.
137
- */
138
- useNativeConfiguration(): this;
139
- /**
140
- * Setup the PostHog module. All calls made before are queued
141
- * and only executed if the configuration was successful.
142
- *
143
- * ```js
144
- * await posthog.setup('YOUR_API_KEY', {
145
- * captureAppLifecycleEvents: true,
146
- * ios: {
147
- * capturePushNotifications: true
148
- * }
149
- * })
150
- * ```
151
- *
152
- * @param apiKey Your PostHog.com API key
153
- * @param configuration An optional {@link Configuration} object.
154
- */
155
- setup(apiKey: string, configuration?: Configuration): Promise<void>;
156
- /**
157
- * Record the actions your users perform.
158
- *
159
- * When a user performs an action in your app, you'll want to capture that action for later analysis.
160
- * Use the event name to say what the user did, and properties to specify any interesting details of the action.
161
- *
162
- * @param event The name of the event you're capturing.
163
- * We recommend using human-readable names like `Played a Song` or `Updated Status`.
164
- * @param properties A dictionary of properties for the event.
165
- * If the event was 'Added to Shopping Cart', it might have properties like price, productType, etc.
166
- */
167
- capture(event: string, properties?: JsonMap): Promise<void>;
168
- /**
169
- * Record the screens or views your users see.
170
- *
171
- * When a user views a screen in your app, you'll want to record that here.
172
- *
173
- * @param screen The title of the screen being viewed.
174
- * We recommend using human-readable names like 'Photo Feed' or 'Completed Purchase Screen'.
175
- * @param properties A dictionary of properties for the screen view event.
176
- * If the event was 'Added to Shopping Cart', it might have properties like price, productType, etc.
177
- */
178
- screen(screen: string, properties?: JsonMap): Promise<void>;
179
- /**
180
- * Associate a user with their unique ID and record traits about them.
181
- *
182
- * When you learn more about who your user is, you can record that information with identify.
183
- *
184
- * @param distinctId database ID (or email address) for this user.
185
- * If you don't have a userId but want to record traits, you should pass nil.
186
- * @param properties A dictionary of properties you know about the user. Things like: email, name, plan, etc.
187
- */
188
- identify(distinctId: string, properties?: JsonMap): Promise<void>;
189
- /**
190
- * Merge two user identities, effectively connecting two sets of user data as one.
191
- *
192
- * When you learn more about who the group is, you can record that information with group.
193
- *
194
- * @param alias The existing ID you want to link to the current distinct ID.
195
- */
196
- alias(alias: string): Promise<void>;
197
- /**
198
- * Reset any user state that is cached on the device.
199
- *
200
- * This is useful when a user logs out and you want to clear the identity.
201
- * It will clear any traits or userId's cached on the device.
202
- */
203
- reset(): Promise<void>;
204
- /**
205
- * Trigger an upload of all queued events.
206
- *
207
- * This is useful when you want to force all messages queued on the device to be uploaded.
208
- * Please note that not all integrations respond to this method.
209
- */
210
- flush(): Promise<void>;
211
- /**
212
- * Enable the sending of posthog data. Enabled by default.
213
- *
214
- * Occasionally used in conjunction with disable user opt-out handling.
215
- */
216
- enable(): Promise<void>;
217
- /**
218
- * Completely disable the sending of any posthog data.
219
- *
220
- * If you have a way for users to actively or passively (sometimes based on location) opt-out of
221
- * posthog data collection, you can use this method to turn off all data collection.
222
- */
223
- disable(): Promise<void>;
224
- /** Retrieve the anonymousId. */
225
- getAnonymousId(): Promise<string>;
226
- private handleError;
227
- }
228
- }
@@ -1,309 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- var bridge_1 = require("./bridge");
39
- var configuration_1 = require("./configuration");
40
- var middleware_1 = require("./middleware");
41
- var wrapper_1 = require("./wrapper");
42
- // prettier-ignore
43
- var PostHog;
44
- (function (PostHog) {
45
- var Client = /** @class */ (function () {
46
- function Client() {
47
- var _this = this;
48
- /**
49
- * Whether the client is ready to send events to PostHog.
50
- *
51
- * This becomes `true` when `.setup()` succeeds.
52
- * All calls will be queued until it becomes `true`.
53
- */
54
- this.ready = false;
55
- this.wrapper = new wrapper_1.NativeWrapper(this, function (err) {
56
- return _this.handleError(err);
57
- });
58
- this.handlers = [];
59
- this.middlewares = new middleware_1.MiddlewareChain(this.wrapper);
60
- }
61
- /**
62
- * Catch React-Native bridge errors
63
- *
64
- * These errors are emitted when calling the native counterpart.
65
- * This only applies to methods with no return value (`Promise<void>`),
66
- * methods like `getAnonymousId` do reject promises.
67
- */
68
- Client.prototype.catch = function (handler) {
69
- this.handlers.push(handler);
70
- return this;
71
- };
72
- Client.prototype.middleware = function (middleware) {
73
- this.middlewares.add(middleware);
74
- return this;
75
- };
76
- /**
77
- * Use the native configuration.
78
- *
79
- * You'll need to call this method when you configure PostHog's singleton
80
- * using the native API.
81
- */
82
- Client.prototype.useNativeConfiguration = function () {
83
- if (this.ready) {
84
- throw new Error('PostHog has already been configured');
85
- }
86
- this.wrapper.ready();
87
- return this;
88
- };
89
- /**
90
- * Setup the PostHog module. All calls made before are queued
91
- * and only executed if the configuration was successful.
92
- *
93
- * ```js
94
- * await posthog.setup('YOUR_API_KEY', {
95
- * captureAppLifecycleEvents: true,
96
- * ios: {
97
- * capturePushNotifications: true
98
- * }
99
- * })
100
- * ```
101
- *
102
- * @param apiKey Your PostHog.com API key
103
- * @param configuration An optional {@link Configuration} object.
104
- */
105
- Client.prototype.setup = function (apiKey, configuration) {
106
- if (configuration === void 0) { configuration = {}; }
107
- return __awaiter(this, void 0, void 0, function () {
108
- var _a, _b;
109
- return __generator(this, function (_c) {
110
- switch (_c.label) {
111
- case 0:
112
- _b = (_a = bridge_1.default).setup;
113
- return [4 /*yield*/, configuration_1.configure(apiKey, configuration)];
114
- case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()])];
115
- case 2:
116
- _c.sent();
117
- this.wrapper.ready();
118
- return [2 /*return*/];
119
- }
120
- });
121
- });
122
- };
123
- /**
124
- * Record the actions your users perform.
125
- *
126
- * When a user performs an action in your app, you'll want to capture that action for later analysis.
127
- * Use the event name to say what the user did, and properties to specify any interesting details of the action.
128
- *
129
- * @param event The name of the event you're capturing.
130
- * We recommend using human-readable names like `Played a Song` or `Updated Status`.
131
- * @param properties A dictionary of properties for the event.
132
- * If the event was 'Added to Shopping Cart', it might have properties like price, productType, etc.
133
- */
134
- Client.prototype.capture = function (event, properties) {
135
- if (properties === void 0) { properties = {}; }
136
- return __awaiter(this, void 0, void 0, function () {
137
- return __generator(this, function (_a) {
138
- switch (_a.label) {
139
- case 0: return [4 /*yield*/, this.middlewares.run('capture', { event: event, properties: properties })];
140
- case 1:
141
- _a.sent();
142
- return [2 /*return*/];
143
- }
144
- });
145
- });
146
- };
147
- /**
148
- * Record the screens or views your users see.
149
- *
150
- * When a user views a screen in your app, you'll want to record that here.
151
- *
152
- * @param screen The title of the screen being viewed.
153
- * We recommend using human-readable names like 'Photo Feed' or 'Completed Purchase Screen'.
154
- * @param properties A dictionary of properties for the screen view event.
155
- * If the event was 'Added to Shopping Cart', it might have properties like price, productType, etc.
156
- */
157
- Client.prototype.screen = function (screen, properties) {
158
- if (properties === void 0) { properties = {}; }
159
- return __awaiter(this, void 0, void 0, function () {
160
- return __generator(this, function (_a) {
161
- switch (_a.label) {
162
- case 0: return [4 /*yield*/, this.middlewares.run('screen', { screen: screen, properties: properties })];
163
- case 1:
164
- _a.sent();
165
- return [2 /*return*/];
166
- }
167
- });
168
- });
169
- };
170
- /**
171
- * Associate a user with their unique ID and record traits about them.
172
- *
173
- * When you learn more about who your user is, you can record that information with identify.
174
- *
175
- * @param distinctId database ID (or email address) for this user.
176
- * If you don't have a userId but want to record traits, you should pass nil.
177
- * @param properties A dictionary of properties you know about the user. Things like: email, name, plan, etc.
178
- */
179
- Client.prototype.identify = function (distinctId, properties) {
180
- if (properties === void 0) { properties = {}; }
181
- return __awaiter(this, void 0, void 0, function () {
182
- return __generator(this, function (_a) {
183
- switch (_a.label) {
184
- case 0: return [4 /*yield*/, this.middlewares.run('identify', { distinctId: distinctId, properties: properties })];
185
- case 1:
186
- _a.sent();
187
- return [2 /*return*/];
188
- }
189
- });
190
- });
191
- };
192
- /**
193
- * Merge two user identities, effectively connecting two sets of user data as one.
194
- *
195
- * When you learn more about who the group is, you can record that information with group.
196
- *
197
- * @param alias The existing ID you want to link to the current distinct ID.
198
- */
199
- Client.prototype.alias = function (alias) {
200
- return __awaiter(this, void 0, void 0, function () {
201
- return __generator(this, function (_a) {
202
- switch (_a.label) {
203
- case 0: return [4 /*yield*/, this.middlewares.run('alias', { alias: alias })];
204
- case 1:
205
- _a.sent();
206
- return [2 /*return*/];
207
- }
208
- });
209
- });
210
- };
211
- /**
212
- * Reset any user state that is cached on the device.
213
- *
214
- * This is useful when a user logs out and you want to clear the identity.
215
- * It will clear any traits or userId's cached on the device.
216
- */
217
- Client.prototype.reset = function () {
218
- return __awaiter(this, void 0, void 0, function () {
219
- return __generator(this, function (_a) {
220
- switch (_a.label) {
221
- case 0: return [4 /*yield*/, this.wrapper.run('reset', function (reset) { return reset(); })];
222
- case 1:
223
- _a.sent();
224
- return [2 /*return*/];
225
- }
226
- });
227
- });
228
- };
229
- /**
230
- * Trigger an upload of all queued events.
231
- *
232
- * This is useful when you want to force all messages queued on the device to be uploaded.
233
- * Please note that not all integrations respond to this method.
234
- */
235
- Client.prototype.flush = function () {
236
- return __awaiter(this, void 0, void 0, function () {
237
- return __generator(this, function (_a) {
238
- switch (_a.label) {
239
- case 0: return [4 /*yield*/, this.wrapper.run('flush', function (flush) { return flush(); })];
240
- case 1:
241
- _a.sent();
242
- return [2 /*return*/];
243
- }
244
- });
245
- });
246
- };
247
- /**
248
- * Enable the sending of posthog data. Enabled by default.
249
- *
250
- * Occasionally used in conjunction with disable user opt-out handling.
251
- */
252
- Client.prototype.enable = function () {
253
- return __awaiter(this, void 0, void 0, function () {
254
- return __generator(this, function (_a) {
255
- switch (_a.label) {
256
- case 0: return [4 /*yield*/, this.wrapper.run('enable', function (enable) { return enable(); })];
257
- case 1:
258
- _a.sent();
259
- return [2 /*return*/];
260
- }
261
- });
262
- });
263
- };
264
- /**
265
- * Completely disable the sending of any posthog data.
266
- *
267
- * If you have a way for users to actively or passively (sometimes based on location) opt-out of
268
- * posthog data collection, you can use this method to turn off all data collection.
269
- */
270
- Client.prototype.disable = function () {
271
- return __awaiter(this, void 0, void 0, function () {
272
- return __generator(this, function (_a) {
273
- switch (_a.label) {
274
- case 0: return [4 /*yield*/, this.wrapper.run('disable', function (disable) { return disable(); })];
275
- case 1:
276
- _a.sent();
277
- return [2 /*return*/];
278
- }
279
- });
280
- });
281
- };
282
- /** Retrieve the anonymousId. */
283
- Client.prototype.getAnonymousId = function () {
284
- return __awaiter(this, void 0, void 0, function () {
285
- return __generator(this, function (_a) {
286
- switch (_a.label) {
287
- case 0: return [4 /*yield*/, this.wrapper.wait()];
288
- case 1:
289
- _a.sent();
290
- return [2 /*return*/, bridge_1.default.getAnonymousId()];
291
- }
292
- });
293
- });
294
- };
295
- Client.prototype.handleError = function (error) {
296
- var handlers = this.handlers;
297
- if (!handlers.length) {
298
- console.error('Uncaught PostHog error', error);
299
- throw error;
300
- }
301
- else {
302
- handlers.forEach(function (handler) { return handler(error); });
303
- }
304
- };
305
- return Client;
306
- }());
307
- PostHog.Client = Client;
308
- })(PostHog = exports.PostHog || (exports.PostHog = {}));
309
- //# sourceMappingURL=posthog.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"posthog.js","sourceRoot":"","sources":["../../src/posthog.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA0C;AAC1C,iDAA2C;AAC3C,2CAA0D;AAC1D,qCAAuD;AAEvD,kBAAkB;AAClB,IAAc,OAAO,CA0SpB;AA1SD,WAAc,OAAO;IAkHpB;QAAA;YAAA,iBAuLC;YAtLA;;;;;eAKG;YACa,UAAK,GAAG,KAAK,CAAA;YAEZ,YAAO,GAAG,IAAI,uBAAa,CAAC,IAAI,EAAE,UAAA,GAAG;gBACrD,OAAA,KAAI,CAAC,WAAW,CAAC,GAAG,CAAC;YAArB,CAAqB,CACrB,CAAA;YACgB,aAAQ,GAAmB,EAAE,CAAA;YAC7B,gBAAW,GAAG,IAAI,4BAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QA0KjE,CAAC;QAxKA;;;;;;WAMG;QACI,sBAAK,GAAZ,UAAa,OAAqB;YACjC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YAE3B,OAAO,IAAI,CAAA;QACZ,CAAC;QAEM,2BAAU,GAAjB,UAAkB,UAAsB;YACvC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CA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AA;;;;SAC9B;QAEO,4BAAW,GAAnB,UAAoB,KAAY;YACvB,IAAA,wBAAQ,CAAS;YAEzB,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;gBACrB,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAA;gBAC9C,MAAM,KAAK,CAAA;aACX;iBAAM;gBACN,QAAQ,CAAC,OAAO,CAAC,UAAA,OAAO,IAAI,OAAA,OAAO,CAAC,KAAK,CAAC,EAAd,CAAc,CAAC,CAAA;aAC3C;QACF,CAAC;QACF,aAAC;IAAD,CAAC,AAvLD,IAuLC;IAvLY,cAAM,SAuLlB,CAAA;AACF,CAAC,EA1Sa,OAAO,GAAP,eAAO,KAAP,eAAO,QA0SpB"}
@@ -1 +0,0 @@
1
- export declare function assertNever(never: never): void;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function assertNever(never) {
4
- throw new Error('Expected never, got ' + never);
5
- }
6
- exports.assertNever = assertNever;
7
- //# sourceMappingURL=utils.js.map