Skip to content

Commit aa798b9

Browse files
handle undefine siteid and url pass in createTracker
1 parent f5c74c1 commit aa798b9

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

example/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function App() {
3434
const [result] = React.useState<number | undefined>();
3535

3636
React.useEffect(() => {
37-
createTracker("https://your-domain-url/matomo.php", 1) //Replace 1 with your matomo site id
37+
createTracker(undefined, undefined,) //Replace 1 with your matomo site id
3838
setLogger()
3939
}, []);
4040

ios/ReactNativeMatomoTracker.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ class ReactNativeMatomoTracker: NSObject {
2626

2727
baseURL = uri
2828
site_id = siteId
29-
30-
let dispatcher = URLSessionDispatcher(baseURL: URL(string:baseURL)!)
31-
matomoTracker = MatomoTracker(siteId: siteId, queue: queue, dispatcher: dispatcher)
32-
matomoTracker?.userId = _id;
29+
if(!baseURL.isEmpty && !siteId.isEmpty){
30+
let dispatcher = URLSessionDispatcher(baseURL: URL(string:baseURL)!)
31+
matomoTracker = MatomoTracker(siteId: siteId, queue: queue, dispatcher: dispatcher)
32+
matomoTracker?.userId = _id;
33+
}
3334
} catch let error {
3435
// Handle the error
3536
print("An error occurred: \(error.localizedDescription)")
@@ -61,8 +62,10 @@ class ReactNativeMatomoTracker: NSObject {
6162

6263
@objc(trackOutlink:)
6364
func trackOutlink(url:String) {
64-
let event = Event(tracker: matomoTracker!, action: ["link"],customTrackingParameters: ["link" : url],isCustomAction: true)
65-
matomoTracker?.track(event)
65+
if(matomoTracker != nil){
66+
let event = Event(tracker: matomoTracker!, action: ["link"],customTrackingParameters: ["link" : url],isCustomAction: true)
67+
matomoTracker?.track(event)
68+
}
6669
}
6770

6871
@objc(trackSearch:)
@@ -83,8 +86,11 @@ class ReactNativeMatomoTracker: NSObject {
8386

8487
@objc(trackDownload:withAction:withUrl:)
8588
func trackDownload(category:String,action:String,url:String) {
86-
let event = Event(tracker: matomoTracker!, action: ["download"],customTrackingParameters: ["download" : url],isCustomAction: true)
87-
matomoTracker?.track(event)
89+
if(matomoTracker != nil){
90+
let event = Event(tracker: matomoTracker!, action: ["download"],customTrackingParameters: ["download" : url],isCustomAction: true)
91+
matomoTracker?.track(event)
92+
93+
}
8894
}
8995

9096
@objc(setUserId:)

0 commit comments

Comments
 (0)