googleanalytics / autotrack

Automatic and enhanced Google Analytics tracking for common user interactions on the web.
Other
4.92k stars 564 forks source link

fieldsObj.page encoding issue #191

Open pcvandamcb opened 7 years ago

pcvandamcb commented 7 years ago

I'm trying to use the cleanUrlTracker functionality to strip out e-mail addresses from our page views. I'm running into the issue that when I check the fieldsObj, the page property is sometimes encoded and sometimes not.

When I do a request for https://mydomain.com/page?someparam=1 the resulting fieldsObj is as expected:

{
  page: '/page?someparam=1',
  location: 'https://mydomain.com/page?someparam=1'
}

However when I request https://mydomain.com/?someparam=1 the resulting fieldsObj is as such:

{
  page: '/%2F%3Fsomeparam%3D1',
  location: 'https://mydomain.com/?someparam=1'
}

(note that it also adds an extra slash in front)

Any idea what is going on here?

philipwalton commented 7 years ago

Can you show your code? Specifically how you're requiring the cleanUrlTracker plugin and what options you're passing?

pcvandamcb commented 7 years ago
window.ga("require", "cleanUrlTracker", {
  urlFieldsFilter: function(fieldsObj, parseUrl) {
    console.log(fieldsObj);
    return fieldsObj;
  }
});

I minimised the case to this. No other options and also removed other plugins and just ran this one.

philipwalton commented 7 years ago

I'm not seeing that. Do you have this hosted live anywhere? Here's what I'm seeing:

screen shot 2017-07-31 at 10 43 13 am

And as you can see I'm using the same options you are:

<!doctype html>
<html>
<head>
  <script>
    window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;

    ga('create', 'UA-12345-1', 'auto');
    ga('require', 'cleanUrlTracker', {
      urlFieldsFilter: function(fieldsObj, parseUrl) {
        console.log(fieldsObj);
        return fieldsObj;
      }
    });
    ga('send', 'pageview');

  </script>
  <script async src="https://www.google-analytics.com/analytics.js"></script>
  <script async src="https://rawgit.com/googleanalytics/autotrack/master/autotrack.js"></script>
</head>
<body>
</body>
</html>
pcvandamcb commented 7 years ago

Thank you. Unfortunately there is no live example I can show. I will have to do some more research into what is different on our end that causes this behaviour. Will update this post if it is something you should know.