To include Matomo JavaScript Tracking code in your SharePoint server (intranet) Sites, please follow the instructions below. The solution involves adding the Matomo JavaScript tracking code to your Master pages in SharePoint.

1) Get the tracking code for your website

  • log in to Matomo (Piwik) with your admin or Super User account
  • click on your username in the top right menu, and click Settings to access the administration area
  • click on Tracking Code in the left menu
  • Copy the Tracking code

The tracking code looks as follows:

<!-- Matomo -->
<script type="text/javascript">
  var _paq = window._paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//{$PIWIK_URL}/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', {$IDSITE}]);
    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+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

In your tracking code, {$PIWIK_URL} would be replaced by your Matomo URL and {$IDSITE} would be replaced by the idsite of the website you are tracking in Matomo.

2) Add this Tracking code to SharePoint master page.

  • Edit your master page in ‘Advanced mode’ with SharePoint designer 2013
  • and paste/insert the Matomo Tracking code just before </head> tag.
  • Save-Check-in-publish/Approve the master page.

3) Check your Visitors data in Matomo

Under Visitors > Visits Log, select “Today” in the calendar, you can now see your visitors and interactions tracked in real-time.

If you are using SharePoint Online instead, please check our other FAQ: Matomo SharePoint Online