Skip to content

Commit 27b8b28

Browse files
committed
feat: register turbo modules
1 parent 24d0008 commit 27b8b28

File tree

3 files changed

+249
-119
lines changed

3 files changed

+249
-119
lines changed

react-native-mytracker.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Pod::Spec.new do |s|
1414
s.platforms = { :ios => "12.4" }
1515
s.source = { :git => "https://github.com/Splicer97/react-native-mytracker.git", :tag => "#{s.version}" }
1616

17-
s.source_files = "ios/**/*.{h,m,mm}"
17+
s.source_files = "ios/**/*.{h,m,mm,cpp}"
1818

1919
s.dependency "React-Core"
2020
s.dependency "myTrackerSDK", '3.2.0'

src/NativeMytracker.ts

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import type { TurboModule } from 'react-native';
2+
3+
import { TurboModuleRegistry } from 'react-native';
4+
5+
export interface Spec extends TurboModule {
6+
/**
7+
* Initializing the tracker
8+
*/
9+
initTracker(SDK_KEY: string): void;
10+
/**
11+
* An arbitrary event with a given name.
12+
*/
13+
trackEvent(name: string): void;
14+
/**
15+
* An arbitrary event with a given name. The optional attributes parameter allows you to set arbitrary key-value parameters for the event. Maximum length of name, key and value is 255 characters.
16+
*/
17+
trackEventWithParams(name: string, attributes: Object): void;
18+
/**
19+
* To track statistics not only by device, but also by user, set the customUserId parameter. This is the unique identifier of the user in your project, which you assign to him at the moment of registration. It must remain unchanged even if the user logs in on a different device. By setting this parameter, you can estimate the size and activity of the app's audience, regardless of how many devices the user has your app on. And you won't lose the history of accumulated data on the user if he decides to switch devices.
20+
* It is important to set the parameter before event tracking to pass the user ID with each tracked event.
21+
*/
22+
setCustomUserId(USER_ID: string): void;
23+
/**
24+
* Authorization event. The method must be called immediately after the user registers with the application. vkConnectId can be empty string.
25+
*/
26+
trackLoginEvent(userId: string, vkConnectId: string): void;
27+
/**
28+
* Authorization event. The method must be called immediately after the user registers with the application. vkConnectId can be empty string. The user ID must be passed in the userId parameter.
29+
*/
30+
trackLoginEventWithParams(
31+
userId: string,
32+
vkConnectId: string,
33+
attributes: Object
34+
): void;
35+
/**
36+
* An event to send an invitation.
37+
*/
38+
trackInviteEvent(): void;
39+
/**
40+
* An event to send an invitation. The optional eventParams parameter allows you to set arbitrary key-value parameters for the event. The maximum length of key and value is 255 characters.
41+
*/
42+
trackInviteEventWithParams(attributes: Object): void;
43+
/**
44+
* Forcing all events to be sent and resetting the send timer.
45+
To reduce the channel load and minimize the impact on application performance, the SDK buffers all events on the device before sending them to the server, and regularly sends the collected data in a compressed packet. By default, data is sent to the server every 15 minutes. This interval can be set via the bufferingPeriod parameter from 1 second to 1 day. If the user has closed the application, it will be sent the next time it is started. But some events are very important to get to the analytics as early as possible, especially in the first sessions after the installation of the application. The flush() method will help here.
46+
*/
47+
flush(): void;
48+
/**
49+
* Registration event. The method must be called immediately after the user registers with the application. vkConnectId can be empty string.
50+
*/
51+
trackRegistrationEvent(userId: string, vkConnectId: string): void;
52+
/**
53+
* Registration event. The method must be called immediately after the user registers with the application. vkConnectId can be empty string. The user ID must be passed in the userId parameter.
54+
*/
55+
trackRegistrationEventWithParams(
56+
userId: string,
57+
vkConnectId: string,
58+
attributes: Object
59+
): void;
60+
/**
61+
* The event of reaching a level without level number (level parameter).
62+
*/
63+
trackLevel(): void;
64+
/**
65+
* The event of reaching a level with level number (level parameter).
66+
*/
67+
trackLevelWithLevel(level: number): void;
68+
/**
69+
* The event of reaching a level with level number (level parameter). Additional parameter eventParams allows to set arbitrary key-value parameters for event. Maximum length of key and value is 255 characters.
70+
*/
71+
trackLevelWithLevelWithParams(level: number, params: Object): void;
72+
/**
73+
* Tracking application launches. The default is true.
74+
* @default true
75+
*/
76+
trackLaunchEnable(enable: boolean): void;
77+
/**
78+
* Interval in seconds during which a new startup will not be counted and the session will be interrupted when the application is minimized. The default is 30 seconds. You can set the value in the range of 30-7200 seconds.
79+
* @default 30
80+
*/
81+
trackLaunchTimeout(seconds: number): void;
82+
/**
83+
* Interval in seconds during which events will be accumulated on the device before being sent to the server. The default setting is 900 seconds. You can set the value in the range of 1-86400 seconds (1 day).
84+
* @default 900
85+
*/
86+
bufferingPeriod(seconds: number): void;
87+
/**
88+
* Interval in seconds after installing or updating an application, during which events will be immediately sent to the server without local buffering. The default is 0 seconds (immediate sending is disabled). You can set a value in the range of 0-432000 seconds (5 days).
89+
*/
90+
forcingPeriod(seconds: number): void;
91+
/**
92+
* Automatic in-app purchase tracking. The default is true.
93+
* @default true
94+
*/
95+
autotrackPurchase(enable: boolean): void;
96+
/**
97+
* Tracking the user's location. The default is false.
98+
If your application requests access to the device's location, you can enable this option to improve the accuracy of statistics related to the user's geography. In some cases, location tracking also improves attribution and predictive model performance.
99+
* @default 0
100+
* @platform IOS:
101+
* 0 — location is not tracked;
102+
* 1 — uses the system's cached value;
103+
* 2 — uses a request for the current location (default);
104+
* @platform Android:
105+
* 0 - do not track the user's location (default);
106+
* 1 or 2 - track the user's location;
107+
*/
108+
trackLocation(number: 0 | 1 | 2): void;
109+
/**
110+
* Enables/disables debug mode. The default is false.
111+
* @default 0
112+
*/
113+
setDebugMode(enable: boolean): void;
114+
/**
115+
* To transfer data from your server to the MyTracker server (e.g., untracked data, offline events, etc.), you may need a special device identifier, instanceId. The identifier is a UUID v4 value that is generated when the application is first launched and remains unchanged until the application (or application data) is removed from the device
116+
*/
117+
getInstanceId(): Promise<string>;
118+
}
119+
120+
export default TurboModuleRegistry.getEnforcing<Spec>('Mytracker');

