|
1 | 1 | import { NativeModules } from 'react-native' |
2 | 2 |
|
3 | | -import bridge = NativeModules.RNAnalytics |
| 3 | +export interface Configuration { |
| 4 | + writeKey: string |
| 5 | + recordScreenViews: boolean |
| 6 | + trackAppLifecycleEvents: boolean |
| 7 | + trackAttributionData: boolean |
| 8 | + debug: boolean |
| 9 | + flushAt: number |
| 10 | + |
| 11 | + android: { |
| 12 | + flushInterval?: number |
| 13 | + collectDeviceId: boolean |
| 14 | + } |
| 15 | + ios: { |
| 16 | + trackAdvertising: boolean |
| 17 | + trackDeepLinks: boolean |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +export type JsonValue = boolean | number | string | null | JsonList | JsonMap |
| 22 | +export interface JsonMap { |
| 23 | + [key: string]: JsonValue |
| 24 | + [index: number]: JsonValue |
| 25 | +} |
| 26 | +export interface JsonList extends Array<JsonValue> {} |
| 27 | + |
| 28 | +export interface Bridge { |
| 29 | + setup(configuration: Configuration): Promise<void> |
| 30 | + track(event: string, properties: JsonMap, context: JsonMap): Promise<void> |
| 31 | + identify(user: string, traits: JsonMap, context: JsonMap): Promise<void> |
| 32 | + screen(name: string, properties: JsonMap, context: JsonMap): Promise<void> |
| 33 | + group(groupId: string, traits: JsonMap, context: JsonMap): Promise<void> |
| 34 | + alias(alias: string, context: JsonMap): Promise<void> |
| 35 | + reset(): Promise<void> |
| 36 | + flush(): Promise<void> |
| 37 | + enable(): Promise<void> |
| 38 | + disable(): Promise<void> |
| 39 | +} |
| 40 | + |
| 41 | +const bridge: Bridge = NativeModules.RNAnalytics |
4 | 42 |
|
5 | 43 | if (!bridge) { |
6 | 44 | throw new Error('Failed to load Analytics native module.') |
7 | 45 | } |
8 | 46 |
|
9 | 47 | export default bridge |
10 | | -export type JsonMap = NativeModules.RNAnalytics.JsonMap |
11 | | -export type Bridge = typeof bridge |
|
0 commit comments