Inconsistent number of events by User ID and total number of events

Hi there,

I am trying to produce a report using Matomo API. The report is supposed to show events by user id. User Id is sent to Matomo as a url parameter. User Id is set as a custom dimension. But sum of events split by user id sometimes is the same as the total number of events, and sometimes it is not.
And this is true in Matomo interface and when I use Matomo API.
Here are screenshots from Matomo interface:

As you can see, the total number of actions by User Id is 230, and this is less than the total number of event actions.

I noticed that I have a lot of actions where the URL is a loopback


And I think that is why the actions are not attributed to a specific user id.
If this is the case, how do I fix this problem? Why is the loopback used and the user id is not assigned?

To get the number of events/actions split by user id I use
https://analytics.bsc.gwu.edu/?module=API&method=Live.getLastVisitsDetails&idSite=7&period=month&date=&format=xml&token_auth=<MY_TOKEN_HERE>&segment=dimension2!=&showColumns=actionDetails&idDimension=2&filter_limit=-1

Please help/suggestion/advise is greatly appreciated.
Thank you.
Alla

Hi @Alla_A_Sapozhnikova sorry for the delay.

Is there any particular reason why you are tracking User ID as a Custom Dimension instead of using the built in User ID feature of Matomo?

It sounds like the local loopback address might be caused by you maybe testing things. Matomo basically tracks what the visitor sees, so if the visitor (Or maybe dev, tester, etc) is hosting the code on a loopback address then that’s what it will track

Since you are not always tracking the User ID Custom Dimension it would be expected that the number of events won’t match because they’re clearly not able to always track the User ID Custom Dimension.

Hope this helps clarify your concerns.

Hi Varun,

You wrote: “It sounds like the local loopback address might be caused by you maybe testing things. Matomo basically tracks what the visitor sees, so if the visitor (Or maybe dev, tester, etc) is hosting the code on a loopback address then that’s what it will track” I am not sure what you mean by this. The way I or anyone else is accessing the site is by logging in to the site and using the site interface. So, I cannot imagine how I or anyone else will cause using the loopback address.

as you can see, in my screenshot in place where Browser shows up we see
image

I do not think a user visiting website can cause this.

what am I missing here?

Thank you.
Alla

Hi @Alla_A_Sapozhnikova
How do you track?
What is your tracking code?

Hi Philippe,

I have a js file myscript.js

<!-- Matomo -->
// tracker methods like "setCustomDimension" should be called before "trackPageView"
//AAS matomo.js load code was commented out. See https://github.com/matomo-org/tag-manager/issues/172.
//AAS Using both Matomo analytics and Tag Manager is not recommended.
//AAS Consider using only Tag manager.

  var _paq = window._paq || [];

  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
 _paq.push(['enableHeartBeatTimer']);
   var _mtm = _mtm || [];
  _mtm.push(['enableDebugMode']);
  (function() {
    var u="https://analytics.bsc.gwu.edu/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '7']);
/*    var d=document,
      g=d.createElement('script'),
      s=d.getElementsByTagName('script')[0];
      g.type='text/javascript';
      g.async=true; g.defer=true;
      g.src=u+'matomo.js';
      s.parentNode.insertBefore(g,s);  */
  })();


<!-- End Matomo Code -->



// AAS Cannot have _ or blanks in Event Action
// AAS Cannot have spaces in Event Name


$(document).on('shiny:connected', function(event) {
// if (event.name === 'input_name') {
//_paq.push(['trackEvent', 'input',
//           'updates', event.name, event.value]);
console.log(event.type);


});
$(document).on("click","#DataTables_Table_0_wrapper > div.dt-buttons > a:nth-child(3) > span",function() {
  console.log( $( this ).text() );
});


$(document).on( "input", "#DataTables_Table_0_filter > label > input[type=search]", function() {
  console.log( $( this ).text() );
});

$(document).on("click","#DataTables_Table_0 > thead > tr:nth-child(2) > td:nth-child(2) > div > input",function() {
  console.log( $( this ).text() );
});


