I am a new PiwikPro Core plan user. I have installed the Piwik java script code on my WordPress websites with the PiwikPro WordPress plugin.
I noticed that the java script code installed by PiwkPro is a lot bigger than the code used by Google Analytics. The Piwik code is around 86KB and the GA code is just around 20KB. Uncompressed the Piwik code is more than 300KB.
Is there any way to make the code smaller in size? For example by disabling options in the Data collection settings?
Hello @optipiwik, which .js file did you look at when analyzing size?
By default our container code is also responsible for loading Consent Manager and Tag Manager. That’s the file that contains the ID of your site or app from Piwik PRO (example: “74bda40d-ed9d-40c8-ac93-99d58da82a95.js”).
If considering just the main Analytics library (our JavaScript Tracking Client called ppms.js or ppas.js) loaded standalone or inside of the Tag Manager, the code is indeed a bit bigger than GA’s analytics library, but that doesn’t affect website’s overall performance. You can verify that by running tools like Lighthouse.
However, we understand that optimizing sizes of assets like JS libraries is important. Because of that, we are planning to reduce the size of our Analytics library in the near future. I’ll update this thread once we can share more details.
You can get rid of the first one, but it means basically disabling the Tag Manager module. Requires also some custom code to be added. No. 3 is the actual request that transfers data to the analytics backend, so it’s a must have. Its size is 0 because all the data is passed via GET params or headers.
On one of my sites I used this code to exlude using the large tag manager code:
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function() {
var u = "https://your-account-name.piwik.pro/";
_paq.push(["setTrackerUrl", u + "ppms.php"]);
_paq.push(["setSiteId", "XXX-XXX-XXX-XXX-XXX"]);
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 + "ppms.js";
s.parentNode.insertBefore(g, s);
})();
</script>
Now everything seems to be working fine on this site with PiwikPro (I don’t use tag manager options or consent manager options on this site) and the PiwikPro code is ow indeed much smaller.
However, one thing I notice is that Real User Monitoring is not working anymore when using the above code? Is that correct?
Can I add some lines of code at the above code to make RUM work again?
Hi. Yes. The thing is that we can’t really delay the page view event just for the sake of gathering page performance data at the same time. Because of that, we implemented it via a separate ping event.