Debug not working with urls containing #

In our web application we use links like this one: “https://xxx.xxx.xx/MyApp.html#Overview”.

I inspected the debug script which is injected by matomo tag manager and found:

if ((document.cookie.indexOf(‘mtmPreview1_8Jipm5bo%3D1’) !== -1 && window.location.search.indexOf(’&mtmPreviewMode=0’) === -1 && window.location.search.indexOf(’?mtmPreviewMode=0’) === -1) || window.location.search.indexOf(’&mtmPreviewMode=8Jipm5bo’) !== -1 || window.location.search.indexOf(’?mtmPreviewMode=8Jipm5bo’) !== -1) {

as you can see it uses window.location.search …

If you use the console you will find that even you have an url containing the debug parameter the result of window.location.search.indexOf(’?mtmPreviewMode=8Jipm5bo’) will return -1 thus disabling debug.

To reproduce this:
Enable Debug Mode in Matomo Tag Manager
Browse an url which does NOT contain #something in the url
Go to console and enter window.location.search(’?mtmPreviewMode=8Jipm5bo’);
You will receive 0

Now head to an url which contains an #
You will receive -1

Thus the debug mode will not work.

I am not sure whether this is a bug. Can you please confirm.

Hi,

I am not sure I can reproduce this.

I go to https://example.com/?mtmPreviewMode=8Jipm5bo#test and window.location.search.indexOf("?mtmPreviewMode=8Jipm5bo") returns 0.

Put # before ?mtmPreviewMode then it’ll break

That makes sense as everything after # is just part of the hash, but window.location.search looks at the GET parameters.

I am so stupid. You are right. Now it’s working! Sorry for the inconvenience!

1 Like