Following on my previous article on getting Matomo platform up and running, just wanted to show if, and how you can use it to monitor SharePoint sites as well.
For those unfamiliar with SP, it lacks web analytics tools in the recent versions that are worth the name, so in that case, you are depending on an outside solution. Can you use Matomo with SP for your analytics needs? Yes, you can!
Installing Matomo with SharePoint
I will assume that you have a working SharePoint setup already running as well as Matomo running via HTTPS.
There are several ways to get this up and running but I have decided to not use the App Catalog feature (SPFx), but rather connect the "old school" way.
All steps are from the following site: https://blog.lsonline.fr/2019/07/29/setup-matomo-analytics-to-the-classic-sharepoint-site-collections/
STEP 01 - Download the SharePoint PNP PowerShell Module
To make use of the Powershell script that will be used, you will need a PS PNP module.
Depending on your Sharepoint point version (2013, 2016, 2019, Online) you will need the correct version. The problem with PNP is that depending on what SP setup you have, you will need to have the correct PNP version.
You can have multiple versions installed but PS will use the first one it can detect, and if that is not the version you need your connection to that SP farm will fail.
So we can download them all, and keep them in a folder and invoke a specific one depending on the environment. That way you won't have any problems.
Save-Module -Name SharePointPnPPowerShell2013 -Path c:\bin\pnppowershell
Save-Module -Name SharePointPnPPowerShell2016 -Path c:\bin\pnppowershell
Save-Module -Name SharePointPnPPowerShellOnline -Path c:\bin\pnppowershell
So these commands will save each version to the path location that you have configured, c:\bin\pnppowershell
in this example.
STEP 02 - Import PNP module and connect to your SharePoint site
Now that we have the PNP, we are ready to import it in the PowerShell session and connect to our site to execute the Matomo script that will integrate Javascript needed to connect Matomo and your SP site.
import-module C:\bin\pnppowershell\SharePointPnPPowerShell2013\2.24.1803.0\sharepointpnppowershell2013.psd1 -DisableNameChecking
NOTE: At the time of this article, version 2.24.1803 was the final version, so your example might be a bit different at one point in time.
So use the command above to set the path to the appropriate version of PNP and import it.
Once this is done, it is time to connect to the SP site. Use the following command:
Connect-PnPOnline -Url https://yourSPsite.domain
Using Connect-PNPOnline
command line might point in the direction of connecting to SharePoint online, but that is not the case. Considering that we have import the 2013 or 2016 module, this command will still use that PNP and connect to your SP of choice.
STEP 03 - Implement Matomo tracking Javascript using Matomo Powershell script
To make this work, we need to get the PS script from the following location: https://gitlab.lsonline.fr/SharePoint/javascript-customactions/tree/master/SharePoint.MA
Download the SPMA.ps1
file, and go back to Powershell with the loaded PNP model and connection to your site and execute it in the following form:
.\SPMA.ps1 -siteUrl "https://yourSPsite.domain" -trackingUrl https://yourMatomosite.domain/ -trackingSiteId "1"
Change the siteURL
and trackingURL
variables to match your setup by adding your SP site URL as well as your Matomo instance URL.
NOTE: Keep in mind that the trackingSiteId
needs to match yours! If this is your 1st site, then add number 1, if it's a new one just increment the number. Also, you can log into your Matomo instance and check the current status of site numbers
The end result of this script will be similar like this:
Connecting to target site URL: https://yourSPSite.domain
Enabling Matomo Analytics to the target site
Remove old Matomo Analytics Custom Action from target site
Apply PnP schema to target site
Matomo Analytics implementation succeeded
With this, you are done and ready to use your Matomo with your current SP site.