Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setReferrerUrl is ignored #17047

Closed
basos9 opened this issue Jan 5, 2021 · 2 comments
Closed

setReferrerUrl is ignored #17047

basos9 opened this issue Jan 5, 2021 · 2 comments
Labels
answered For when a question was asked and we referred to forum or answered it. c: Documentation For issues related to in-app product help messages, or to the Matomo knowledge base.

Comments

@basos9
Copy link

basos9 commented Jan 5, 2021

When using the JS tracking setReferrerUrl seems to be ignored.

ENV

Matomo 3.14.0

CODE

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

    (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);
    })();
    }

EXECUTION

We see that code which sets referrer is run

console.log

Unsetting referrer, current:...

nevertheless the current referrer as seen by

document.referrer
https://bad.domain/

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

urlref: https://bad.domain/
@basos9
Copy link
Author

basos9 commented Jan 5, 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
Copy link
Member

tsteur commented Jan 10, 2021

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

    _paq.push(['enableLinkTracking']);
    if (document.referrer && document.referrer.search(/bad/ > -1) {
      console.log('Unsetting referrer, current:'+document.referrer);
      _paq.push(['setReferrerUrl','']);
    }
    _paq.push(['trackPageView']);

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.

@tsteur tsteur added the c: Documentation For issues related to in-app product help messages, or to the Matomo knowledge base. label Jan 10, 2021
@mattab mattab added the answered For when a question was asked and we referred to forum or answered it. label Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it. c: Documentation For issues related to in-app product help messages, or to the Matomo knowledge base.
Projects
None yet
Development

No branches or pull requests

3 participants