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

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