I've troubleshooted this for a few days now and can't figure out the problem.
As a customization, if I add:
"javascript": "console.log('this is a test');",
...in /public_html/config/local-production.json and systemctl restart peertube, as expected, it prints _this is a test_ in the console.
However, if I add instead:
var _paq=_paq||[];_paq.push(['setDocumentTitle',document.domain+'/'+document.title]);_paq.push(['setCookieDomain','*.mysite.com']);_paq.push(['setDomains',['*.mysite.com','*.video.mysite.com']]);_paq.push(['enableCrossDomainLinking']);_paq.push(['trackPageView']);_paq.push(['enableLinkTracking']);(function(){var u='https://mysite.com/matomo/';_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)})();
...the page view is not recorded in Matomo. (As a side note, mysite.com/matomo/ is on a different server but that shouldn't matter.)
Now, if I add:
<script type="text/javascript" src="/client/en_US/matomo.js"></script>
...right before the </body> tag in /versions/peertube-v1.0.1/client/dist/en_US/index.html and include the above Javascript in the matomo.js file, the page view is recorded in Matomo correctly.
So I'm not sure this enhancement is working properly.
Additionally, per Matomo's JavaScript Tracking Client guide:
Manually trigger events
By default, Matomo tracks page views when the JavaScript tracking code loads and executes on each page view.
However, on modern web applications, user interactions do not necessarily involve loading a new page. For example, when users click on a JavaScript link, or when they click on a tab (which triggers a JS event), or when they interact with elements of the user interface, you can still track these interactions with Matomo.
To track any user interaction or click with Matomo, you can manually call the JavaScript function
trackEvent(). For example, if you wanted to track a click on a JavaScript menu, you could write:
<a href="#" onclick="_paq.push(['trackEvent', 'Menu', 'Freedom']);">Freedom page</a>
Considering how PeerTube works, each link would require an onclick tag to record properly. So this enhancement doesn't work for Matomo.
Will users have to opt-in for this, or will it be enabled by default?
Implemented in a plugin: https://framagit.org/framasoft/peertube/official-plugins/tree/master/peertube-plugin-matomo
Thanks for implementing the plugin. I feel silly but I'm a bit confused how to install this and the readme does not say. Just installing it from PeerTube's /admin/plugins/list-installed?pluginType=1 menu didn't seem to work with my settings as:
Matomo Url: https://mysite.com/matomo/index.php (edit: also tried https://mysite.com/matomo/piwik.php)
Site id: 1
So then I searched how to install plugins and found https://docs.joinpeertube.org/#/contribute-plugins which states:
Then, you can install or reinstall your local plugin/theme by running:
$ node ./dist/server/tools/peertube.js plugins install --path /your/absolute/plugin-or-theme/path
However, I don't think this is correct as there is no ./dist/server/tools/peertube.js. (You might want to update.) I did find ./dist/scripts/plugin/install.js so I manually added a directory, FTPed the plugin, and used that:
node ./dist/scripts/plugin/install.js "--plugin-path" "/home/peertube/public_html/versions/peertube-v1.4.1/plugins/peertube-plugin-matomo"
...which gave me:
[mysite.com:443] 2019-10-09 13:41:38.861 info: Installing plugin /home/peertube/public_html/versions/peertube-v1.4.1/plugins/peertube-plugin-matomo.
[mysite.com:443] 2019-10-09 13:41:40.419 info: Successful installation of plugin /home/peertube/public_html/versions/peertube-v1.4.1/plugins/peertube-plugin-matomo.
[mysite.com:443] 2019-10-09 13:41:40.422 info: Registering plugin or theme peertube-plugin-matomo.
[mysite.com:443] 2019-10-09 13:41:40.427 info: Add plugin peertube-plugin-matomo CSS to global file.
[mysite.com:443] 2019-10-09 13:41:40.428 info: Cleaning HTML cache.
However, even doing systemctl restart peertube did not seem to get the plugin to work. Can you suggest what I'm doing wrong please? Thanks
I found the directions to install plugins at https://docs.joinpeertube.org/#/maintain-tools?id=plugin-installuninstall but this plugin still does not work (and I do not see any references to matomo in the HTML/JS page sources). I also updated the Matomo Url to https://mysite.com/matomo/.
@c-prompt Please open a dedicated issue on https://framagit.org/framasoft/peertube/official-plugins/issues so we can continue this discussion
@c-prompt Please open a dedicated issue on https://framagit.org/framasoft/peertube/official-plugins/issues so we can continue this discussion
Most helpful comment
Implemented in a plugin: https://framagit.org/framasoft/peertube/official-plugins/tree/master/peertube-plugin-matomo