Answer the question
In order to leave comments, you need to log in
How to tell Google Tag Manager where to get Referrer from?
When entering the site, under certain conditions, a redirect occurs, due to which the original document.referrer flies on the final page with analytics, this leads to the loss of data about where the user came to the site from.
There is a need for GTM to take not document.referrer for analytics, but what will be slipped into it. The original Referer header is remembered by the server and substituted into $_SERVER["HTTP_REFERER"] on the final page, but document.referrer is a read-only property and cannot be substituted there for this to work in all browsers.
In the case of Yandex.Metrica, everything is solved and works well through the utm_referrer parameter in the URL. It correctly indicates transitions from other sites and from search engines, despite the redirect.
From documentation:
In order for Yandex.Metrica to correctly determine the source of a referral to a site during a JavaScript redirect or when a user navigates to your site with the HTTP protocol from a site accessible via the HTTPS protocol, use the utm_referrer parameter.
As a value, specify the address of the site from which the transition was made. Example:
https://example.com/?utm_referrer=example-source.com
gtag('set', {
referrer: "https://your-referrer-url.com"
})
var referrer = "<?=$_SERVER["HTTP_REFERER"]?>";
gtag('set', {
referrer: referrer,
});
gtag('config', 'G-XXXXXX');
// так же указывал gtag('set') после gtag('config'), всё равно не работает
ga('set', 'referrer', 'http://example.com');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question