@@ -47,82 +47,110 @@ class ReactNativeMatomoTrackerModule(reactContext: ReactApplicationContext) :
4747
4848 // Example method
4949 // See https://reactnative.dev/docs/native-modules-android
50+
51+ @ReactMethod
52+ fun startSession () {
53+ tracker?.startNewSession()
54+ }
55+
5056 @ReactMethod
5157 fun createTracker (uri : String ,siteId : Int ) {
5258 setTracker(uri,siteId)
5359 }
5460
5561 @ReactMethod
5662 fun trackScreen (screenName : String ,title : String ) {
57- TrackHelper .track().screen(screenName).title(title).with (tracker)
58-
63+ if (tracker != null ) {
64+ TrackHelper .track().screen(screenName).title(title).with (tracker)
65+ }
5966 }
6067
6168 @ReactMethod
6269 fun trackEvent (category : String ,action : String ,name : String ,value : Float ) {
63- TrackHelper .track().event(category, action).name(name).value(value).with (tracker)
64-
70+ if (tracker != null ) {
71+ TrackHelper .track().event(category, action).name(name).value(value).with (tracker)
72+ }
6573 }
6674 @ReactMethod
6775 fun trackDispatch () {
68- tracker?.dispatch()
76+ if (tracker != null ) {
77+ tracker?.dispatch()
78+ }
6979 }
7080
7181
7282 @ReactMethod
7383 fun trackOutlink (url : String ) {
7484 val validUrl = URL (url)
75- TrackHelper .track()
76- .outlink(validUrl)
77- .with (tracker)
85+ if (tracker != null ) {
86+ TrackHelper .track()
87+ .outlink(validUrl)
88+ .with (tracker);
89+ }
7890 }
7991
8092 @ReactMethod
8193 fun trackSearch (keyword : String ) {
94+ if (tracker != null ) {
8295 TrackHelper .track()
8396 .search(keyword)
84- .with (tracker)
97+ .with (tracker);
98+ }
8599 }
86100
87101 @ReactMethod
88102 fun trackImpression (contentName : String ) {
89- TrackHelper .track()
90- .impression(contentName)
91- .with (tracker)
103+ if (tracker != null ) {
104+ TrackHelper .track()
105+ .impression(contentName)
106+ .with (tracker);
107+ }
92108 }
93109
94110
95111 @ReactMethod
96112 fun trackInteraction (contentName : String ,contentInteraction : String ) {
97- TrackHelper .track()
98- .interaction(contentName, contentInteraction)
99- .with (tracker)
113+ if (tracker != null ) {
114+ TrackHelper .track()
115+ .interaction(contentName, contentInteraction)
116+ .with (tracker)
117+ }
100118 }
101119
102120 @ReactMethod
103121 fun trackDownload (category : String ,action : String ,url : String ) {
104- TrackHelper .track().event(category, action).name(url).with (tracker)
122+ if (tracker != null ) {
123+ TrackHelper .track().event(category, action).name(url).with (tracker);
105124// TrackHelper.track().download().with(tracker);
125+ }
106126 }
107127
108128 @ReactMethod
109129 fun setUserId (id : String ) {
110- tracker?.setUserId(id);
130+ if (tracker != null ) {
131+ tracker?.setUserId(id);
132+ }
111133 }
112134
113135 @ReactMethod
114136 fun trackScreens () {
115- TrackHelper .track().screens(Application ()).with (tracker);
137+ if (tracker != null ) {
138+ TrackHelper .track().screens(Application ()).with (tracker);
139+ }
116140 }
117141
118142 @ReactMethod
119143 fun trackGoal (goalId : Int ,revenue : Float ) {
120- TrackHelper .track().goal(goalId).revenue(revenue).with (tracker);
144+ if (tracker != null ) {
145+ TrackHelper .track().goal(goalId).revenue(revenue).with (tracker);
146+ }
121147 }
122148
123149 @ReactMethod
124150 fun setVisitorId (visitorId : String ) {
125- tracker?.setVisitorId(visitorId)
151+ if (tracker != null ) {
152+ tracker?.setVisitorId(visitorId);
153+ }
126154 }
127155
128156 @ReactMethod
@@ -134,7 +162,9 @@ class ReactNativeMatomoTrackerModule(reactContext: ReactApplicationContext) :
134162 @ReactMethod
135163 fun setIsOptedOut (isOptedOut : Boolean ) {
136164 Log .e(TAG , " An error occurred: ${isOptedOut} " )
137- tracker?.setOptOut(isOptedOut);
165+ if (tracker != null ) {
166+ tracker?.setOptOut(isOptedOut);
167+ }
138168 }
139169
140170
0 commit comments