//   $(document).on('change', 'select#my_input.selectized.shiny-bound-input', function(e) {
$(document).on('change', 'select#SITE', function(e) {
      console.log($(e.currentTarget).val());
  //_paq.push(['trackEvent',  'Widget', 'Select_Z_DataXX-XXPickXXSite', $(e.currentTarget).val()[0]]);
  _paq.push(['trackEvent',  'Widget', 'SelectData-PickSite',$(e.currentTarget).val().join('').replace(/\s+/g, '')]);
//'YYYYYYYYYYYYYYYYYYYYYYY']);

    });


$(document).on('change', 'select#RACE', function(e) {
      console.log($(e.currentTarget).val());
_paq.push(['trackEvent',  'Widget', 'SelectData-PickRace',$(e.currentTarget).val().join('').replace(/\s+/g, '')]);
//$(e.currentTarget).val()]);
    });

$(document).on('change', 'select#SUPPRESSED', function(e) {
      console.log($(e.currentTarget).val());
_paq.push(['trackEvent',  'Widget', 'SelectData-PickSuppressed',$(e.currentTarget).val()]);
//$(e.currentTarget).val()]);
    });

$(document).on('change', 'select#RETENTION', function(e) {
      console.log($(e.currentTarget).val());
_paq.push(['trackEvent',  'Widget', 'SelectData-PickRetention',$(e.currentTarget).val()]);
//$(e.currentTarget).val()]);
    });


$(document).on('change', 'select#ONART', function(e) {
      console.log($(e.currentTarget).val());
_paq.push(['trackEvent',  'Widget', 'SelectData-PickOnArt',$(e.currentTarget).val()]);
//$(e.currentTarget).val()]);
    });


$(document).on('change', 'select#SCREENTEST', function(e) {
      console.log($(e.currentTarget).val());
_paq.push(['trackEvent',  'Widget', 'SelectData-PickScreenTest',$(e.currentTarget).val()]);
//$(e.currentTarget).val()]);
    });





 <!-- Matomo Tag Manager -->

var _mtm = _mtm || [];
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true;
g.src='https://analytics.bsc.gwu.edu/js/container_YdAFaJaI.js'; s.parentNode.insertBefore(g,s);

/* g.src='https://analytics.bsc.gwu.edu/js/container_gPbBpSls.js'; s.parentNode.insertBefore(g,s); */

<!-- End Matomo Tag Manager -->

This file is included in my shiny app, like this:

tags$head(tags$style(HTML(
          ".dt-button.buttons-columnVisibility {
              background: #d1c1af !important;
              color: white !important;
              opacity: 1;
              }
          .dt-button.buttons-columnVisibility.active {
              background: #5e6ea8 !important;
              color: white !important;
              opacity: 1;
            }
          .bg-blue {background-color: #0d94d2!important; }
          .bg-green {background-color: #7bc143!important; }
          .bg-orange {background-color: #f58025!important; }
          .bg-purple {background-color: #7c2b83!important; }
          "
    )),

    #tracking JS code
    tags$script(src = "myscript.js"),

     tags$script(HTML(
        'console.log("Now");'
      ))
   ),

I am getting userId as a parameter from the URL in my shiny app server R file

      session$user <- query[['sub']]
I also have a number of Triggers and Tags
![image|690x363](upload://k4yWCxPJfYCLMzHMMZpFxyDmULr.png)

Then I use Custom Dimension

Everything works as expected, except that sometimes there are events that are seemingly using loopback and do not have any users. This causes the problem, because the total number of events bu User id is less than the total number of events.

Thank you very much for all your help.
Alla

Hi,

Looking at your code, I see some problems: You put both MTM and Javascript bootstrap codes. You have to choose one or another one, but not both in the same page.

Secondly, you use MTM, but you push events by JavaScript code. It could be more efficient to track events with MTM.

As written previously by Varun, you should use the user ID as user ID instead of new dimension.

Also, have a look at: