Skip to content

Commit 8816ceb

Browse files
fixed the swap value track in custom dimension
1 parent 4fe37ad commit 8816ceb

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

android/src/main/java/com/logicwind/reactnativematomotracker/ReactNativeMatomoTrackerModule.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,17 @@ class ReactNativeMatomoTrackerModule(reactContext: ReactApplicationContext) :
301301
if (dimensions.size() > 0) {
302302
for (i in 0 until dimensions.size()) {
303303
val dimension = dimensions.getMap(i)
304-
305304
val key = dimension?.getString("key")
306305
val value = dimension?.getString("value")
307306
if (key != null && value != null) {
308-
TrackHelper.track().screen("/media").dimension((dimensions.size()-i),value).with(tracker)
307+
308+
val id = key.toIntOrNull()
309+
if (id != null) {
310+
TrackHelper.track().screen("/media").dimension(id,value).with(tracker)
309311
trackDispatch();
312+
} else {
313+
println("Key could not be converted to an Int")
314+
}
310315
}
311316
}
312317
}

ios/ReactNativeMatomoTracker.swift

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,28 +177,20 @@ class ReactNativeMatomoTracker: NSObject {
177177
) {
178178
if(!siteId.isEmpty && matomoTracker != nil)
179179
{
180-
181180
if(mediaStatus=="0"){
182-
183181
matomoTracker?.track(eventWithCategory:mediaType, action:"play",name: mediaTitle)
184-
185182
}
186-
187183
if(mediaStatus==mediaLength){
188184
matomoTracker?.track(eventWithCategory:mediaType, action:"stop",name: mediaTitle)
189-
190185
}
191-
192-
186+
193187
var uid = ""
194-
195188
if var userId = matomoTracker?.userId {
196189
uid = userId
197190
} else {
198191
uid = ""
199192
}
200193

201-
202194
let baseUrl = baseURL
203195
var query = "idsite=\(encodeParameter(value: siteId))" +
204196
"&rec=1" +
@@ -213,12 +205,15 @@ class ReactNativeMatomoTracker: NSObject {
213205
"&uid=\(encodeParameter(value: uid))"
214206

215207
if(!dimensions.isEmpty){
216-
var index = 1 ;
208+
217209
for dimension in dimensions {
218210
if let key = dimension["key"] as? String, let value = dimension["value"] as? String {
219-
matomoTracker?.setDimension(value, forIndex: index)
220-
matomoTracker?.dispatch()
221-
index = index + 1
211+
if let id = Int(key) {
212+
matomoTracker?.setDimension(value, forIndex: id)
213+
matomoTracker?.dispatch()
214+
} else {
215+
print("Key could not be converted to an Int")
216+
}
222217
}
223218
}
224219
}

0 commit comments

Comments
 (0)