This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
forked from segmentio/analytics-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes segmentio#11
- Loading branch information
Showing
3 changed files
with
44 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,47 @@ | ||
import { NativeModules } from 'react-native' | ||
|
||
import bridge = NativeModules.RNAnalytics | ||
export interface Configuration { | ||
writeKey: string | ||
recordScreenViews: boolean | ||
trackAppLifecycleEvents: boolean | ||
trackAttributionData: boolean | ||
debug: boolean | ||
flushAt: number | ||
|
||
android: { | ||
flushInterval?: number | ||
collectDeviceId: boolean | ||
} | ||
ios: { | ||
trackAdvertising: boolean | ||
trackDeepLinks: boolean | ||
} | ||
} | ||
|
||
export type JsonValue = boolean | number | string | null | JsonList | JsonMap | ||
export interface JsonMap { | ||
[key: string]: JsonValue | ||
[index: number]: JsonValue | ||
} | ||
export interface JsonList extends Array<JsonValue> {} | ||
|
||
export interface Bridge { | ||
setup(configuration: Configuration): Promise<void> | ||
track(event: string, properties: JsonMap, context: JsonMap): Promise<void> | ||
identify(user: string, traits: JsonMap, context: JsonMap): Promise<void> | ||
screen(name: string, properties: JsonMap, context: JsonMap): Promise<void> | ||
group(groupId: string, traits: JsonMap, context: JsonMap): Promise<void> | ||
alias(alias: string, context: JsonMap): Promise<void> | ||
reset(): Promise<void> | ||
flush(): Promise<void> | ||
enable(): Promise<void> | ||
disable(): Promise<void> | ||
} | ||
|
||
const bridge: Bridge = NativeModules.RNAnalytics | ||
|
||
if (!bridge) { | ||
throw new Error('Failed to load Analytics native module.') | ||
} | ||
|
||
export default bridge | ||
export type JsonMap = NativeModules.RNAnalytics.JsonMap | ||
export type Bridge = typeof bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,2 @@ | ||
declare module '*.json' | ||
declare module 'react-native' { | ||
export namespace NativeModules.RNAnalytics { | ||
export interface Configuration { | ||
writeKey: string | ||
recordScreenViews: boolean | ||
trackAppLifecycleEvents: boolean | ||
trackAttributionData: boolean | ||
debug: boolean | ||
flushAt: number | ||
|
||
android: { | ||
flushInterval?: number | ||
collectDeviceId: boolean | ||
} | ||
ios: { | ||
trackAdvertising: boolean | ||
trackDeepLinks: boolean | ||
} | ||
} | ||
|
||
export type JsonValue = | ||
| boolean | ||
| number | ||
| string | ||
| null | ||
| JsonList | ||
| JsonMap | ||
export interface JsonMap { | ||
[key: string]: JsonValue | ||
[index: number]: JsonValue | ||
} | ||
export interface JsonList extends Array<JsonValue> {} | ||
|
||
export function setup(configuration: Configuration): Promise<void> | ||
export function track( | ||
event: string, | ||
properties: JsonMap, | ||
context: JsonMap | ||
): Promise<void> | ||
export function identify( | ||
user: string, | ||
traits: JsonMap, | ||
context: JsonMap | ||
): Promise<void> | ||
export function screen( | ||
name: string, | ||
properties: JsonMap, | ||
context: JsonMap | ||
): Promise<void> | ||
export function group( | ||
groupId: string, | ||
traits: JsonMap, | ||
context: JsonMap | ||
): Promise<void> | ||
export function alias(alias: string, context: JsonMap): Promise<void> | ||
export function reset(): Promise<void> | ||
export function flush(): Promise<void> | ||
export function enable(): Promise<void> | ||
export function disable(): Promise<void> | ||
} | ||
} | ||
declare module 'react-native' |