Skip to content

Commit 4fe37ad

Browse files
Fixed the custom dimension not track issue
1 parent 8f3562f commit 4fe37ad

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,19 +301,12 @@ class ReactNativeMatomoTrackerModule(reactContext: ReactApplicationContext) :
301301
if (dimensions.size() > 0) {
302302
for (i in 0 until dimensions.size()) {
303303
val dimension = dimensions.getMap(i)
304+
304305
val key = dimension?.getString("key")
305306
val value = dimension?.getString("value")
306-
307307
if (key != null && value != null) {
308-
try {
309-
val jsonObject = JSONObject(value)
310-
val jsonValueString = jsonObject.toString()
311-
TrackHelper.track().screen("/media").dimension(i+1,value).with(tracker)
312-
trackDispatch()
313-
} catch (e: Exception) {
314-
TrackHelper.track().screen("/media").dimension(i+1,value).with(tracker)
315-
trackDispatch()
316-
}
308+
TrackHelper.track().screen("/media").dimension((dimensions.size()-i),value).with(tracker)
309+
trackDispatch();
317310
}
318311
}
319312
}

ios/ReactNativeMatomoTracker.swift

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ class ReactNativeMatomoTracker: NSObject {
181181
if(mediaStatus=="0"){
182182

183183
matomoTracker?.track(eventWithCategory:mediaType, action:"play",name: mediaTitle)
184-
matomoTracker?.dispatch()
184+
185185
}
186186

187187
if(mediaStatus==mediaLength){
188188
matomoTracker?.track(eventWithCategory:mediaType, action:"stop",name: mediaTitle)
189-
matomoTracker?.dispatch()
189+
190190
}
191191

192192

@@ -213,22 +213,16 @@ class ReactNativeMatomoTracker: NSObject {
213213
"&uid=\(encodeParameter(value: uid))"
214214

215215
if(!dimensions.isEmpty){
216-
216+
var index = 1 ;
217217
for dimension in dimensions {
218218
if let key = dimension["key"] as? String, let value = dimension["value"] as? String {
219-
// Attempt to parse the JSON value
220-
if let data = value.data(using: .utf8),
221-
let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
222-
// Convert jsonObject to a string or handle as needed
223-
let jsonValueString = jsonObject.map { "\($0.key)=\($0.value)" }.joined(separator: ",")
224-
query += "&\(key)=\(encodeParameter(value: jsonValueString))"
225-
} else {
226-
query += "&\(key)=\(encodeParameter(value: value))"
227-
}
219+
matomoTracker?.setDimension(value, forIndex: index)
220+
matomoTracker?.dispatch()
221+
index = index + 1
228222
}
229223
}
230-
231224
}
225+
232226

233227
// if(!customVariable.isEmpty){
234228
//
@@ -283,6 +277,7 @@ class ReactNativeMatomoTracker: NSObject {
283277
}
284278
task.resume()
285279
}
280+
matomoTracker?.dispatch()
286281
}
287282
}
288283

0 commit comments

Comments
 (0)