How to disable some functions in Matomo.js

Hello, is there any correct way to disable two functions that are located in Matomo.js file (in order to prevent them being called from front-end)

The functions:

These functions allow a front-end user to modify the cookie expiration value.
I want to prevent this, so I need to disable the functions in that file.

Can you help me, please?

Hi,

The easiest way is probably to write a plugin that adds JS to the tracker that overwrites those functions with ones that do nothing.

https://developer.matomo.org/guides/enrich-js-tracker

Keep in mind that doing so does change pretty little* as obviously users can change the cookie expiration by simply editing the cookie.

* the only thing I can think of that this prevents is that a frontend developer can’t accidentally call these functions thinking they do something else.

But I don’t see how to override those functions, they are part of matomo class so I can’t acess them

You might be able to do something like

window.Matomo.getAsyncTracker().setVisitorCookieTimeout = function(){}

but I can’t promise it will work reliably.

Hello, sadly that way to disable the function didn’t work, but we could achieve something similar by using the plugin https://plugins.matomo.org/JsTrackerCustom and writing this into it:
_paq.push([“setVisitorCookieTimeout”, “15552000”]);

Seems that this override any call to the function from outside matomo.js so we are safe like this.

Thanks for your support

1 Like