I have a website that is tracked by Matomo, and that website can also be embedded in a custom desktop application. That application has a unique user agent string so it can be tracked if the user is accessing the website embedded or not. One method is adding a custom variable, but that would not be as good as having Matomo registering the custom user agent.
I have searched and found these two forum posts: How do I add a custom user agent so it doesn’t show as “unknown”? - Support & Bugs - Matomo forums Logo for custom Browser/user-agent - Plugins & Platform - Matomo forums
Which manually adds the user agent string. Though they havent written what exactly they did, specifically in regards to Browser.php, and there are no official guides or how to’s of any sort on how to do this. On top of that any modifications can be removed if Matomo is updated.
So then there is this the same issue raised in github where its suggested to write a custom plugin for this. Which is totally out of my league seeing as I am administrating a matomo installation who was asked to add this user agent string, and have no knowledge of extending Matomo at all.
So what to do? It would be nice for an easy way to a custom user agent string, but some more hints on how to add it to the device detector files would be great.
Hope this will at least get noticed because I can see other requests for this goes unnoticed. I would provide more links for the github issue mentioned above and more forum posts here without replies, but I am restricted to just two links currently.
I suggest first you create a new ticket (be able to manually add an own UserAgent in Matomo) in the Matomo Device Detector GitHub:
Then for manual update, I think you won’t have no other choice than keeping the modification and apply then on each update, if you are not able to develop your own plugin…:
Open the file device-detector/regexes/client/browsers.yml if you consider this is a browser, or mobile_apps.yml if you consider this is a mobile app…
Create a new entry in the form of the other ones you could see. Eg:
# Microsoft Edge (newer versions of IE)
- regex: 'Edge[ /](\d+[\.\d]+)'
name: 'Microsoft Edge'
The regex is used to catch your browser, you can find some cheat sheats on the Internet like there:
Simple parenthesis (blabla) are used as capturing group used for example in the version ($1 means the first captured expression), whereas (?:)blabla) are used just for expression grouping, as in any mathematical operation… You can also test your expression at:
Name is your browser name and engine should be, I think, either Gecko (Firefox based) or Edge (new Microsoft based) or WebKit (Safari/Chrome based) or Trident (old Microsoft based).
Then finally add (in UPPERCASE for the 2 chars code) a new entry in
protected static $availableBrowsers = array(
and add your 2 chars code in the good sub-list of: