Tracking FE microservices separately

Hiii Matomo team ,
You are doing great job. I am integrating matomo in our system . our Website FE arch is divided into 2 microservices . suppose abc, def.
you can take it as
https://www.example.com/abc,
https://www.example.com/def,
And I want to create 2 measurables for tracking different part separately.
Is it possible to do so ??

Yes, it is possible.
You could event track the same website in 2 different measurables :wink:

1 Like

Hii …

Thanks for the answer !
I have created 2 measurables with 2 different idSite numbers for different microservice .
But the issue is when i am tracking . both are getting tracked under 1 measurable .
And
If possible what is the correct way to write URL’s in the measurables ??
Regards
Dipanshu Negi

There’s an option in Matomo to do this and it’s documented here https://matomo.org/faq/how-to/faq_21077/

1 Like

How do you track?
How do your microservices work (together?)

1 Like

Thanks @je_mi_bi great help for measurable urls .

hey philippe,
No they work separately .

let us take an example .
for your info. We have K8 arch and IntrAnet.

mywebsite = www.myproduct.com website is same . 2 urls i could use in this text . :smile:

talking about FE only .

mywebsite/cars
/cars ingress is destined for cars-ui-ms microservice .

mywebsite/bikes
/ bike ingress is for 1 bikes-ui-ms microservice .

for your information we are using kubernetics architecture for deployment of bitnami matomo helm chart .

As i have read … 1 measurable is for 1 website only .
but but what i have done is .

I created 2 measurables
1 .
name : CAR
URL : “mywebsite/cars”

2 .
name : BIKES
URL : “mywebsite/bikes”

and thereby added the separate tracking codes into 2 ms seroerately .

each being successfully tracked …
But everything under CARS. BIKES pages are also tracked under CARS

Regards
Dipanshu Negi

:+1:

I think your tracking code may have mistake…
Can you share the tracking code you use?
In order to put some code, don’t forget to start with: ``` on a blank line and terminate also with ``` also on a blank line…

1 Like

So when you open the Matomo profile for mywebsite/cars you see data for mywebsite/bikes as well correct? What about the link I shared https://matomo.org/faq/how-to/faq_21077/n have you tried ? I do not believe this is retroactive by the way. Setting-up a custom segment might help here.

thanks @heurteph-ei

this is the code : -

matomo.js

for ms 1

export function setMatomoCode(user) {
  let _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['setUserId', user]);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    let u = window.location.protocol + '//' + window.location.hostname + '/matomo/';
    _paq.push(['setTrackerUrl', u + 'matomo.php']);
    _paq.push(['setSiteId', '7']);

    let d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
    g.async = true; g.src = u + 'matomo.js'; s.parentNode.insertBefore(g, s);
  })();
}

for ms 2

export function setMatomoCode(user) {
  let _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['setUserId', user]);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    let u = window.location.protocol + '//' + window.location.hostname + '/matomo/';
    _paq.push(['setTrackerUrl', u + 'matomo.php']);
    _paq.push(['setSiteId', '4']);
    let d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
    g.async = true; g.src = u + 'matomo.js'; s.parentNode.insertBefore(g, s);
  })();
}

Different id site

Thank you

Hi @Dipanshu_Negi
Are you sure both codes are not in the same page at the same time? eg. in case of single page application, the URL changes, but the page javaScript code (and HTML core) is the same.
Are you sure the code in the 2nd MS is called (and not the 1st one instead of the 2nd one?)