SocialGouv / matomo-next

Matomo for Next.js applications
Apache License 2.0
152 stars 21 forks source link

Do not set ReferrerUrl on routeChangeStart #96

Open carolineBda opened 1 year ago

carolineBda commented 1 year ago

This param is used to determine how someone got to the website and not for internal navigation : https://developer.matomo.org/api-reference/tracking-api#optional-user-info

As they say here we only need to call setCustomUrl and setDocumentTitle before trackPageView

So we need to remove this bit

maxgfr commented 1 year ago

+1

m-maillot commented 1 year ago

Il parle aussi dans la section Updating the referrer un peu plus bas que l'on peut mettre à jour le referrer également. Par contre ça manque d'information de pourquoi je voudrais indiquer un referrer 🤔

m-maillot commented 1 year ago

D'ailleurs dans l'exemple plus loin (Measuring Single-Page Apps: Complete Example), il set un referrerUrl à la current page :

var currentUrl = location.href;
window.addEventListener('hashchange', function() {
    _paq.push(['setReferrerUrl', currentUrl]); <------------------ ICI
     currentUrl = '/' + window.location.hash.substr(1);
    _paq.push(['setCustomUrl', currentUrl]);
    _paq.push(['setDocumentTitle', 'My New Title']);

    // remove all previously assigned custom variables, requires Matomo (formerly Piwik) 3.0.2
    _paq.push(['deleteCustomVariables', 'page']);
    _paq.push(['AbTesting::create', {
       name: 'theExperimentName',
       includedTargets: [{"attribute":"url","type":"starts_with","value":"http:\/\/www.example.org","inverted":"0"}],
       excludedTargets: [],
       variations: [
          {
             name: 'original',
             activate: function (event) {
                // usually nothing needs to be done here
             }
          },
          {
             name: 'blue',
             activate: function(event) {
                // eg $('#btn').attr('style', 'color: ' + this.name + ';');
             }
          }
       ]
    }]);
    _paq.push(['trackPageView']);

    // make Matomo aware of newly added content
    var content = document.getElementById('content');
    _paq.push(['MediaAnalytics::scanForMedia', content]);
    _paq.push(['FormAnalytics::scanForForms', content]);
    _paq.push(['trackContentImpressionsWithinNode', content]);
    _paq.push(['enableLinkTracking']);
});