V
V
Victor2020-11-17 12:04:39
Google Analytics
Victor, 2020-11-17 12:04:39

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


Question: is there something similar for GTM?

Here is the solution:

gtag('set', {
    referrer: "https://your-referrer-url.com"
})


Full code:
var referrer = "<?=$_SERVER["HTTP_REFERER"]?>";

gtag('set', {
    referrer: referrer,
});

gtag('config', 'G-XXXXXX');

// так же указывал gtag('set') после gtag('config'), всё равно не работает


So: is there a way to tell GTM which referrer to take and whether it is possible to somehow check that he actually took it, because in Google Analytics itself this data is displayed with a delay of almost a day.

Perhaps this solution works, but it is not clear where exactly this line should be specified and at what point GTM sends data (there are no AJAX requests in the console, unlike Yandex.Metrica).

For ga.js, this point is indicated in the documentation , but not for gtag.js. But I understand that ga.js is already marked as a deprecated API. The gtag.js source code is hard to understand because it is obfuscated.

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 question

Ask a Question

731 491 924 answers to any question