posthog-react-native 1.1.4 → 2.0.0-alpha8
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/README.md +9 -0
- package/lib/index.cjs.js +1761 -0
- package/lib/index.cjs.js.map +1 -0
- package/lib/index.d.ts +211 -0
- package/lib/index.esm.js +1725 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/node_modules/tslib/tslib.es6.d.ts +35 -0
- package/lib/posthog-core/src/eventemitter.d.ts +8 -0
- package/lib/posthog-core/src/index.d.ts +84 -0
- package/lib/posthog-core/src/lz-string.d.ts +8 -0
- package/lib/posthog-core/src/types.d.ts +68 -0
- package/lib/posthog-core/src/utils.d.ts +13 -0
- package/lib/posthog-react-native/index.d.ts +10 -0
- package/lib/posthog-react-native/src/PostHogProvider.d.ts +13 -0
- package/lib/posthog-react-native/src/PosthogContext.d.ts +5 -0
- package/lib/posthog-react-native/src/autocapture.d.ts +3 -0
- package/lib/posthog-react-native/src/hooks/useFeatureFlag.d.ts +1 -0
- package/lib/posthog-react-native/src/hooks/useFeatureFlags.d.ts +3 -0
- package/lib/posthog-react-native/src/hooks/useLifecycleTracker.d.ts +2 -0
- package/lib/posthog-react-native/src/hooks/useNavigationTracker.d.ts +5 -0
- package/lib/posthog-react-native/src/hooks/usePostHog.d.ts +2 -0
- package/lib/posthog-react-native/src/legacy.d.ts +4 -0
- package/lib/posthog-react-native/src/optional-imports.d.ts +6 -0
- package/lib/posthog-react-native/src/posthog-rn.d.ts +14 -0
- package/lib/posthog-react-native/src/storage.d.ts +8 -0
- package/lib/posthog-react-native/src/types.d.ts +12 -0
- package/package.json +35 -51
- package/RNPostHog.podspec +0 -21
- package/android/build.gradle +0 -46
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/java/com/posthog/reactnative/core/RNPostHogModule.kt +0 -251
- package/android/src/main/java/com/posthog/reactnative/core/RNPostHogPackage.kt +0 -44
- package/build/cjs/__mocks__/bridge.d.ts +0 -14
- package/build/cjs/__mocks__/bridge.js +0 -15
- package/build/cjs/__mocks__/bridge.js.map +0 -1
- package/build/cjs/__tests__/bridge.spec.d.ts +0 -1
- package/build/cjs/__tests__/bridge.spec.js +0 -19
- package/build/cjs/__tests__/bridge.spec.js.map +0 -1
- package/build/cjs/__tests__/configuration.spec.d.ts +0 -1
- package/build/cjs/__tests__/configuration.spec.js +0 -131
- package/build/cjs/__tests__/configuration.spec.js.map +0 -1
- package/build/cjs/__tests__/index.spec.d.ts +0 -1
- package/build/cjs/__tests__/index.spec.js +0 -9
- package/build/cjs/__tests__/index.spec.js.map +0 -1
- package/build/cjs/__tests__/posthog.spec.d.ts +0 -1
- package/build/cjs/__tests__/posthog.spec.js +0 -193
- package/build/cjs/__tests__/posthog.spec.js.map +0 -1
- package/build/cjs/bridge.d.ts +0 -50
- package/build/cjs/bridge.js +0 -9
- package/build/cjs/bridge.js.map +0 -1
- package/build/cjs/configuration.d.ts +0 -3
- package/build/cjs/configuration.js +0 -94
- package/build/cjs/configuration.js.map +0 -1
- package/build/cjs/index.d.ts +0 -5
- package/build/cjs/index.js +0 -6
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/make-pkg.d.ts +0 -1
- package/build/cjs/make-pkg.js +0 -5
- package/build/cjs/make-pkg.js.map +0 -1
- package/build/cjs/middleware.d.ts +0 -41
- package/build/cjs/middleware.js +0 -114
- package/build/cjs/middleware.js.map +0 -1
- package/build/cjs/posthog.d.ts +0 -228
- package/build/cjs/posthog.js +0 -309
- package/build/cjs/posthog.js.map +0 -1
- package/build/cjs/utils.d.ts +0 -1
- package/build/cjs/utils.js +0 -7
- package/build/cjs/utils.js.map +0 -1
- package/build/cjs/wrapper.d.ts +0 -22
- package/build/cjs/wrapper.js +0 -114
- package/build/cjs/wrapper.js.map +0 -1
- package/build/esm/__mocks__/bridge.d.ts +0 -14
- package/build/esm/__mocks__/bridge.js +0 -13
- package/build/esm/__mocks__/bridge.js.map +0 -1
- package/build/esm/__tests__/bridge.spec.d.ts +0 -1
- package/build/esm/__tests__/bridge.spec.js +0 -19
- package/build/esm/__tests__/bridge.spec.js.map +0 -1
- package/build/esm/__tests__/configuration.spec.d.ts +0 -1
- package/build/esm/__tests__/configuration.spec.js +0 -129
- package/build/esm/__tests__/configuration.spec.js.map +0 -1
- package/build/esm/__tests__/index.spec.d.ts +0 -1
- package/build/esm/__tests__/index.spec.js +0 -7
- package/build/esm/__tests__/index.spec.js.map +0 -1
- package/build/esm/__tests__/posthog.spec.d.ts +0 -1
- package/build/esm/__tests__/posthog.spec.js +0 -191
- package/build/esm/__tests__/posthog.spec.js.map +0 -1
- package/build/esm/bridge.d.ts +0 -50
- package/build/esm/bridge.js +0 -7
- package/build/esm/bridge.js.map +0 -1
- package/build/esm/configuration.d.ts +0 -3
- package/build/esm/configuration.js +0 -92
- package/build/esm/configuration.js.map +0 -1
- package/build/esm/index.d.ts +0 -5
- package/build/esm/index.js +0 -4
- package/build/esm/index.js.map +0 -1
- package/build/esm/make-pkg.d.ts +0 -1
- package/build/esm/make-pkg.js +0 -3
- package/build/esm/make-pkg.js.map +0 -1
- package/build/esm/middleware.d.ts +0 -41
- package/build/esm/middleware.js +0 -112
- package/build/esm/middleware.js.map +0 -1
- package/build/esm/posthog.d.ts +0 -228
- package/build/esm/posthog.js +0 -307
- package/build/esm/posthog.js.map +0 -1
- package/build/esm/utils.d.ts +0 -1
- package/build/esm/utils.js +0 -4
- package/build/esm/utils.js.map +0 -1
- package/build/esm/wrapper.d.ts +0 -22
- package/build/esm/wrapper.js +0 -112
- package/build/esm/wrapper.js.map +0 -1
- package/build/package.json +0 -3
- package/ios/RNPostHog/RNPostHog.h +0 -9
- package/ios/RNPostHog/RNPostHog.m +0 -128
- package/ios/RNPostHog.xcodeproj/project.pbxproj +0 -336
- package/ios/RNPostHog.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/src/__mocks__/bridge.ts +0 -12
- package/src/__tests__/bridge.spec.ts +0 -23
- package/src/__tests__/configuration.spec.ts +0 -79
- package/src/__tests__/index.spec.ts +0 -7
- package/src/__tests__/posthog.spec.ts +0 -108
- package/src/bridge.ts +0 -61
- package/src/configuration.ts +0 -61
- package/src/index.ts +0 -5
- package/src/make-pkg.ts +0 -3
- package/src/middleware.ts +0 -128
- package/src/modules.d.ts +0 -2
- package/src/posthog.ts +0 -305
- package/src/utils.ts +0 -3
- package/src/wrapper.ts +0 -61
package/src/index.ts
DELETED
package/src/make-pkg.ts
DELETED
package/src/middleware.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { Context, Options, JsonMap } from './bridge'
|
|
2
|
-
import { assertNever } from './utils'
|
|
3
|
-
import { NativeWrapper } from './wrapper'
|
|
4
|
-
|
|
5
|
-
export interface MiddlewarePayload<T extends string, D extends {}> {
|
|
6
|
-
type: T
|
|
7
|
-
data: D
|
|
8
|
-
context: Context
|
|
9
|
-
next(context?: Partial<Context>): void
|
|
10
|
-
// tslint:disable-next-line:unified-signatures
|
|
11
|
-
next(context?: Partial<Context>, data?: D): void
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface CapturePayload
|
|
15
|
-
extends MiddlewarePayload<
|
|
16
|
-
'capture',
|
|
17
|
-
{
|
|
18
|
-
event: string
|
|
19
|
-
properties: JsonMap
|
|
20
|
-
}
|
|
21
|
-
> {}
|
|
22
|
-
|
|
23
|
-
export interface ScreenPayload
|
|
24
|
-
extends MiddlewarePayload<
|
|
25
|
-
'screen',
|
|
26
|
-
{
|
|
27
|
-
screen: string
|
|
28
|
-
properties: JsonMap
|
|
29
|
-
}
|
|
30
|
-
> {}
|
|
31
|
-
|
|
32
|
-
export interface IdentifyPayload
|
|
33
|
-
extends MiddlewarePayload<
|
|
34
|
-
'identify',
|
|
35
|
-
{
|
|
36
|
-
distinctId: string | null
|
|
37
|
-
properties: JsonMap
|
|
38
|
-
}
|
|
39
|
-
> {}
|
|
40
|
-
|
|
41
|
-
export interface AliasPayload
|
|
42
|
-
extends MiddlewarePayload<
|
|
43
|
-
'alias',
|
|
44
|
-
{
|
|
45
|
-
alias: string
|
|
46
|
-
}
|
|
47
|
-
> {}
|
|
48
|
-
|
|
49
|
-
export type Payload = CapturePayload | IdentifyPayload | ScreenPayload | AliasPayload
|
|
50
|
-
|
|
51
|
-
export type Middleware = (payload: Payload) => void | Promise<void>
|
|
52
|
-
export type PayloadFromType<T> = Extract<Payload, { type: T }>
|
|
53
|
-
|
|
54
|
-
export class MiddlewareChain {
|
|
55
|
-
private readonly middlewares: Middleware[] = []
|
|
56
|
-
|
|
57
|
-
constructor(private readonly wrapper: NativeWrapper<any>) {}
|
|
58
|
-
|
|
59
|
-
public add(middleware: Middleware) {
|
|
60
|
-
this.middlewares.push(middleware)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public async run<T extends Payload['type'], P extends PayloadFromType<T>>(type: T, data: P['data']) {
|
|
64
|
-
const payload: Payload = await this.exec(type, data)
|
|
65
|
-
|
|
66
|
-
switch (payload.type) {
|
|
67
|
-
case 'alias':
|
|
68
|
-
return this.wrapper.run('alias', alias => alias(payload.data.alias))
|
|
69
|
-
case 'identify':
|
|
70
|
-
return this.wrapper.run('identify', identify => identify(payload.data.distinctId, payload.data.properties))
|
|
71
|
-
case 'screen':
|
|
72
|
-
return this.wrapper.run('screen', screen => screen(payload.data.screen, payload.data.properties))
|
|
73
|
-
case 'capture':
|
|
74
|
-
return this.wrapper.run('capture', capture => capture(payload.data.event, payload.data.properties))
|
|
75
|
-
default:
|
|
76
|
-
return assertNever(payload)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private async exec<T extends Payload['type'], P extends PayloadFromType<T>>(
|
|
81
|
-
type: T,
|
|
82
|
-
data: P['data'],
|
|
83
|
-
index = 0
|
|
84
|
-
): Promise<P> {
|
|
85
|
-
const { middlewares } = this
|
|
86
|
-
const middleware = middlewares[index]
|
|
87
|
-
const ctx = {}
|
|
88
|
-
|
|
89
|
-
if (index >= middlewares.length || !middleware) {
|
|
90
|
-
return makePayload(type, data)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let called = false
|
|
94
|
-
|
|
95
|
-
return new Promise<P>((resolve, reject) =>
|
|
96
|
-
Promise.resolve(
|
|
97
|
-
middleware.call(
|
|
98
|
-
middleware,
|
|
99
|
-
makePayload(type, data, (nextProps = data) => {
|
|
100
|
-
if (called) {
|
|
101
|
-
throw new Error('middleware.payload.next() can only be called one time')
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
called = true
|
|
105
|
-
this.exec(type, nextProps, index + 1)
|
|
106
|
-
.then(resolve)
|
|
107
|
-
.catch(reject)
|
|
108
|
-
})
|
|
109
|
-
)
|
|
110
|
-
).catch(reject)
|
|
111
|
-
)
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const notImplemented = (name: string) => () => {
|
|
116
|
-
throw new Error(`.${name}() not implemented`)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const makePayload = <T extends Payload['type'], P extends PayloadFromType<T>>(
|
|
120
|
-
type: T,
|
|
121
|
-
data: P['data'],
|
|
122
|
-
next: (data?: P['data']) => void = notImplemented('next')
|
|
123
|
-
) =>
|
|
124
|
-
({
|
|
125
|
-
data,
|
|
126
|
-
next,
|
|
127
|
-
type
|
|
128
|
-
} as P)
|
package/src/modules.d.ts
DELETED
package/src/posthog.ts
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import Bridge, { JsonMap } from './bridge'
|
|
2
|
-
import { configure } from './configuration'
|
|
3
|
-
import { Middleware, MiddlewareChain } from './middleware'
|
|
4
|
-
import { ErrorHandler, NativeWrapper } from './wrapper'
|
|
5
|
-
|
|
6
|
-
// prettier-ignore
|
|
7
|
-
export module PostHog {
|
|
8
|
-
export interface Configuration {
|
|
9
|
-
/**
|
|
10
|
-
* Which PostHog host to send events to.
|
|
11
|
-
*
|
|
12
|
-
* `https://app.posthog.com` by default
|
|
13
|
-
*/
|
|
14
|
-
host?: string
|
|
15
|
-
/**
|
|
16
|
-
* Whether the posthog client should automatically make a screen call when a
|
|
17
|
-
* view controller is added to a view hierarchy.
|
|
18
|
-
* Because the iOS underlying implementation uses method swizzling,
|
|
19
|
-
* we recommend initializing the posthog client as early as possible.
|
|
20
|
-
*
|
|
21
|
-
* Disabled by default.
|
|
22
|
-
*/
|
|
23
|
-
recordScreenViews?: boolean
|
|
24
|
-
/**
|
|
25
|
-
* Whether the posthog client should automatically capture application lifecycle events, such as
|
|
26
|
-
* "Application Installed", "Application Updated" and "Application Opened".
|
|
27
|
-
*
|
|
28
|
-
* Disabled by default.
|
|
29
|
-
*/
|
|
30
|
-
captureApplicationLifecycleEvents?: boolean
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Whether the posthog client should automatically capture deep links. You'll still need to call the
|
|
34
|
-
* continueUserActivity and openURL methods on the posthog client.
|
|
35
|
-
*
|
|
36
|
-
* Disabled by default.
|
|
37
|
-
*/
|
|
38
|
-
captureDeepLinks?: boolean
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Register a set of integrations to be used with this PostHog instance.
|
|
42
|
-
*/
|
|
43
|
-
debug?: boolean
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The number of queued events that the posthog client should flush at.
|
|
47
|
-
* Setting this to `1` will not queue any events and will use more battery.
|
|
48
|
-
*
|
|
49
|
-
* `20` by default.
|
|
50
|
-
*/
|
|
51
|
-
flushAt?: number
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* The amount of time to wait before each tick of the flush timer, in seconds.
|
|
55
|
-
* Smaller values will make events delivered in a more real-time manner and also use more battery.
|
|
56
|
-
* A value smaller than 10 seconds will seriously degrade overall performance.
|
|
57
|
-
*
|
|
58
|
-
* `30` seconds by default.
|
|
59
|
-
*/
|
|
60
|
-
flushInterval?: number
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* iOS specific settings.
|
|
64
|
-
*/
|
|
65
|
-
ios?: {
|
|
66
|
-
/**
|
|
67
|
-
* Whether the posthog client should use location services.
|
|
68
|
-
* If `true` and the host app hasn't asked for permission to use location services then the user will be
|
|
69
|
-
* presented with an alert view asking to do so. `false` by default. If `true`, please make sure to add a
|
|
70
|
-
* description for `NSLocationAlwaysUsageDescription` in your `Info.plist` explaining why your app is
|
|
71
|
-
* accessing Location APIs.
|
|
72
|
-
*
|
|
73
|
-
* Disabled by default.
|
|
74
|
-
*/
|
|
75
|
-
shouldUseLocationServices?: boolean
|
|
76
|
-
/**
|
|
77
|
-
* The maximum number of items to queue before starting to drop old ones. This should be a value greater
|
|
78
|
-
* than zero, the behaviour is undefined otherwise. `1000` by default.
|
|
79
|
-
*
|
|
80
|
-
* `1000` by default.
|
|
81
|
-
*/
|
|
82
|
-
maxQueueSize?: number
|
|
83
|
-
/**
|
|
84
|
-
* Whether the posthog client should record bluetooth information. If `true`, please make sure to add a
|
|
85
|
-
* description for `NSBluetoothPeripheralUsageDescription` in your `Info.plist` explaining explaining why
|
|
86
|
-
* your app is accessing Bluetooth APIs. `false` by default.
|
|
87
|
-
*
|
|
88
|
-
* Disabled by default.
|
|
89
|
-
*/
|
|
90
|
-
shouldUseBluetooth?: boolean
|
|
91
|
-
/**
|
|
92
|
-
* Whether the posthog client should automatically capture in-app purchases from the App Store
|
|
93
|
-
*
|
|
94
|
-
* Disabled by default.
|
|
95
|
-
*/
|
|
96
|
-
captureInAppPurchases?: boolean
|
|
97
|
-
/**
|
|
98
|
-
* Whether the posthog client should automatically capture push notifications.
|
|
99
|
-
*
|
|
100
|
-
* Disabled by default.
|
|
101
|
-
*/
|
|
102
|
-
capturePushNotifications?: boolean
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Android specific settings.
|
|
106
|
-
*/
|
|
107
|
-
android?: {
|
|
108
|
-
/**
|
|
109
|
-
* Whether the posthog client should client the device identifier.
|
|
110
|
-
* The device identifier is obtained using :
|
|
111
|
-
* - `android.provider.Settings.Secure.ANDROID_ID`
|
|
112
|
-
* - `android.os.Build.SERIAL`
|
|
113
|
-
* - or Telephony Identifier retrieved via TelephonyManager as available
|
|
114
|
-
*
|
|
115
|
-
* Enabled by default.
|
|
116
|
-
*/
|
|
117
|
-
collectDeviceId?: boolean
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export class Client {
|
|
122
|
-
/**
|
|
123
|
-
* Whether the client is ready to send events to PostHog.
|
|
124
|
-
*
|
|
125
|
-
* This becomes `true` when `.setup()` succeeds.
|
|
126
|
-
* All calls will be queued until it becomes `true`.
|
|
127
|
-
*/
|
|
128
|
-
public readonly ready = false
|
|
129
|
-
|
|
130
|
-
private readonly wrapper = new NativeWrapper(this, err =>
|
|
131
|
-
this.handleError(err)
|
|
132
|
-
)
|
|
133
|
-
private readonly handlers: ErrorHandler[] = []
|
|
134
|
-
private readonly middlewares = new MiddlewareChain(this.wrapper)
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Catch React-Native bridge errors
|
|
138
|
-
*
|
|
139
|
-
* These errors are emitted when calling the native counterpart.
|
|
140
|
-
* This only applies to methods with no return value (`Promise<void>`),
|
|
141
|
-
* methods like `getAnonymousId` do reject promises.
|
|
142
|
-
*/
|
|
143
|
-
public catch(handler: ErrorHandler) {
|
|
144
|
-
this.handlers.push(handler)
|
|
145
|
-
|
|
146
|
-
return this
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
public middleware(middleware: Middleware) {
|
|
150
|
-
this.middlewares.add(middleware)
|
|
151
|
-
|
|
152
|
-
return this
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Use the native configuration.
|
|
157
|
-
*
|
|
158
|
-
* You'll need to call this method when you configure PostHog's singleton
|
|
159
|
-
* using the native API.
|
|
160
|
-
*/
|
|
161
|
-
public useNativeConfiguration() {
|
|
162
|
-
if(this.ready) {
|
|
163
|
-
throw new Error('PostHog has already been configured')
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
this.wrapper.ready()
|
|
167
|
-
|
|
168
|
-
return this
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Setup the PostHog module. All calls made before are queued
|
|
173
|
-
* and only executed if the configuration was successful.
|
|
174
|
-
*
|
|
175
|
-
* ```js
|
|
176
|
-
* await posthog.setup('YOUR_API_KEY', {
|
|
177
|
-
* captureAppLifecycleEvents: true,
|
|
178
|
-
* ios: {
|
|
179
|
-
* capturePushNotifications: true
|
|
180
|
-
* }
|
|
181
|
-
* })
|
|
182
|
-
* ```
|
|
183
|
-
*
|
|
184
|
-
* @param apiKey Your PostHog.com API key
|
|
185
|
-
* @param configuration An optional {@link Configuration} object.
|
|
186
|
-
*/
|
|
187
|
-
public async setup(apiKey: string, configuration: Configuration = {}) {
|
|
188
|
-
await Bridge.setup(
|
|
189
|
-
await configure(apiKey, configuration)
|
|
190
|
-
)
|
|
191
|
-
this.wrapper.ready()
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Record the actions your users perform.
|
|
196
|
-
*
|
|
197
|
-
* When a user performs an action in your app, you'll want to capture that action for later analysis.
|
|
198
|
-
* Use the event name to say what the user did, and properties to specify any interesting details of the action.
|
|
199
|
-
*
|
|
200
|
-
* @param event The name of the event you're capturing.
|
|
201
|
-
* We recommend using human-readable names like `Played a Song` or `Updated Status`.
|
|
202
|
-
* @param properties A dictionary of properties for the event.
|
|
203
|
-
* If the event was 'Added to Shopping Cart', it might have properties like price, productType, etc.
|
|
204
|
-
*/
|
|
205
|
-
public async capture(event: string, properties: JsonMap = {}) {
|
|
206
|
-
await this.middlewares.run('capture', { event, properties })
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Record the screens or views your users see.
|
|
211
|
-
*
|
|
212
|
-
* When a user views a screen in your app, you'll want to record that here.
|
|
213
|
-
*
|
|
214
|
-
* @param screen The title of the screen being viewed.
|
|
215
|
-
* We recommend using human-readable names like 'Photo Feed' or 'Completed Purchase Screen'.
|
|
216
|
-
* @param properties A dictionary of properties for the screen view event.
|
|
217
|
-
* If the event was 'Added to Shopping Cart', it might have properties like price, productType, etc.
|
|
218
|
-
*/
|
|
219
|
-
public async screen(screen: string, properties: JsonMap = {}) {
|
|
220
|
-
await this.middlewares.run('screen', { screen, properties })
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Associate a user with their unique ID and record traits about them.
|
|
225
|
-
*
|
|
226
|
-
* When you learn more about who your user is, you can record that information with identify.
|
|
227
|
-
*
|
|
228
|
-
* @param distinctId database ID (or email address) for this user.
|
|
229
|
-
* If you don't have a userId but want to record traits, you should pass nil.
|
|
230
|
-
* @param properties A dictionary of properties you know about the user. Things like: email, name, plan, etc.
|
|
231
|
-
*/
|
|
232
|
-
public async identify(distinctId: string | null, properties: JsonMap = {}) {
|
|
233
|
-
await this.middlewares.run('identify', { distinctId, properties })
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Merge two user identities, effectively connecting two sets of user data as one.
|
|
239
|
-
*
|
|
240
|
-
* When you learn more about who the group is, you can record that information with group.
|
|
241
|
-
*
|
|
242
|
-
* @param alias The existing ID you want to link to the current distinct ID.
|
|
243
|
-
*/
|
|
244
|
-
public async alias(alias: string) {
|
|
245
|
-
await this.middlewares.run('alias', { alias })
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Reset any user state that is cached on the device.
|
|
250
|
-
*
|
|
251
|
-
* This is useful when a user logs out and you want to clear the identity.
|
|
252
|
-
* It will clear any traits or userId's cached on the device.
|
|
253
|
-
*/
|
|
254
|
-
public async reset() {
|
|
255
|
-
await this.wrapper.run('reset', reset => reset())
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Trigger an upload of all queued events.
|
|
260
|
-
*
|
|
261
|
-
* This is useful when you want to force all messages queued on the device to be uploaded.
|
|
262
|
-
* Please note that not all integrations respond to this method.
|
|
263
|
-
*/
|
|
264
|
-
public async flush() {
|
|
265
|
-
await this.wrapper.run('flush', flush => flush())
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Enable the sending of posthog data. Enabled by default.
|
|
270
|
-
*
|
|
271
|
-
* Occasionally used in conjunction with disable user opt-out handling.
|
|
272
|
-
*/
|
|
273
|
-
public async enable() {
|
|
274
|
-
await this.wrapper.run('enable', enable => enable())
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Completely disable the sending of any posthog data.
|
|
279
|
-
*
|
|
280
|
-
* If you have a way for users to actively or passively (sometimes based on location) opt-out of
|
|
281
|
-
* posthog data collection, you can use this method to turn off all data collection.
|
|
282
|
-
*/
|
|
283
|
-
public async disable() {
|
|
284
|
-
await this.wrapper.run('disable', disable => disable())
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/** Retrieve the anonymousId. */
|
|
288
|
-
public async getAnonymousId(): Promise<string> {
|
|
289
|
-
await this.wrapper.wait()
|
|
290
|
-
|
|
291
|
-
return Bridge.getAnonymousId()
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
private handleError(error: Error) {
|
|
295
|
-
const { handlers } = this
|
|
296
|
-
|
|
297
|
-
if (!handlers.length) {
|
|
298
|
-
console.error('Uncaught PostHog error', error)
|
|
299
|
-
throw error
|
|
300
|
-
} else {
|
|
301
|
-
handlers.forEach(handler => handler(error))
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
package/src/utils.ts
DELETED
package/src/wrapper.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import bridge, { Bridge } from './bridge'
|
|
2
|
-
|
|
3
|
-
export interface NativeDelegate {
|
|
4
|
-
ready: boolean
|
|
5
|
-
}
|
|
6
|
-
export type ErrorHandler = (err: Error) => void
|
|
7
|
-
|
|
8
|
-
export class NativeWrapper<T extends NativeDelegate> {
|
|
9
|
-
constructor(
|
|
10
|
-
private readonly delegate: T,
|
|
11
|
-
private readonly handler: ErrorHandler,
|
|
12
|
-
private readonly queue: Array<() => void> = []
|
|
13
|
-
) {}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Run a bridge method.
|
|
17
|
-
* It first waits for `.setup()` or `.useNativeConfiguration()` to be
|
|
18
|
-
* called and redirects exceptions to `handler`.
|
|
19
|
-
* @param method Name of the method to call.
|
|
20
|
-
* @param caller Function with the bridge function as first argument.
|
|
21
|
-
*/
|
|
22
|
-
public async run<M extends keyof Bridge>(
|
|
23
|
-
method: M,
|
|
24
|
-
caller: (fn: Bridge[M]) => Promise<void>
|
|
25
|
-
) {
|
|
26
|
-
const { delegate, handler, queue } = this
|
|
27
|
-
|
|
28
|
-
if (delegate.ready) {
|
|
29
|
-
await run()
|
|
30
|
-
} else {
|
|
31
|
-
queue.push(run)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async function run() {
|
|
35
|
-
try {
|
|
36
|
-
await caller(bridge[method])
|
|
37
|
-
} catch (err) {
|
|
38
|
-
return handler(err)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Waits for `.setup()` or `.useNativeConfiguration()` to be called. */
|
|
44
|
-
public async wait() {
|
|
45
|
-
if (this.delegate.ready) {
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return new Promise(resolve => this.queue.push(resolve))
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public ready() {
|
|
53
|
-
const { delegate, queue } = this
|
|
54
|
-
|
|
55
|
-
delegate.ready = true
|
|
56
|
-
|
|
57
|
-
while (queue.length) {
|
|
58
|
-
queue.shift()!()
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|