Tracking Pageviews based on Referrer - google-analytics

My goal is to track a user session when a visitor is sent from a specific website.
I would expect visitor from 2 websites: a.com and b.com
I would want trigger a tag 1 if referrer contained a.com
and trigger tag 2 if referrer contained b.com. Once a user lands on my site, they would be expected to travel around many pages on my domain. I still would need to track that session even though the HTTP Referer is no longer matching a.com.
My goal is to track how many of these sessions get sent from a.com, how many from b.com and how many reach of each reach a thank page at /thankyoupage
How would this be configured ?
Would this require session scope and if so, how would this be configured ?

If you just want to see this in Google Analytics you can create a segment with referrer a.com or b.com (mind that in GA the referrer is a traffic channel and only filled if there are not campaign parameters present on the landing page url). So for Analytics you do not need extra work. Traffic channels are automatically in session scope (as a change in channel starts a new session).
If you want to fire a tag conditionally based on the referrer it get's a tad more complicated. GTM does not maintain sessions, and does not, by itself, transfer information between page views. So you need to store the info yourself.
You would use the built-in referrer variable in a trigger that fires a tag if the referrer does not match your own domain. You would use that to fire a custom html tag with a Javascript function that sets a cookie. You then set a cookie with the referrer.
On your thankyou page you use the built-in cookie variable to read your cookie. If the cookie contains a.com or b.com respectively you use that for triggers that fire the appropriate tags (pageview trigger, fire on some pageviews, filter "[your cookie variable] equals a.com" (or b.com)). Since cookies are domain specific this only works when your thankyou page is on the same domain.

I don't think you need to do any configuration for this.
For referral traffic, you can see the acquisition report. It should show up with a source as a.com and b.com.
for reaching the thank you page, I'd suggest you set up goals based on the arrival of the thank you page.

As per my understanding, you want to have cross-domain tracking and want to track below thing:
Page 1of a.com --> Page 2 of a.com --> Page 1 of b.com --> page2 of b.com
By default whenever the domain changes User's GA ID is changed. So for a.com and for b.com GA will treat the same user as different, so by default, you cannot track such things.
To track above scenario GA should consider that the user on both the site is same And to do that GA provides Cross Domain tracking using Linker
https://developers.google.com/analytics/devguides/collection/analyticsjs/linker

Related

Manually setting the Google Analytics Client ID

I have a sub-domain that I am unable to put GTM or GA tracking code on. I have GA on the main domain.
I can retrieve the _ga cookie and get the Client ID but but if a user has not been to the main website they won't have one.
My question is:
Can I set a cookie called _ga (in the same format as GA sets it) and will this get picked up by GA if the user then goes back to the main website?
This article seems to be what you need:
Cookie Settings And Subdomain Tracking In Universal Analytics
https://www.simoahava.com/analytics/cookie-settings-and-subdomain-tracking-in-universal-analytics/

Track across subdomains

What's the best way to track across subdomains? Here's the scenario:
Customers on my site can create their own custom site name or subdomain. For example, if John Doe signs up as a customer, they can create their own personal subdomain of: johndoe.mydomain.com. In a sense, subdomains are created dynamically as each new customer signs up and creates their own subdomain.
Once someone signs up as a customer, they have access, or the ability, to sign up for another service that allows them to accept online donations. Should they choose to buy this capability or product, they are taken to a subdomain of: admin.forms.com. It's on this subdomain where customers can purchase this add-on. So basically, customers are moving from their own custom subdomain to admin.forms.com to signup for this service.
The goal is to see how many customers are signing up for this service. Does it make sense to create a new property for admin.forms.com? Or should I use a view or segment?
Thanks in advance for any suggestions/insight.
Since the subdomains actually belong to different domains you would need to set up proper cross-domain tracking if you want to track across domain boundaries.
Pageviews by the same visitor are connected to a session via the clientId. The clientId is stored in a cookie. Cookies are domain specific. Since cookies from mydomain.com cannot be read by a client browsing forms.com the clientId needs to be carried over as query string parameter. That's what cross domain tracking does.
Since you want to view traffic to your two (sub)domains as if this was a single domain (i.e. you want an uninterrupted "user journey") using additional views or properties would defy your purpose).
Unless you specifically set the cookieDomain value either to "auto" or to the top domain the cookie will be valid for the subdomain(s) only, so you won't have to worry that this interferes with tracking on the top domain level (however if you expect users to browser on the top domain level (e.g. switch from admin.forms.com to plain forms.com) then you should set the cookieDomain field to auto, else GA will allocate a new clientId when the user switches from subdomain to main domain).

Preserving cross domain GA on mobile redirect, how to do this properly?

