Skip to content

Commit 9196b97

Browse files
committed
feature: add getInstanceId method
1 parent a18bd9c commit 9196b97

File tree

8 files changed

+39
-13
lines changed

8 files changed

+39
-13
lines changed

android/src/main/java/com/mytracker/MytrackerModule.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import com.mytracker.MytrackerModule
55
import com.facebook.react.bridge.ReactApplicationContext
66
import com.facebook.react.bridge.ReactContextBaseJavaModule
77
import android.app.Application
8+
import androidx.annotation.WorkerThread
9+
import com.facebook.react.bridge.Promise
810
import com.facebook.react.bridge.ReactMethod
911
import com.my.tracker.MyTracker
1012
import com.facebook.react.bridge.ReadableMap
@@ -191,8 +193,14 @@ class MytrackerModule(reactContext: ReactApplicationContext) :
191193
fun setDebugMode(enable: Boolean) {
192194
MyTracker.setDebugMode(enable)
193195
}
196+
@ReactMethod
197+
@WorkerThread
198+
fun getInstanceId(promise: Promise) {
199+
val id = MyTracker.getInstanceId(reactApplicationContext)
200+
promise.resolve(id)
201+
}
194202

195-
companion object {
203+
companion object {
196204
const val NAME = "MyTracker"
197205
}
198206
}

example/ios/MytrackerExample.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@
486486
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
487487
CLANG_ENABLE_MODULES = YES;
488488
CURRENT_PROJECT_VERSION = 1;
489+
DEVELOPMENT_TEAM = 8WUKCL722Z;
489490
ENABLE_BITCODE = NO;
490491
INFOPLIST_FILE = MytrackerExample/Info.plist;
491492
LD_RUNPATH_SEARCH_PATHS = (
@@ -512,6 +513,7 @@
512513
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
513514
CLANG_ENABLE_MODULES = YES;
514515
CURRENT_PROJECT_VERSION = 1;
516+
DEVELOPMENT_TEAM = 8WUKCL722Z;
515517
INFOPLIST_FILE = MytrackerExample/Info.plist;
516518
LD_RUNPATH_SEARCH_PATHS = (
517519
"$(inherited)",

example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ PODS:
303303
- React-jsinspector (0.70.5)
304304
- React-logger (0.70.5):
305305
- glog
306-
- react-native-mytracker (0.7.2):
306+
- react-native-mytracker (0.8.0):
307307
- myTrackerSDK (= 3.1.5)
308308
- React-Core
309309
- React-perflogger (0.70.5)
@@ -566,7 +566,7 @@ SPEC CHECKSUMS:
566566
React-jsiexecutor: 31564fa6912459921568e8b0e49024285a4d584b
567567
React-jsinspector: badd81696361249893a80477983e697aab3c1a34
568568
React-logger: fdda34dd285bdb0232e059b19d9606fa0ec3bb9c
569-
react-native-mytracker: b36b1874f41c2899bfb6001a831e783e4ad0c5bd
569+
react-native-mytracker: 523707651e6c71f53bb4f56791e180c27f6552d3
570570
React-perflogger: e68d3795cf5d247a0379735cbac7309adf2fb931
571571
React-RCTActionSheet: 05452c3b281edb27850253db13ecd4c5a65bc247
572572
React-RCTAnimation: 578eebac706428e68466118e84aeacf3a282b4da
@@ -585,4 +585,4 @@ SPEC CHECKSUMS:
585585

586586
PODFILE CHECKSUM: 9a4c8c8f7e2fbbbb5e416330bf8abc7cff870cbe
587587

588-
COCOAPODS: 1.14.3
588+
COCOAPODS: 1.15.2

example/src/App.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import * as React from 'react';
1+
import React, { useEffect } from 'react';
22

33
import MyTracker from '@splicer97/react-native-mytracker';
44
import { StyleSheet, Text, View } from 'react-native';
55

66
export default function App() {
77
MyTracker.initTracker('initTracker');
8+
const getId = async () => {
9+
const id = await MyTracker.getInstanceId();
10+
console.log('🚀 ~ getId ~ id:', id);
11+
};
12+
useEffect(() => {
13+
getId();
14+
}, []);
815

9-
// MyTracker.trackEvent('trackEvent');
10-
11-
// MyTracker.trackEvent('trackEventWithParams', {
12-
// event1: '1',
13-
// event2: '2',
14-
// });
1516
return (
1617
<View style={styles.container}>
1718
<Text>Result</Text>

ios/Mytracker.mm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ @implementation Mytracker
140140
[MRMyTracker setDebugMode:enable];
141141
}
142142

143+
144+
145+
RCT_EXPORT_METHOD(getInstanceId: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
146+
{
147+
148+
NSString *instanceId = [MRMyTracker instanceId];
149+
150+
resolve(instanceId);
151+
}
152+
153+
154+
143155
// Don't compile this code when we build for the old architecture.
144156
#ifdef RCT_NEW_ARCH_ENABLED
145157
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"release": "release-it",
3535
"example": "yarn --cwd example",
3636
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build",
37-
"bootstrap": "yarn example && yarn install && yarn example pods"
37+
"bootstrap": "yarn example && yarn install && yarn example pod"
3838
},
3939
"keywords": [
4040
"react-native",

src/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ If your application requests access to the device's location, you can enable thi
117117
* @default 0
118118
*/
119119
setDebugMode(enable: boolean): void;
120+
/**
121+
* 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
122+
*/
123+
getInstanceId(): Promise<string>;
120124
}
121125
const MyTracker: IMyTracker = NativeModules.MyTracker;
122126
export default MyTracker;

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"allowUnreachableCode": false,
88
"allowUnusedLabels": false,
99
"esModuleInterop": true,
10-
"importsNotUsedAsValues": "error",
1110
"forceConsistentCasingInFileNames": true,
1211
"jsx": "react",
1312
"lib": ["esnext"],

0 commit comments

Comments
 (0)