@basos9 opened this Issue on January 5th 2021

When using the JS tracking setReferrerUrl seems to be ignored.


Matomo 3.14.0


    var _paq = _paq || [];
    if (document.referrer && document.referrer.search(/bad/ > -1) {
      console.log('Unsetting referrer, current:'+document.referrer);

    (function() {
    var u='//' + piwik_url + '/';
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', siteid]);
    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+'piwik.js'; s.parentNode.insertBefore(g,s);


We see that code which sets referrer is run


Unsetting referrer, current:...

nevertheless the current referrer as seen by


is also set in piwik.php?....&urlref parameter

urlref: https://bad.domain/
@basos9 commented on January 5th 2021

A guess from some inspection that I did in the tracking js might be that setReferrerUrl might have to be executed before trackPageView

In this code that is run (breakpoint in the debugger)

            function logPageView(customTitle, customData, callback) {
                configIdPageView = generateUniqueId();

                var request = getRequest('action_name=' + encodeWrapper(titleFixup(customTitle || configTitle)), customData, 'log');

                sendRequest(request, configTrackerPause, callback);

and inside getRequest the configReferrerUrl is the detected from document.referrer and not the set one.

Also this code

            this.setReferrerUrl = function (url) {
                configReferrerUrl = url;

runs (breakpoint) after the above.

Maybe this has to do with the method applied first as noted in applyFirst=... .
setReferrerUrl is not in this list.

@tsteur commented on January 10th 2021 Member

@basos9 your inspection looks correct. You'll need to call this method before the page view. I suggest you reorder the tracking code to

    if (document.referrer && document.referrer.search(/bad/ > -1) {
      console.log('Unsetting referrer, current:'+document.referrer);

We wouldn't want to add this to applyFirst unfortunately as someone might initially want to track the page view with the original referrer URL first.

I'll mention this in the docs though.

This Issue was closed on January 10th 2021
Powered by GitHub Issue Mirror