forked from tonyxiao/react-native-analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (77 loc) · 2.54 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* @flow
*
* Created by Tal Kain <[email protected]>,
* and Ricky Reusser <[email protected]>,
* and Alex Rothberg
* and Tony Xiao
* Copyright (c) 2016 Fire Place Inc. All rights reserved.
*/
'use strict'
import {NativeModules} from 'react-native'
const NativeRNSegmentIOAnalytics = NativeModules.RNSegmentIOAnalytics
/**
* RNSegmentIOAnalytics is a React Native wrapper for the Segment.com Analytics SDK.
*/
export default {
/*
* https://segment.com/docs/libraries/ios/#identify
* https://segment.com/docs/libraries/android/#identify
*/
identify: function (userId: string, traits: ?Object, options: ?Object) {
NativeRNSegmentIOAnalytics.identify(userId, traits || {}, options || {})
},
/*
* https://segment.com/docs/libraries/ios/#track
* https://segment.com/docs/libraries/android/#track
*/
track: function (event: string, properties: ?Object, options: ?Object) {
NativeRNSegmentIOAnalytics.track(event, properties || {}, options || {})
},
/*
* https://segment.com/docs/libraries/ios/#screen
* https://segment.com/docs/libraries/android/#screen
*/
screen: function (screenName: string, properties: ?Object, options: ?Object) {
NativeRNSegmentIOAnalytics.screen(screenName, properties || {}, options || {})
},
/*
* https://segment.com/docs/connections/sources/catalog/libraries/mobile/ios/#anonymousid
* https://segment.com/docs/connections/sources/catalog/libraries/mobile/android/#anonymousid
*/
anonymousId: async function () {
try {
return await NativeRNSegmentIOAnalytics.anonymousId()
} catch (err) {
return ''
}
},
/*
* https://segment.com/docs/libraries/ios/#reset
* https://segment.com/docs/libraries/android/#how-do-you-handle-unique-identifiers-
*/
reset: function () {
NativeRNSegmentIOAnalytics.reset()
},
/*
* https://segment.com/docs/libraries/ios/#flushing
* https://segment.com/docs/libraries/android/#how-does-the-library-queue-api-calls-
*/
flush: function () {
NativeRNSegmentIOAnalytics.flush()
},
/*
* https://segment.com/docs/libraries/ios/#opt-out
* https://segment.com/docs/libraries/android/#context
*/
disable: function () {
NativeRNSegmentIOAnalytics.disable()
},
/*
* https://segment.com/docs/libraries/ios/#opt-out
* https://segment.com/docs/libraries/android/#context
*/
enable: function () {
NativeRNSegmentIOAnalytics.enable()
},
}