Using Matomo (Piwik) with SharePoint can be very straight forward. There is no need to install any extension for SharePoint or any .wsp solution. All you need is Piwik installation and some lines of JavaScript in a file and a bit of PnP PowerShell.
Piwik offers you a default JavaScript snippet that allows you to track a user on your web site. The default code will somehow look like this:
var _paq = _paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(['enableLinkTracking']); _paq.push(['trackPageView']); (function () { var u = "//piwikserver.domain.de/"; _paq.push(['setTrackerUrl', u + 'piwik.php']); _paq.push(['setSiteId', '1']); 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); })();<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>
As soon as you save this JavaScript code in file, you can get started with SharePoint tracking with the following steps:
- Upload this file to your SharePoint Root Site Collection and place it in the Style Library (Why? Regularly I use this lib as a on-premises CDN)
- Make sure the file is accessible
- Create a Script Link in the Site Collection you want to track.
For step 3 You can use the following PowerShell code to add a script link to your site collection:
Connect-PnPOnline -CurrentCredentials -Url https://mywebapp.domain.de Add-PnPJavaScriptLink -Name SpPiwik -Url "/Style Library/SpPiwik.js" -Sequence 900 -Scope Site
With this setting you can track a user and gain basic insights about his flow through your website. The data you are gaining by now is very basic and there are some SharePoint only specialties: