Custom opt-out form - _paq vs _mtm variable


I got a tracking code and opt-in/out iframe to implement from our digital marketing department. To make the opt-in/out iframe fit the styling of the site, I followed the documentation for implementing a custom opt-in/out form..

At first I was confused because the variable in the tracking script that I got is called _mtm and the documentation references _paq. I changed the code from the documentation to reference _mtm at first but that didn’t work (_mtm.push() function is not valid). Now that I keep the code just like in the documentation, I get an error with this line element.checked = !this.isUserOptedOut();. The isUserOptedOut() method does not exist on the this Object.

When clicking the checkbox I get another error saying
There was an error setting cookiemtm_consent_removed. Please check domain and path.

I’m really confused on which variable I should use for the custom form (_paq or _mtm). Help on how to solve this would be much appreciated! Thanks :slight_smile:



There is no _mtm variable for Matomo tracking, only _paq works. _mtm is the variable for Matomo Tag Manager.

This is

You can either ignore it or update to Matomo 4.5.0 or later.

Hi Lukas,

thanks a lot for clarifying the variables! I will check back with the digital marketing department to see if my implementation of the custom opt-out form works. I have a feeling though that there is a piece missing. Shouldn’t the opt-out form have a URL that the user action is reported to? Or is that taken care of by the main script that is on the page?

var _mtm = (window._mtm = window._mtm || []);
_mtm.push({ "mtm.startTime": new Date().getTime(), event: "mtm.Start" });
var d = document,
  g = d.createElement("script"),
  s = d.getElementsByTagName("script")[0];
g.async = true;
g.src = "";
s.parentNode.insertBefore(g, s);

I found my mistake! If you check the codepen on line 21… the isUserOptedOut is being called outside of _paq.push. After moving it, I don’t get any of the error’s anymore that I described earlier.

1 Like