Skip to content

Commit 9386e39

Browse files
authored
Merge pull request #10 from logicwind/dev
Fixed the custom dimension not track issue
2 parents d35be4e + 80f65f3 commit 9386e39

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,14 @@ trackMediaEvent function use to monitor user interactions with media content, su
286286
| mediaHeight | The resolution height of the media in pixels. Only recommended being set for videos. |
287287
| mediaFullScreen| Should be 0 or 1 and defines whether the media is currently viewed in full screen. Only recommended being set for videos. |
288288
| mediaSE | An optional comma separated list of which positions within a media a user has played. For example if the user has viewed position 5s, 10s, 15s and 35s, then you would need to send 5,10,15,35. We recommend to round to the next 5 seconds and not send a value for each second. Internally, Matomo may round to the next 15 or 30 seconds. For performance optimisation we recommend not sending the same position twice. Meaning if you have sent ma_se=10 there is no need to send later ma_se=10,20 but instead only ma_se=20. |
289-
| dimensions| Dimension contains a key and a value, and where the key is a custom dimension key created on the Matomo dashboard and the value should be a string, you'll need to ensure that the dimensions array is processed correctly. [create custom dimension](https://matomo.org/faq/reporting-tools/create-track-and-manage-custom-dimensions/)
289+
| dimensions| Dimension contains a key and a value, and where the key is a custom dimension id created on the Matomo dashboard and the value should be a string, you'll need to ensure that the dimensions array is processed correctly. [create custom dimension](https://matomo.org/faq/reporting-tools/create-track-and-manage-custom-dimensions/)
290290

291291

292292
#### Examples
293293

294294
```js
295295

296-
trackMediaEvent({siteId:"siteid",mediaId:"unique id",mediaTitle:"video media play track",playerName:"test 08",mediaType:MediaType.VIDEO,mediaResource:"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",mediaStatus:"100",mediaLength:"100",mediaFullScreen:"1",mediaHeight:"720",mediaWidth:"1080",mediaProgress:"100", dimensions:[{key:"dimension1",value: "cf7fad2e-fae4-4c49-9924-ad9a2a7c50de"}]});
296+
trackMediaEvent({siteId:"siteid",mediaId:"unique id",mediaTitle:"video media play track",playerName:"test 08",mediaType:MediaType.VIDEO,mediaResource:"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",mediaStatus:"100",mediaLength:"100",mediaFullScreen:"1",mediaHeight:"720",mediaWidth:"1080",mediaProgress:"100", dimensions:[{key:"1",value: "cf7fad2e-fae4-4c49-9924-ad9a2a7c50de"}]});
297297

298298
```
299299

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,16 +303,14 @@ class ReactNativeMatomoTrackerModule(reactContext: ReactApplicationContext) :
303303
val dimension = dimensions.getMap(i)
304304
val key = dimension?.getString("key")
305305
val value = dimension?.getString("value")
306-
307306
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()
307+
308+
val id = key.toIntOrNull()
309+
if (id != null) {
310+
TrackHelper.track().screen("/media").dimension(id,value).with(tracker)
311+
trackDispatch();
312+
} else {
313+
println("Key could not be converted to an Int")
316314
}
317315
}
318316
}

ios/ReactNativeMatomoTracker.swift

Lines changed: 8 additions & 18 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-
matomoTracker?.dispatch()
185182
}
186-
187183
if(mediaStatus==mediaLength){
188184
matomoTracker?.track(eventWithCategory:mediaType, action:"stop",name: mediaTitle)
189-
matomoTracker?.dispatch()
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,22 +205,19 @@ class ReactNativeMatomoTracker: NSObject {
213205
"&uid=\(encodeParameter(value: uid))"
214206

215207
if(!dimensions.isEmpty){
216-
208+
217209
for dimension in dimensions {
218210
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))"
211+
if let id = Int(key) {
212+
matomoTracker?.setDimension(value, forIndex: id)
213+
matomoTracker?.dispatch()
225214
} else {
226-
query += "&\(key)=\(encodeParameter(value: value))"
215+
print("Key could not be converted to an Int")
227216
}
228217
}
229218
}
230-
231219
}
220+
232221

233222
// if(!customVariable.isEmpty){
234223
//
@@ -283,6 +272,7 @@ class ReactNativeMatomoTracker: NSObject {
283272
}
284273
task.resume()
285274
}
275+
matomoTracker?.dispatch()
286276
}
287277
}
288278

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@logicwind/react-native-matomo-tracker",
3-
"version": "0.3.5",
3+
"version": "0.3.6",
44
"description": "React-native plugin for matomo analytics",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

0 commit comments

Comments
 (0)