Skip to content

Commit bc6f120

Browse files
committed
fix: examples
1 parent 906ebc0 commit bc6f120

File tree

14 files changed

+14882
-52
lines changed

14 files changed

+14882
-52
lines changed

README.md

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,102 @@
11
# react-native-mytracker
22

3-
123
3+
This is unofficial React Native wrapper for myTrackerSDK
44

55
## Installation
66

77
```sh
8-
npm install react-native-mytracker
8+
npm install @splicer97/react-native-mytracker
9+
```
10+
11+
or
12+
13+
```sh
14+
yarn add @splicer97/react-native-mytracker
915
```
1016

1117
## Usage
1218

1319
```js
14-
import { multiply } from 'react-native-mytracker';
20+
import MyTracker from '@splicer97/react-native-mytracker';
1521

1622
// ...
1723

18-
const result = await multiply(3, 7);
24+
MyTracker.initTracker('SDK_KEY');
25+
26+
//MyTracker Parameters
27+
MyTracker.setCustomUserId('USER_ID');
28+
29+
//MyTracker Configurations
30+
MyTracker.trackLaunchEnable(true);
31+
32+
MyTracker.autotrackPurchase(true);
33+
34+
MyTracker.trackLaunchTimeout(30);
35+
36+
MyTracker.bufferingPeriod(30);
37+
38+
MyTracker.forcingPeriod(30);
39+
40+
//for IOS:
41+
// 0 = MRLocationTrackingModeNone — отслеживание местоположения не производится
42+
// 1 = MRLocationTrackingModeCached — используется закэшированное системой значение
43+
// 2 = MRLocationTrackingModeActive — используется запрос текущего местоположения (по умолчанию)
44+
// for Android:
45+
// 0 = false - не отслеживать местоположение пользователя (по умолчанию)
46+
// 1 or 2 = true - отслеживать местоположение пользователя
47+
MyTracker.trackLocation(0);
48+
49+
//for IOS:
50+
// 0 = MRRegionNotSet — значение по умолчанию
51+
// 1 = MRRegionRu — сервер, расположенный на территории Российской Федерации
52+
// 2 = MRRegionEu — сервер, расположенный на территории Европы
53+
// for Android:
54+
// 0 - значение по умолчанию
55+
// 1 = Region.RU — сервер, расположенный на территории Российской Федерации
56+
// 2 = Region.EU — сервер, расположенный на территории Европы
57+
MyTracker.region(0);
58+
59+
MyTracker.setDebugMode(false);
60+
61+
//MyTracker Events
62+
MyTracker.trackEvent('name');
63+
64+
MyTracker.trackEventWithParams('name', {
65+
param1: 'name1',
66+
param2: 'name2',
67+
});
68+
69+
MyTracker.trackLoginEvent('userId', 'vkConnectId');
70+
71+
MyTracker.trackLoginEventWithParams('userId', 'vkConnectId', {
72+
param1: 'name1',
73+
param2: 'name2',
74+
});
75+
76+
MyTracker.trackInviteEvent();
77+
78+
MyTracker.trackInviteEventWithParams({
79+
param1: 'name1',
80+
param2: 'name2',
81+
});
82+
83+
MyTracker.flush();
84+
85+
MyTracker.trackRegistrationEvent('userId', 'vkConnectId');
86+
87+
MyTracker.trackRegistrationEventWithParams('userId', 'vkConnectId', {
88+
param1: 'name1',
89+
param2: 'name2',
90+
});
91+
92+
MyTracker.trackLevel();
93+
94+
MyTracker.trackLevelWithLevel(1);
95+
96+
MyTracker.trackLevelWithLevelWithParams(1, {
97+
param1: 'name1',
98+
param2: 'name2',
99+
});
19100
```
20101

21102
## Contributing

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ repositories {
126126
dependencies {
127127
//noinspection GradleDynamicVersion
128128
implementation "com.facebook.react:react-native:+"
129+
implementation 'com.my.tracker:mytracker-sdk:3.0.10'
129130
// From node_modules
130131
}
131132

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.mytracker">
3-
3+
<uses-permission android:name="android.permission.INTERNET" />
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
46
</manifest>
Lines changed: 171 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
package com.mytracker;
22

3+
import android.app.Application;
4+
35
import androidx.annotation.NonNull;
46

5-
import com.facebook.react.bridge.Promise;
67
import com.facebook.react.bridge.ReactApplicationContext;
78
import com.facebook.react.bridge.ReactContextBaseJavaModule;
89
import com.facebook.react.bridge.ReactMethod;
10+
import com.facebook.react.bridge.ReadableMap;
911
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;
1018

1119
@ReactModule(name = MytrackerModule.NAME)
1220
public class MytrackerModule extends ReactContextBaseJavaModule {
13-
public static final String NAME = "Mytracker";
21+
public static final String NAME = "MyTracker";
22+
private final Application application;
1423

1524
public MytrackerModule(ReactApplicationContext reactContext) {
1625
super(reactContext);
26+
this.application = (Application) reactContext.getApplicationContext();
1727
}
1828

1929
@Override
@@ -22,11 +32,166 @@ public String getName() {
2232
return NAME;
2333
}
2434

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+
}
25192

26-
// Example method
27-
// See https://reactnative.dev/docs/native-modules-android
28193
@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);
31196
}
32197
}

example/ios/MytrackerExample.xcodeproj/project.pbxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@
562562
COPY_PHASE_STRIP = NO;
563563
ENABLE_STRICT_OBJC_MSGSEND = YES;
564564
ENABLE_TESTABILITY = YES;
565-
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
565+
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
566566
GCC_C_LANGUAGE_STANDARD = gnu99;
567567
GCC_DYNAMIC_NO_PIC = NO;
568568
GCC_NO_COMMON_BLOCKS = YES;
@@ -596,6 +596,7 @@
596596
"-DFOLLY_MOBILE=1",
597597
"-DFOLLY_USE_LIBCPP=1",
598598
);
599+
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
599600
SDKROOT = iphoneos;
600601
};
601602
name = Debug;
@@ -633,7 +634,7 @@
633634
COPY_PHASE_STRIP = YES;
634635
ENABLE_NS_ASSERTIONS = NO;
635636
ENABLE_STRICT_OBJC_MSGSEND = YES;
636-
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
637+
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
637638
GCC_C_LANGUAGE_STANDARD = gnu99;
638639
GCC_NO_COMMON_BLOCKS = YES;
639640
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
@@ -659,6 +660,7 @@
659660
"-DFOLLY_MOBILE=1",
660661
"-DFOLLY_USE_LIBCPP=1",
661662
);
663+
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
662664
SDKROOT = iphoneos;
663665
VALIDATE_PRODUCT = YES;
664666
};

example/ios/MytrackerExample.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)