I have a site, let's say test.com. This incorporates Google Tag Manager. I have a console for booking, this goes to a different domain. So the form's action is say, bookings.anotherdomain.com.
When the form is submitted, the URL becomes bookings.anotherdomain.com/?_ga=TOKEN. From what I understand, _ga is the new param for all google tracking, all the utm params are stored for it in google's database.
On bookings.anotherdomain.com, for the moment this site is not fully responsive and has a "sniffer" script that redirects to mobile.yetanotherdomain.com. Yes, that's 3 different domains.
The problem is during the redirect from bookings.anotherdomain.com to mobile.yetanotherdomain.com, no GA params are passed. This redirect happens via server side.
I'm wondering if the proper procedure would be to pass the _ga variable?
$ga = '?_ga=' . htmlspecialchars( $_REQUEST['_ga'] );
header('Location: mobile.yetanotherdomain.com/' . $ga );
exit;
Would this be the right way of sending the GA params? I can't use JS for this as I want to keep it a server-side redirect, so that eliminates any GA JS script calls.
The short answer to your question is yes, forward that URL parameter if you can.
It sounds like you're using the analytics.js linker plugin, which is designed to do cross-domain tracking. Analytics.js keeps track of a particular user on a domain by storing a client ID value in a cookie. So, in order for analytics.js to track a particular user when she leaves domain A and goes to domain B, that client ID must be passed somehow. That's what the _ga=TOKEN URL parameter is -- the client ID.
In order for the destination domain to know to check for that _ga URL param, you have to tell your tracking code to expect it. The developer guide I linked to above should explain how to do that.
This site also has some good information on cross-domain tracking:
https://support.google.com/analytics/answer/1034342
I hope that helps; let me know if you want more details.

Shibboleth being passed as referrer in Analytics

Been searching for an answer for this for a while but nothing that I can find that is useful.
Basically in the organisation I work in we use Shibboleth for user authentication.
We probably have 200+ sites & Shibboleth works effectively for these.
However, one site in particular is protected using Shibboleth (if the user is not a valid user they have to sign up for an account in this process also) which is causing an issue with our Analytics (Google Analytics). The referrer to the site is ALWAYS the shibboleth authenticator.
What we need is a facility to track conversions on this site based on source/campaign the user arrived from. The proposed solution right now is to use a Tag Manager product to fire off specific tags based on a combination the referrer or campaign. This one single site is used for a multitude of things (all prospective leads to EPR) but we need different information based on how the user landed on that page.
We are tracking all the interaction points that lead up to this (i.e. tracking potential leads) but a lot drop out during the signup process and right now we do not have actual conversion data, meaning the Marketing etc is being spent based on highest traffic source rather than which source or campaign is most effective.
The problem is when a user signs in, signs up using Shibboleth, Shibboleth sets a new cookie for that session. In Google Analytics all the referrer to this site are from the authenticator.
Is there some configuration issue with GA that I am overlooking for this scenario or is there something that can be done with Shibboleth so that the initial referrer (rather than the authenticator) being passed as the referrer which in turn would facilitate the rule creation of the Tag Manager to fire off the required tags
If you use Universal Analytics, you might be able to overcome using the new Referral Exclusion:
You can exclude specific domains from being recognized as referral
traffic sources in your Analytics reports. A common use for this
feature is to exclude traffic from a third-party shopping cart to
prevent customers from being counted in new session and as a referral
when they return to your order confirmation page after checking out on
the third-party site.
Google Analytics recognizes the URL you use to set up a new property
in your account and automatically excludes this domain from your
referral traffic, so you won’t see self-referrals in your Analytics
reports.
https://support.google.com/analytics/answer/2795830?hl=en
Another option might be to pass a parameter across the login page when you request an authentication. If you set your fields in the request correctly, you could have Shibboleth send your user back to any page or with any query string, such as adding ?source=original_page_name. After authentication, these parameters should be available to manipulate or pass on to GA. This won't actually spoof your referrers, but it will get you the data you need.

iframe cross-domain validate caller

I have a page on A.com that has an iframe whose "src=" is on B.com.
For example, src="http://B.com/index.asp?123456"
The query string 123456 is a client key assigned to domain A.com.
index.asp does a database lookup with the key to identify the domain.
How can I ensure that it was a page on A.com that made the call?
I thought about passing location.host, but that can be hacked.
That is, C.com could say: it's B.com by changing location.host to B.com.
(Obviously, location.host is determined via JavaScript.)
I can have other HTML code on A.com than just the iframe.
You can use postMessage and verify the origin on the event object., but you should never rely on any client side validation where security is a concern. Simply by adding a break point on the post message callback in any developer tool can easily circumvent this method.

Resources