donni106 / matomo-tracker-react-native

Stand alone library for using Matomo tracking in React Native and Expo projects.
MIT License
47 stars 15 forks source link

Tracking device type #13

Open BatDroid opened 1 year ago

BatDroid commented 1 year ago

Is your feature request related to a problem? Please describe. I wanted to know if there can be a way to define the device type. there is a section in dashboard for it which everyone will be marked unknown eventually. it could be good if we could implement it with expo-device package and at least know whether the users are with phone or tablets

donni106 commented 1 year ago

Hi @BatDroid, did you take a look at the possible options from Matomo at https://developer.matomo.org/api-reference/tracking-api#optional-user-info? Maybe it is something you can transmit with the ua or uadata params? image

BatDroid commented 1 year ago

no, sorry, I'm new at Matomo, and I have millions of questions now. thanks to your fast response & guide, I think I could reach into these, which seems to be part of the uadata:

https://github.com/matomo-org/matomo-sdk-ios/blob/develop/MatomoTracker/Device.swift#L3

https://github.com/matomo-org/matomo-sdk-android/blob/master/tracker/src/main/java/org/matomo/sdk/tools/DeviceHelper.java#L49

if you think I'm correct then feel free to close the ticket

donni106 commented 1 year ago

I don't know exactly what you mean. How did you plan your next steps?

BatDroid commented 1 year ago

@donni106 I want to attach more info about the device to my request, so that I'll be able to have an overview of device types, OS, etc. What I don't know is that I don't know how the format of my body should be. as an example should be like:

{
uadata: {
device : {
type: "smartphone",
...
}
}
}

or something else ... still researching on this.

BatDroid commented 1 year ago

just to be more clear. I don't see any statistics on how many users are using iPhone 12. how many are on what version of android and how many users are on smartphone and how many on tablet. I made the uadata like this but only the model is being saved in dashboard, and it only get saved when I apply it like Json.stringify. here is an example:

import * as Device from 'expo-device';
{
uid: userID,
uadata: JSON.stringify({
model: Device.deviceName,
brand: Device.brand
type: Device.DeviceType.Phone
})
}
BatDroid commented 1 year ago

I tried various combinations of data but here is all the data which I was able to let the Matomo detect. I wish I was able to make track more records. like the device type(table, smartphone), device brand (for android devices), etc

{
    uid: userId,
    res: `${Math.trunc(Dimensions.get('window').width)}x${Math.trunc(
      Dimensions.get('window').height,
    )}` as unknown as number,
    uadata: JSON.stringify({
      model: Device.deviceName,
      platform: `${Device.osName}`,
      platformVersion: `${Device.osVersion}`,
    }) as unknown as object,
  }
Screen Shot 1401-09-28 at 13 25 22 Screen Shot 1401-09-28 at 13 24 37
donni106 commented 1 year ago

I understand your issue, thanks. I think this is something we need to ask Matomo directly. I do not know their system parameters. The way you send the informations with this library is totally correct. Now we need to know, which parameters uadata can receive, right?

I found some example in the API reference at https://developer.matomo.org/api-reference/tracking-api#example-tracking-request

image

Here they transmit the os version as custom variable with _cvar. Custom variables can be anything but maybe they also use some default ones for device brand and type.

I have created an issue at the Matomo GitHub asking for support on this.

donni106 commented 1 year ago

So as they said:

The values send with uadata then are checked with device detector. So it's not possible to send through random values, as they might get ignored then.

BatDroid commented 1 year ago

@donni106 thank you so much for following up. so do you have any idea what can be done for it?

donni106 commented 1 year ago

What react native and expo versions is your app running? Do you have new insights with the latest versions? In my case, I can see more detailed information:

type brand model screen
image image image image

It seems that the point of logging is important. On app start, there are informations missing, but when tracking a screen, the details are present (at least on iOS, on Android it seems to be more often undefined):

app start screen
image image

Can you see some behavior like this in your case? As we need to rely on the underlying detection system ("device detector" as they said) and cannot pass information on our own, I cannot think of anything specific for us to do.

angelxmoreno commented 1 year ago

a few points:

  1. relying on uadata feels very wrong for tracking mobile apps since Matomo's device detector works off of the UserAgent
  2. maybe we need a Matomo plugin that acknowledges react native device params
  3. how does the react-native-matomo handle this if at all?
  4. @donni106 what params are you sending to get the model and screen values you posted?
donni106 commented 1 year ago
  1. @donni106 what params are you sending to get the model and screen values you posted?

this is what we do:

import Constants from 'expo-constants';
import * as Localization from 'expo-localization';

...
const ua = await Constants.getWebViewUserAgentAsync();
...
{
  lang: Localization.locale,
  res: `${device.width}x${device.height}`,
  ua
}
...

Expo Constants: https://docs.expo.dev/versions/latest/sdk/constants

angelxmoreno commented 1 year ago

once we merge #23 I'd like to get started on #24 and incorporate

{
  lang: Localization.locale,
  res: `${device.width}x${device.height}`,
  ua: await Constants.getWebViewUserAgentAsync(),
  _id: Constants.sessionId,
}
angelxmoreno commented 1 year ago

@BatDroid @donni106 should we consider this issue as closed ?

donni106 commented 11 months ago

@BatDroid @donni106 should we consider this issue as closed ?

I still need to tackle the before mentioned PR and issue!

donni106 commented 11 months ago

23 is merged, you can go on and I look forward to release a 0.3.3 after the changes.