bengen343
bengen343

Reputation: 139

Capture subdomain page referrer UA/GA4

It seems like there should be a wide need for this but I can't find a solution anywhere. I presently have a domain configured for Google UA and GA4. We have a sub-domain where we accept payments for example:

Main page: example.com

Payments page: payments.example.com

When a user navigates from "example.com/product" to "payments.example.com" the 'page_referrer' parameter in Google Tag Manager, Analytics, etc. just shows "example.com". I'd like to capture the referring page as "example.com/product"

The correct behavior occurs across the rest of the website. It's only when crossing subdomains that I lose the page information. I can see from the DebugView as well as my cookies that analytics correctly identifies me as the same user, that cookies are being set at the root-domain level of .example.com and that information is being captured at the user/session level. So it seems baffling that I can't get this one parameter to populate.

Does anyone have any ideas on how I can remedy this?

Upvotes: 0

Views: 1211

Answers (1)

Eike Pierstorff
Eike Pierstorff

Reputation: 32780

You cannot easily remedy this from within GTM/GA, since the root cause is a security feature of the browser, the referrer policy. That is a setting that determines how much information is exposed via the referrer, and for some time now the quasi standard for the default referrer policy has been "strict-origin-when-cross-origin".

This means that when a user navigates across domains, which includes navigation across subdomains, all information except the "origin" (the hostname) is stripped from the referrer.

As workarounds you can either append the referring page as a query parameter in urls to payment.example.com, read it from the address bar and in your code overwrite the referrer field in Google Analytics.

Or, a rather more elegant, but maybe less reliable way would be to set a referrer header via your server - the most 'radical" option would be unsafe-url, which send the untampered with referrer. You can do this, since your page and your domain are under your own control (but I am not quite sure all browsers will respect that header, which is why I called it "maybe less reliable"). Implementation depends on your programming language or server software.

Upvotes: 1

Related Questions