Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User ID Not Populating in Matomo #1

Open
Aaron-Gonz opened this issue Aug 26, 2020 · 1 comment
Open

User ID Not Populating in Matomo #1

Aaron-Gonz opened this issue Aug 26, 2020 · 1 comment

Comments

@Aaron-Gonz
Copy link

Aaron-Gonz commented Aug 26, 2020

Looking at the Query String Parameters sent to Matomo from my DokuWiKi instance, it's evident the user_id or UID field is missing. The Matomo database in MySQL shows the user_id as NULL. The User IDs and Visitor logs also do not show a user ID.

I'm running Matomo version 3.14.0 and 2018-04-22b "Greebo" for Doku. My tracking code is as follows:

<!-- Matomo -->
<script type="text/javascript">
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['trackAllContentImpressions']);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//dokuwiki.corp.intranet/analytics/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '2']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript><p><img src="//dokuwiki.corp.intranet/analytics/matomo.php?idsite=2&amp;rec=1" style="border:0;" alt="" /></p></noscript>
<!-- End Matomo Code -->

I've also experimented with adding with using several variations of _paq.push(['setUserId', 'USER_ID_HERE']); within the tracking code, and elsewhere, without any luck.

Any help would be greatly appreciated!

@Aaron-Gonz
Copy link
Author

Was able to get this working by disabling the plugin and placing the tracking code in my template's main.php file so tracking is added to every page.

Placed this in the top PHP section:
$user = $_SERVER['REMOTE_USER'];

Put the tracking code with setUserID snippet, per Matomo dev documentation, above tracker methods within HTML , also in the main.php file. Code:

<!--#################### Matomo ####################-->
<script type="text/javascript">
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['setUserId', '<?php echo $user; ?>']); 
  _paq.push(['trackAllContentImpressions']);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//dokuwiki.corp.intranet/analytics/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '2']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript><p><img src="//dokuwiki.corp.intranet/analytics/matomo.php?idsite=2&amp;rec=1" style="border:0;" alt="" /></p></noscript>
<!--#################### End Matomo Code ####################-->

The plugin doesn't accurately read PHP contained within _paq.push in the tracking code area as it's currently written. Perhaps there's another way of going about this but Doku's documentation shows it's needed to grab the User ID.

Hopefully this saves people all the frustration I experienced trying to get this to work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant