1
1
package com .mytracker ;
2
2
3
+ import android .app .Application ;
4
+
3
5
import androidx .annotation .NonNull ;
4
6
5
- import com .facebook .react .bridge .Promise ;
6
7
import com .facebook .react .bridge .ReactApplicationContext ;
7
8
import com .facebook .react .bridge .ReactContextBaseJavaModule ;
8
9
import com .facebook .react .bridge .ReactMethod ;
10
+ import com .facebook .react .bridge .ReadableMap ;
9
11
import com .facebook .react .module .annotations .ReactModule ;
12
+ import com .my .tracker .MyTracker ;
13
+ import com .my .tracker .MyTrackerConfig ;
14
+ import com .my .tracker .MyTrackerParams ;
15
+
16
+ import java .util .HashMap ;
17
+ import java .util .Map ;
10
18
11
19
@ ReactModule (name = MytrackerModule .NAME )
12
20
public class MytrackerModule extends ReactContextBaseJavaModule {
13
- public static final String NAME = "Mytracker" ;
21
+ public static final String NAME = "MyTracker" ;
22
+ private final Application application ;
14
23
15
24
public MytrackerModule (ReactApplicationContext reactContext ) {
16
25
super (reactContext );
26
+ this .application = (Application ) reactContext .getApplicationContext ();
17
27
}
18
28
19
29
@ Override
@@ -22,11 +32,166 @@ public String getName() {
22
32
return NAME ;
23
33
}
24
34
35
+ @ ReactMethod
36
+ public void initTracker (String SDK_KEY ) {
37
+ MyTracker .initTracker (SDK_KEY , application );
38
+ }
39
+
40
+ @ ReactMethod
41
+ public void trackEvent (String name ) {
42
+ MyTracker .trackEvent (name );
43
+ }
44
+
45
+ @ ReactMethod
46
+ public void trackLoginEvent (String userId , String vkConnectId ) {
47
+ MyTracker .trackLoginEvent (userId , vkConnectId );
48
+ }
49
+
50
+ @ ReactMethod
51
+ public void trackLoginEventWithParams (String userId , String vkConnectId , ReadableMap attributes ) {
52
+ Map <String , Object > map = attributes .toHashMap ();
53
+ Map <String , String > params = new HashMap <>();
54
+ for (Map .Entry <String , Object > entry : map .entrySet ()) {
55
+ if (entry .getValue () instanceof String ) {
56
+ params .put (entry .getKey (), (String ) entry .getValue ());
57
+ }
58
+ }
59
+ MyTracker .trackLoginEvent (userId , vkConnectId , params );
60
+ }
61
+
62
+ @ ReactMethod
63
+ public void trackEventWithParams (String name , ReadableMap attributes ) {
64
+ Map <String , Object > map = attributes .toHashMap ();
65
+ Map <String , String > params = new HashMap <>();
66
+ for (Map .Entry <String , Object > entry : map .entrySet ()) {
67
+ if (entry .getValue () instanceof String ) {
68
+ params .put (entry .getKey (), (String ) entry .getValue ());
69
+ }
70
+ }
71
+ MyTracker .trackEvent (name , params );
72
+ }
73
+
74
+ @ ReactMethod
75
+ public void setCustomUserId (String USER_ID ) {
76
+ MyTrackerParams trackerParams = MyTracker .getTrackerParams ();
77
+ trackerParams .setCustomUserId (USER_ID );
78
+ }
79
+
80
+ @ ReactMethod
81
+ public void trackInviteEvent () {
82
+ MyTracker .trackInviteEvent ();
83
+ }
84
+
85
+ @ ReactMethod
86
+ public void trackInviteEventWithParams (ReadableMap attributes ) {
87
+ Map <String , Object > map = attributes .toHashMap ();
88
+ Map <String , String > params = new HashMap <>();
89
+ for (Map .Entry <String , Object > entry : map .entrySet ()) {
90
+ if (entry .getValue () instanceof String ) {
91
+ params .put (entry .getKey (), (String ) entry .getValue ());
92
+ }
93
+ MyTracker .trackInviteEvent (params );
94
+ }
95
+ }
96
+
97
+ @ ReactMethod
98
+ public void flush () {
99
+ MyTracker .flush ();
100
+ }
101
+
102
+ @ ReactMethod
103
+ public void trackRegistrationEvent (String userId , String vkConnectId ) {
104
+ MyTracker .trackRegistrationEvent (userId , vkConnectId );
105
+ }
106
+
107
+ @ ReactMethod
108
+ public void trackRegistrationEventWithParams (String userId , String vkConnectId , ReadableMap attributes ) {
109
+ Map <String , Object > map = attributes .toHashMap ();
110
+ Map <String , String > params = new HashMap <>();
111
+ for (Map .Entry <String , Object > entry : map .entrySet ()) {
112
+ if (entry .getValue () instanceof String ) {
113
+ params .put (entry .getKey (), (String ) entry .getValue ());
114
+ }
115
+ }
116
+ MyTracker .trackRegistrationEvent (userId , vkConnectId , params );
117
+ }
118
+
119
+ @ ReactMethod
120
+ public void trackLevel () {
121
+ MyTracker .trackLevelEvent ();
122
+ }
123
+
124
+ @ ReactMethod
125
+ public void trackLevelWithLevel (int level ) {
126
+ MyTracker .trackLevelEvent (level , (Map <String , String >) null );
127
+ }
128
+
129
+ @ ReactMethod
130
+ public void trackLevelWithLevelWithParams (int level , ReadableMap attributes ) {
131
+ Map <String , Object > map = attributes .toHashMap ();
132
+ Map <String , String > params = new HashMap <>();
133
+ for (Map .Entry <String , Object > entry : map .entrySet ()) {
134
+ if (entry .getValue () instanceof String ) {
135
+ params .put (entry .getKey (), (String ) entry .getValue ());
136
+ }
137
+ }
138
+ MyTracker .trackLevelEvent (level , params );
139
+ }
140
+
141
+ @ ReactMethod
142
+ public void trackLaunchEnable (boolean enable ) {
143
+ MyTrackerConfig trackerConfig = MyTracker .getTrackerConfig ();
144
+ trackerConfig .setTrackingLaunchEnabled (enable );
145
+ }
146
+
147
+ @ ReactMethod
148
+ public void trackLaunchTimeout (int seconds ) {
149
+ MyTrackerConfig trackerConfig = MyTracker .getTrackerConfig ();
150
+ trackerConfig .setLaunchTimeout (seconds );
151
+ }
152
+
153
+ @ ReactMethod
154
+ public void bufferingPeriod (int seconds ) {
155
+ MyTrackerConfig trackerConfig = MyTracker .getTrackerConfig ();
156
+ trackerConfig .setBufferingPeriod (seconds );
157
+ }
158
+
159
+ @ ReactMethod
160
+ public void forcingPeriod (int seconds ) {
161
+ MyTrackerConfig trackerConfig = MyTracker .getTrackerConfig ();
162
+ trackerConfig .setForcingPeriod (seconds );
163
+ }
164
+
165
+ @ ReactMethod
166
+ public void autotrackPurchase (boolean enable ) {
167
+ MyTrackerConfig trackerConfig = MyTracker .getTrackerConfig ();
168
+ trackerConfig .setAutotrackingPurchaseEnabled (enable );
169
+ }
170
+
171
+ @ ReactMethod
172
+ public void trackLocation (int number ) {
173
+ MyTrackerConfig trackerConfig = MyTracker .getTrackerConfig ();
174
+ if (number == 0 ) {
175
+ trackerConfig .setTrackingLocationEnabled (false );
176
+ }
177
+ if (number == 1 || number == 2 ) {
178
+ trackerConfig .setTrackingLocationEnabled (true );
179
+ }
180
+ }
181
+
182
+ @ ReactMethod
183
+ public void region (int number ) {
184
+ MyTrackerConfig trackerConfig = MyTracker .getTrackerConfig ();
185
+ if (number == 1 ) {
186
+ trackerConfig .setRegion (MyTrackerConfig .Region .RU );
187
+ }
188
+ if (number == 2 ) {
189
+ trackerConfig .setRegion (MyTrackerConfig .Region .EU );
190
+ }
191
+ }
25
192
26
- // Example method
27
- // See https://reactnative.dev/docs/native-modules-android
28
193
@ ReactMethod
29
- public void multiply ( double a , double b , Promise promise ) {
30
- promise . resolve ( a * b );
194
+ public void setDebugMode ( boolean enable ) {
195
+ MyTracker . setDebugMode ( enable );
31
196
}
32
197
}
0 commit comments