0

I have a client site that is experiencing a rogue JS redirect that is causing issues with analytics tracking, as these tools rely on an accurate document.referrer. This redirect is interesting in that it is only for new users, and it redirects the user back to the same page they originally navigated to.

The client is not able to tell me what tools they have added or removed lately, so I am stuck trying to identify for them what piece of JS on their site is causing this. Is there any good way to identify what is causing this redirect?

Things I've tried:

  • Searching the site source for instances of 'window.location'
  • Searching all directly utilized JS on the site for 'window.location'

Any help would be appreciated!

andre622
  • 495
  • 3
  • 16
  • Are you able to get the requet's header for 'referer' ? https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer – blurfus Jun 24 '19 at 19:57
  • It's possible the client's server-side code could get the true referrer, but all of the analytics tools are entirely client-side, i.e. Google Analytics, Google Ads, etc. These tools are loading and sending requests after the JS initiated redirect happens, causing the referring URL to appear to be the page the user is currently on (redirect points to the same page). – andre622 Jun 24 '19 at 20:00
  • add a unique query to every redirect URL that identifies which is which. Like in `function X line 100` add "&src=x100". Then just check the value of src when the redirect happens. – imvain2 Jun 24 '19 at 20:02

1 Answers1

0

Add a listener to href changes:

window.addEventListener('popstate', listener);

const pushUrl = (href) => {
  history.pushState({}, '', href);
  window.dispatchEvent(new Event('popstate'));
};

And give merits to @PHF Merits

Sam
  • 1,459
  • 1
  • 18
  • 32