'How to override referrer in Google Analytics after refresh from window.location.href
Issue Steps:
- client search on google;
- google gives a link of mysite.com/page-a; and client clicks on the link
- At this point, the referrer is "www.google.com", which is correct
- There is internal logic in the website, redirect and refresh to new page mysite.com/page-b, via reset
window.location.href, this needs to be kept - At this point, the Google referrer is '', which it thinks the traffic is from its own website. (direct source, which is wrong)
How can I programmatically change to tell Google Analytics to reset the referrer?
Through js?: gtag("set","referrer", "www.google.com")
Or script?: https://www.googletagmanager.com/gtag/js?id=MyIDXXXXXX&dr=www.google.com
Solution 1:[1]
Well, first of all, you're supposed to be using a different field as per Google's Documentation:
gtag('set', 'page_referrer', 'https://example.com');
Secondly, you should mention whether you're using UA or GA4. I'm presuming GA4 due to gtag usage.
Finally, you can do it in GTM via setting the page_referrer field like so:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BNazaruk |

