UNPKG

2.12 kBJavaScriptView Raw
1// @flow
2import { NativeModules, Platform } from 'react-native';
3
4const { ExponentSegment } = NativeModules;
5
6export default {
7 initialize(options: { androidWriteKey?: string, iosWriteKey?: string }) {
8 if (Platform.OS === 'android') {
9 return ExponentSegment.initializeAndroid(options.androidWriteKey);
10 } else if (Platform.OS === 'ios') {
11 return ExponentSegment.initializeIOS(options.iosWriteKey);
12 } else {
13 throw new Error(`Unable to initialize Segment on \`${Platform.OS}\``);
14 }
15 },
16
17 initializeIOS(writeKey: string) {
18 console.warn(
19 '`Segment.initializeIOS(writeKey)` is deprecated, use `Segment.initialize({androidWriteKey, iosWriteKey})` instead.'
20 );
21 if (Platform.OS !== 'ios') {
22 throw new Error(
23 `Expo.Segment.initializeIOS() should only be called on iOS, not \`${Platform.OS}\``
24 );
25 }
26
27 return ExponentSegment.initializeIOS(writeKey);
28 },
29
30 initializeAndroid(writeKey: string) {
31 console.warn(
32 '`Segment.initializeAndroid(writeKey)` is deprecated, use `Segment.initialize({androidWriteKey, iosWriteKey})` instead.'
33 );
34 if (Platform.OS !== 'android') {
35 throw new Error(
36 `Expo.Segment.initializeAndroid() should only be called on Android, not \`${Platform.OS}\``
37 );
38 }
39
40 return ExponentSegment.initializeAndroid(writeKey);
41 },
42
43 identify(userId: string) {
44 return ExponentSegment.identify(userId);
45 },
46
47 identifyWithTraits(userId: string, traits: { [string]: any }) {
48 return ExponentSegment.identifyWithTraits(userId, traits);
49 },
50
51 reset() {
52 return ExponentSegment.reset();
53 },
54
55 track(event: string) {
56 return ExponentSegment.track((event: string));
57 },
58
59 trackWithProperties(event: string, properties: { [string]: any }) {
60 return ExponentSegment.trackWithProperties(event, properties);
61 },
62
63 screen(screenName: string) {
64 return ExponentSegment.screen(screenName);
65 },
66
67 screenWithProperties(event: string, properties: string) {
68 return ExponentSegment.screenWithProperties(event, properties);
69 },
70
71 flush() {
72 return ExponentSegment.flush();
73 },
74};