File tree Expand file tree Collapse file tree 4 files changed +29
-16
lines changed
android/src/main/java/com/logicwind/reactnativematomotracker Expand file tree Collapse file tree 4 files changed +29
-16
lines changed Original file line number Diff line number Diff line change @@ -41,14 +41,10 @@ class ReactNativeMatomoTrackerModule(reactContext: ReactApplicationContext) :
4141 fun setTracker (uri : String ,siteId : Int ) {
4242 if (tracker == null ) {
4343 try {
44-
4544 tracker = TrackerBuilder .createDefault(uri, siteId)
4645 .build(mMatomoTracker)
47-
4846 Log .e(TAG , " initialized successfully! ${tracker} " )
4947
50-
51-
5248 } catch (e: Exception ) {
5349 Log .e(TAG , " An error occurred: ${e.message} " )
5450 }
@@ -64,8 +60,22 @@ class ReactNativeMatomoTrackerModule(reactContext: ReactApplicationContext) :
6460 @ReactMethod
6561 fun createTracker (uri : String ,siteId : Int ,token : String ) {
6662 authToken = token;
67- site_Id = siteId.toString();
68- setTracker(uri,siteId)
63+
64+ if (uri.isEmpty() && siteId <= 0 ) {
65+ // Handle the error appropriately
66+ Log .e(" createTracker" , " baseURL and siteId is empty or undeifne" );
67+ // You can show an error message, disable tracking, or use default value
68+ }
69+ else if (uri.isEmpty()){
70+ Log .e(" createTracker" , " baseURL is empty or undeifne" );
71+ }
72+ else if (siteId <= 0 ){
73+ Log .e(" createTracker" , " siteId is empty or undeifne" );
74+ }
75+ else {
76+ site_Id = siteId.toString();
77+ setTracker(uri,siteId)
78+ }
6979 }
7080
7181 @ReactMethod
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ export default function App() {
3434 const [ result ] = React . useState < number | undefined > ( ) ;
3535
3636 React . useEffect ( ( ) => {
37- createTracker ( undefined , undefined , ) //Replace 1 with your matomo site id
37+ createTracker ( "https://your-domain-url/matomo.php" , 1 ) //Replace 1 with your matomo site id
3838 setLogger ( )
3939 } , [ ] ) ;
4040
Original file line number Diff line number Diff line change @@ -20,22 +20,25 @@ class ReactNativeMatomoTracker: NSObject {
2020
2121 @objc ( createTracker: withSiteId: withToken: )
2222 func createTracker( uri: String , siteId: String , token: String ) {
23- do {
2423 authToken = token
2524 let queue = UserDefaultsQueue ( UserDefaults . standard, autoSave: true )
2625
2726 baseURL = uri
2827 site_id = siteId
29- if ( !baseURL. isEmpty && !siteId. isEmpty) {
28+ if ( baseURL. isEmpty && siteId. isEmpty) {
29+ print ( " createTracker : baseURL and siteId is empty or undeifne " )
30+ }
31+ else if ( baseURL. isEmpty) {
32+ print ( " createTracker : baseURL is empty or undeifne " )
33+ }
34+ else if ( siteId. isEmpty) {
35+ print ( " createTracker : siteId is empty or undeifne " )
36+ }
37+ else if ( !baseURL. isEmpty && !siteId. isEmpty) {
3038 let dispatcher = URLSessionDispatcher ( baseURL: URL ( string: baseURL) !)
3139 matomoTracker = MatomoTracker ( siteId: siteId, queue: queue, dispatcher: dispatcher)
3240 matomoTracker? . userId = _id;
3341 }
34- } catch let error {
35- // Handle the error
36- print ( " An error occurred: \( error. localizedDescription) " )
37- }
38-
3942 }
4043
4144
Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ const ReactNativeMatomoTracker = NativeModules.ReactNativeMatomoTracker
1717 }
1818 ) ;
1919
20- export function createTracker ( uri : String , siteId : Number , token :String = "" ) {
21- return ReactNativeMatomoTracker . createTracker ( uri , Platform . OS == "ios" ?siteId . toString ( ) :siteId , token ) ;
20+ export function createTracker ( uri : String = "" , siteId : Number = 0 , token :String = "" ) {
21+ return ReactNativeMatomoTracker . createTracker ( uri , Platform . OS == "ios" ?siteId ? .toString ( ) :siteId , token ) ;
2222}
2323
2424export function trackScreen ( screenName : String , title : String ) {
You can’t perform that action at this time.
0 commit comments