# Make PiwikPro java script code smaller?

**URL:** <https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079>\
**Category:** Data collection and tags\
**Created:** [October 5, 2022, 10:46am UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079 "2022-10-05T10:46:22Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![optipiwik](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/optipiwik/32/806_2.png) [@optipiwik](https://community.piwik.pro/u/optipiwik)\
**Post date:** [October 5, 2022, 10:46am UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/1 "2022-10-05T10:46:22Z")

</div>

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?

Thanks for the help!

Best Wishes,  
Alwin

---

<div class="post-metadata">

**Author:** ![Piotrek](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/piotrek/32/160_2.png) [@Piotrek](https://community.piwik.pro/u/Piotrek)\
**Post date:** [October 6, 2022, 9:49am UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/2 "2022-10-06T09:49:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![optipiwik](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/optipiwik/32/806_2.png) [@optipiwik](https://community.piwik.pro/u/optipiwik)\
**Post date:** [October 7, 2022, 10:23am UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/3 "2022-10-07T10:23:36Z")

</div>

Thank you for your help Piotrek!

Trying to understand how PiwikPro code works:

I see 3 connections in my GTmetrix report:

1. [https://option-webdesign.containers.piwik.pro/0ac0d197-f254-48d9-9ffa-67ba0e222f8d.js](https://option-webdesign.containers.piwik.pro/0ac0d197-f254-48d9-9ffa-67ba0e222f8d.js)  
(60,6 KB compressed / 224KB uncompressed)

2. [https://option-webdesign.containers.piwik.pro/ppms.js](https://option-webdesign.containers.piwik.pro/ppms.js)  
(26,6 KB / 79,3KB)

3. [https://option-webdesign.piwik.pro/ppms.php?action\_name=Experiment%20Krewerd%20|%20Aardbevingsdorp%20neemt%20heft%20in%20eigen%20handen&idsite=0ac0d197-f254-48d9-9ffa-67ba0e222f8d&rec=1&r=691412&h=2&m=37&s=31&url=https%3A%2F%2Fwww.experimentkrewerd.nl%2F&\_idts=1665135452&\_idvc=1&\_idn=1&\_viewts=1665135452&send\_image=0&ts\_n=jstc\_tm&ts\_v=2.8.3&cookie=1&res=1367x864&gt\_ms=22&pv\_id=E3PQEy](https://option-webdesign.piwik.pro/ppms.php?action_name=Experiment%20Krewerd%20%7C%20Aardbevingsdorp%20neemt%20heft%20in%20eigen%20handen&idsite=0ac0d197-f254-48d9-9ffa-67ba0e222f8d&rec=1&r=691412&h=2&m=37&s=31&url=https%3A%2F%2Fwww.experimentkrewerd.nl%2F&_idts=1665135452&_idvc=1&_idn=1&_viewts=1665135452&send_image=0&ts_n=jstc_tm&ts_v=2.8.3&cookie=1&res=1367x864&gt_ms=22&pv_id=E3PQEy)

(0 KB/ 0KB)

Now some questions:

- Do I need all three of them? What is the 3th one with 0KB? Seems like an empty URL?
- Will the code be smaller if I add the code manually and do not use the WordPress plugin?
- Can I deactivate the Tag Manager to make the code smaller?

Thanks for your help 🙂  
Alwin

---

<div class="post-metadata">

**Author:** ![Admin](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Admin](https://community.piwik.pro/u/Admin)\
**Post date:** [October 11, 2022, 4:07pm UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/4 "2022-10-11T16:07:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![optipiwik](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/optipiwik/32/806_2.png) [@optipiwik](https://community.piwik.pro/u/optipiwik)\
**Post date:** [October 12, 2022, 2:48pm UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/5 "2022-10-12T14:48:32Z")

</div>

Thank you for your help kuba!

---

<div class="post-metadata">

**Author:** ![optipiwik](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/optipiwik/32/806_2.png) [@optipiwik](https://community.piwik.pro/u/optipiwik)\
**Post date:** [April 8, 2023, 8:31am UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/6 "2023-04-08T08:31:22Z")

</div>

Hello kuba,

On one of my sites I used this code to exlude using the large tag manager code:

```auto
<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?

Thanks for your help!  
Alwin

---

<div class="post-metadata">

**Author:** ![rmastop](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/rmastop/32/29_2.png) [@rmastop](https://community.piwik.pro/u/rmastop)\
**Post date:** [April 8, 2023, 9:41am UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/7 "2023-04-08T09:41:19Z")

</div>

Hi @optipiwik,

By default this code will calculate the Real User Monitoring on 10 percent of the requests.

If you need more precise RUM details, you can alter it by using  
`setTimingDataSamplingOnPageLoad`

> **[API](https://developers.piwik.pro/en/latest/data_collection/web/javascript_tracking_client/api.html#setTimingDataSamplingOnPageLoad)**
>
> The following API allows the user to: track page views, track visits on multiple domains and subdomains, track e-commerce events (successful orders, cart changes, product and category views), track...

Kind regards,  
Richard

---

<div class="post-metadata">

**Author:** ![optipiwik](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/optipiwik/32/806_2.png) [@optipiwik](https://community.piwik.pro/u/optipiwik)\
**Post date:** [April 9, 2023, 6:15pm UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/8 "2023-04-09T18:15:53Z")

</div>

Hell rmastop,

Thank you for the link; I have added the code now 🙂  
Alwin

---

<div class="post-metadata">

**Author:** ![optipiwik](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/optipiwik/32/806_2.png) [@optipiwik](https://community.piwik.pro/u/optipiwik)\
**Post date:** [April 10, 2023, 7:32am UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/9 "2023-04-10T07:32:49Z")

</div>

The code is not working, still around 10% of the requests is used for RUM reporting. I have added the exra line of code like this:

```auto
	<script type="text/javascript">
    var _paq = _paq || [];
    _paq.push(["trackPageView"]);
    _paq.push(["enableLinkTracking"]);
    (function() {
        var u = "xxxxxxxxxxxxxxxxxxxx.piwik.pro/";
        _paq.push(["setTrackerUrl", u + "ppms.php"]);
        _paq.push(["setSiteId", "xxxxxxxxxxxxxxxxxxxxxxxx"]);
        _paq.push(["setTimingDataSamplingOnPageLoad", 100]);
        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>

```

---

<div class="post-metadata">

**Author:** ![mbaersch](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mbaersch/32/35_2.png) [@mbaersch](https://community.piwik.pro/u/mbaersch)\
**Post date:** [April 10, 2023, 2:52pm UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/10 "2023-04-10T14:52:09Z")

</div>

Hi,

move the command up before the pageview gets pushed and it should work as expected.

best,  
Markus

---

<div class="post-metadata">

**Author:** ![optipiwik](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/optipiwik/32/806_2.png) [@optipiwik](https://community.piwik.pro/u/optipiwik)\
**Post date:** [April 11, 2023, 3:56pm UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/11 "2023-04-11T15:56:59Z")

</div>

Hello mbaersch,

So you mean like this?

```auto
<script type="text/javascript">
    var _paq = _paq || [];
    _paq.push(["setTimingDataSamplingOnPageLoad", 100]);
    _paq.push(["trackPageView"]);
    _paq.push(["enableLinkTracking"]);
    (function() {
        var u = "xxxxxxxxxxxxxxxxxxxx.piwik.pro/";
        _paq.push(["setTrackerUrl", u + "ppms.php"]);
        _paq.push(["setSiteId", "xxxxxxxxxxxxxxxxxxxxxxxx"]);
        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>

```

---

<div class="post-metadata">

**Author:** ![mbaersch](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mbaersch/32/35_2.png) [@mbaersch](https://community.piwik.pro/u/mbaersch)\
**Post date:** [April 11, 2023, 4:40pm UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/12 "2023-04-11T16:40:24Z")

</div>

Exactly. Why are you asking, is it not working as expected?

---

<div class="post-metadata">

**Author:** ![optipiwik](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/optipiwik/32/806_2.png) [@optipiwik](https://community.piwik.pro/u/optipiwik)\
**Post date:** [April 11, 2023, 5:34pm UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/13 "2023-04-11T17:34:25Z")

</div>

Just asking to be sure 🙂

I just checked and it seems to be working now!

---

<div class="post-metadata">

**Author:** ![optipiwik](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/optipiwik/32/806_2.png) [@optipiwik](https://community.piwik.pro/u/optipiwik)\
**Post date:** [April 14, 2023, 11:59am UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/14 "2023-04-14T11:59:38Z")

</div>

One more question about adding this line of code to the javascript snippet:

```auto
 _paq.push(["setTimingDataSamplingOnPageLoad", 100]);

```

- Does this line create an extra request for mydomain/piwik.pro/ppms.php? Because that is what I think to see in my GTmetrix waterfall.

Thanks,  
Alwin

---

<div class="post-metadata">

**Author:** ![Admin](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Admin](https://community.piwik.pro/u/Admin)\
**Post date:** [April 14, 2023, 3:26pm UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/15 "2023-04-14T15:26:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![optipiwik](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/optipiwik/32/806_2.png) [@optipiwik](https://community.piwik.pro/u/optipiwik)\
**Post date:** [April 14, 2023, 4:04pm UTC](https://community.piwik.pro/t/make-piwikpro-java-script-code-smaller/1079/16 "2023-04-14T16:04:33Z")

</div>

I get it; thanks for confirming!