src/index.tsx

Lines changed: 128 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,128 @@
1-
import { NativeModules } from 'react-native';
2-
3-
interface IMyTracker {
4-
/**
5-
* Initializing the tracker
6-
*/
7-
initTracker(SDK_KEY: string): void;
8-
/**
9-
* An arbitrary event with a given name.
10-
*/
11-
trackEvent(name: string): void;
12-
/**
13-
* An arbitrary event with a given name. The optional attributes parameter allows you to set arbitrary key-value parameters for the event. Maximum length of name, key and value is 255 characters.
14-
*/
15-
trackEventWithParams(name: string, attributes: Object): void;
16-
/**
17-
* To track statistics not only by device, but also by user, set the customUserId parameter. This is the unique identifier of the user in your project, which you assign to him at the moment of registration. It must remain unchanged even if the user logs in on a different device. By setting this parameter, you can estimate the size and activity of the app's audience, regardless of how many devices the user has your app on. And you won't lose the history of accumulated data on the user if he decides to switch devices.
18-
* It is important to set the parameter before event tracking to pass the user ID with each tracked event.
19-
*/
20-
setCustomUserId(USER_ID: string): void;
21-
/**
22-
* Authorization event. The method must be called immediately after the user registers with the application. vkConnectId can be empty string.
23-
*/
24-
trackLoginEvent(userId: string, vkConnectId: string): void;
25-
/**
26-
* Authorization event. The method must be called immediately after the user registers with the application. vkConnectId can be empty string. The user ID must be passed in the userId parameter.
27-
*/
28-
trackLoginEventWithParams(
29-
userId: string,
30-
vkConnectId: string,
31-
attributes: Object
32-
): void;
33-
/**
34-
* An event to send an invitation.
35-
*/
36-
trackInviteEvent(): void;
37-
/**
38-
* An event to send an invitation. The optional eventParams parameter allows you to set arbitrary key-value parameters for the event. The maximum length of key and value is 255 characters.
39-
*/
40-
trackInviteEventWithParams(attributes: Object): void;
41-
/**
42-
* Forcing all events to be sent and resetting the send timer.
43-
To reduce the channel load and minimize the impact on application performance, the SDK buffers all events on the device before sending them to the server, and regularly sends the collected data in a compressed packet. By default, data is sent to the server every 15 minutes. This interval can be set via the bufferingPeriod parameter from 1 second to 1 day. If the user has closed the application, it will be sent the next time it is started. But some events are very important to get to the analytics as early as possible, especially in the first sessions after the installation of the application. The flush() method will help here.
44-
*/
45-
flush(): void;
46-
/**
47-
* Registration event. The method must be called immediately after the user registers with the application. vkConnectId can be empty string.
48-
*/
49-
trackRegistrationEvent(userId: string, vkConnectId: string): void;
50-
/**
51-
* Registration event. The method must be called immediately after the user registers with the application. vkConnectId can be empty string. The user ID must be passed in the userId parameter.
52-
*/
53-
trackRegistrationEventWithParams(
54-
userId: string,
55-
vkConnectId: string,
56-
attributes: Object
57-
): void;
58-
/**
59-
* The event of reaching a level without level number (level parameter).
60-
*/
61-
trackLevel(): void;
62-
/**
63-
* The event of reaching a level with level number (level parameter).
64-
*/
65-
trackLevelWithLevel(level: number): void;
66-
/**
67-
* The event of reaching a level with level number (level parameter). Additional parameter eventParams allows to set arbitrary key-value parameters for event. Maximum length of key and value is 255 characters.
68-
*/
69-
trackLevelWithLevelWithParams(level: number, params: Object): void;
70-
/**
71-
* Tracking application launches. The default is true.
72-
* @default true
73-
*/
74-
trackLaunchEnable(enable: boolean): void;
75-
/**
76-
* Interval in seconds during which a new startup will not be counted and the session will be interrupted when the application is minimized. The default is 30 seconds. You can set the value in the range of 30-7200 seconds.
77-
* @default 30
78-
*/
79-
trackLaunchTimeout(seconds: number): void;
80-
/**
81-
* Interval in seconds during which events will be accumulated on the device before being sent to the server. The default setting is 900 seconds. You can set the value in the range of 1-86400 seconds (1 day).
82-
* @default 900
83-
*/
84-
bufferingPeriod(seconds: number): void;
85-
/**
86-
* Interval in seconds after installing or updating an application, during which events will be immediately sent to the server without local buffering. The default is 0 seconds (immediate sending is disabled). You can set a value in the range of 0-432000 seconds (5 days).
87-
*/
88-
forcingPeriod(seconds: number): void;
89-
/**
90-
* Automatic in-app purchase tracking. The default is true.
91-
* @default true
92-
*/
93-
autotrackPurchase(enable: boolean): void;
94-
/**
95-
* Tracking the user's location. The default is false.
96-
If your application requests access to the device's location, you can enable this option to improve the accuracy of statistics related to the user's geography. In some cases, location tracking also improves attribution and predictive model performance.
97-
* @default 0
98-
* @platform IOS:
99-
* 0 — location is not tracked;
100-
* 1 — uses the system's cached value;
101-
* 2 — uses a request for the current location (default);
102-
* @platform Android:
103-
* 0 - do not track the user's location (default);
104-
* 1 or 2 - track the user's location;
105-
*/
106-
trackLocation(number: 0 | 1 | 2): void;
107-
/**
108-
* Enables/disables debug mode. The default is false.
109-
* @default 0
110-
*/
111-
setDebugMode(enable: boolean): void;
112-
/**
113-
* To transfer data from your server to the MyTracker server (e.g., untracked data, offline events, etc.), you may need a special device identifier, instanceId. The identifier is a UUID v4 value that is generated when the application is first launched and remains unchanged until the application (or application data) is removed from the device
114-
*/
115-
getInstanceId(): Promise<string>;
116-
}
117-
const MyTracker: IMyTracker = NativeModules.MyTracker;
118-
export default MyTracker;
1+
import type { Spec } from './NativeMytracker';
2+
3+
const MyTracker: Spec = require('./NativeMyTracker').default;
4+
5+
function initTracker(SDK_KEY: string): void {
6+
return MyTracker.initTracker(SDK_KEY);
7+
}
8+
9+
function trackEvent(name: string): void {
10+
return MyTracker.trackEvent(name);
11+
}
12+
13+
function trackEventWithParams(name: string, attributes: Object): void {
14+
return MyTracker.trackEventWithParams(name, attributes);
15+
}
16+
17+
function setCustomUserId(USER_ID: string): void {
18+
return MyTracker.setCustomUserId(USER_ID);
19+
}
20+
21+
function trackLoginEvent(userId: string, vkConnectId: string): void {
22+
return MyTracker.trackLoginEvent(userId, vkConnectId);
23+
}
24+
25+
function trackLoginEventWithParams(
26+
userId: string,
27+
vkConnectId: string,
28+
attributes: Object
29+
): void {
30+
return MyTracker.trackLoginEventWithParams(userId, vkConnectId, attributes);
31+
}
32+
33+
function trackInviteEvent(): void {
34+
return MyTracker.trackInviteEvent();
35+
}
36+
37+
function trackInviteEventWithParams(attributes: Object): void {
38+
return MyTracker.trackInviteEventWithParams(attributes);
39+
}
40+
41+
function flush(): void {
42+
return MyTracker.flush();
43+
}
44+
45+
function trackRegistrationEvent(userId: string, vkConnectId: string): void {
46+
return MyTracker.trackRegistrationEvent(userId, vkConnectId);
47+
}
48+
49+
function trackRegistrationEventWithParams(
50+
userId: string,
51+
vkConnectId: string,
52+
attributes: Object
53+
): void {
54+
return MyTracker.trackRegistrationEventWithParams(
55+
userId,
56+
vkConnectId,
57+
attributes
58+
);
59+
}
60+
61+
function trackLevel(): void {
62+
return MyTracker.trackLevel();
63+
}
64+
65+
function trackLevelWithLevel(level: number): void {
66+
return MyTracker.trackLevelWithLevel(level);
67+
}
68+
69+
function trackLevelWithLevelWithParams(level: number, params: Object): void {
70+
return MyTracker.trackLevelWithLevelWithParams(level, params);
71+
}
72+
73+
function trackLaunchEnable(enable: boolean): void {
74+
return MyTracker.trackLaunchEnable(enable);
75+
}
76+
77+
function trackLaunchTimeout(seconds: number): void {
78+
return MyTracker.trackLaunchTimeout(seconds);
79+
}
80+
81+
function bufferingPeriod(period: number): void {
82+
return MyTracker.bufferingPeriod(period);
83+
}
84+
85+
function forcingPeriod(period: number): void {
86+
return MyTracker.forcingPeriod(period);
87+
}
88+
89+
function autotrackPurchase(enable: boolean): void {
90+
return MyTracker.autotrackPurchase(enable);
91+
}
92+
93+
function trackLocation(number: 0 | 1 | 2): void {
94+
return MyTracker.trackLocation(number);
95+
}
96+
97+
function setDebugMode(enable: boolean): void {
98+
return MyTracker.setDebugMode(enable);
99+
}
100+
101+
function getInstanceId(): Promise<string> {
102+
return MyTracker.getInstanceId();
103+
}
104+
105+
export default {
106+
initTracker,
107+
trackEvent,
108+
trackEventWithParams,
109+
setCustomUserId,
110+
trackLoginEvent,
111+
trackLoginEventWithParams,
112+
trackInviteEvent,
113+
trackInviteEventWithParams,
114+
flush,
115+
trackRegistrationEvent,
116+
trackRegistrationEventWithParams,
117+
trackLevel,
118+
trackLevelWithLevel,
119+
trackLevelWithLevelWithParams,
120+
trackLaunchEnable,
121+
trackLaunchTimeout,
122+
bufferingPeriod,
123+
forcingPeriod,
124+
autotrackPurchase,
125+
trackLocation,
126+
setDebugMode,
127+
getInstanceId,
128+
};

0 commit comments

Comments
 (0)