How to set up cross-domain tracking in GA4? - google-analytics

How to set up cross-domain tracking in GA4 right?
I followed official instructions: [GA4] Set up cross-domain measurement
I've added all the domains I need to the Date Stream Details - More Tagging Settings - Configure your Domains.
Added 'Google Analytics: GA4 Configuration' tag on the website using Google Tag Manager.
But now, when switching between domains, a lengthy parameter
(smth like "?_gl=11lop9ld*_gaNDcxNTp2McYzKjE2LTcxMjQwKLv._ga_3JP1WO1NB3MTYxNzEyNDA4Ny8xLjEuKOPxNzEyNLI5Ny40Nw..")
is added to the page address and the page does not open, a 404 error appears.
What could be the problem?

As #Tony McCreath said, It might be a problem on the website's end on handling unexpected query parameters. I already faced this problem while working on a client website, and there was nothing that could be done on the Analytics side to fix the issue. You can test if that's the case by adding any random parameters at the end of the URL to see if the website still works.
The lengthy parameter that is added to the URL is the way Google uses to identify that a user is coming from another domain. It's basically an ID that will link the user from the previous domain to the current one.

Related

How to create a Google Analytics report on a specific query string?

I have hunted around a bit and only found how to setup the site search parameter in a site's admin section. This is not what I want. Also looked through some Google Search Console videos - no go.
Given a URL, https://somesite.com/redirect/?redirect=https://gofundme.com/somecampaign/.
As some background, what I have setup here is a simple page that says "Loading..." and is used for external links I want to track analytics on, from platforms that I may not have access to the link's analytics. For example: https://gofundme.com/somecampaign.
Rather than having a redirect setup on the page itself, I injected custom JavaScript through Google Tag Manager that records analytics data in Google Universal Analytics (anyone want to recommend how to do this in G4A?) then performs the redirect.
My question is, in Google Analytics, how do I setup a custom report where the query string parameter = redirect and/or the specific page URL?
Thanks.

Tracking original referrer in GA when using SagePay Form integration

When using the SagePay Form integration, the referrer in Google Analytics always shows as live.sagepay.com rather than the original referrer. This is because, when using this integration method, the user gets redirected to live.sagepay.com to complete the payment process before getting redirected back to the original website.
Since the payment templates on SagePay don't allow external scripts, we can't add the analytics tracking script here, which means cross-domain tracking is out of the question.
Is there a workaround for this problem? As many payment gateways are external and behave in a similar way I'm guessing this must be a fairly common issue?
You can add a referral exclusion in the Google Analytics account itself. This should prevent new sessions being created as per the docs:
https://support.google.com/analytics/answer/2795830?hl=en

Can you test google analytics on a localhost address?

I have to test out my new GA account on my local machine.
Will this work just by copying the standard snippet supplied by Google onto the page ?
I don't want to spend 24 hours waiting to see if it will or won't work.
This question remains valid today, however the technology has changed. The old Urchin tracker is deprecated and obsolete. The new asynchronous Google Analytics tracking code uses slightly different code to achieve the same results.
Google Analytics Classic - Asynchronous Syntax - ga.js
The current syntax for setting the tracking domain to none on google analytics looks like this:
_gaq.push(['_setDomainName', 'none']);
Google analytics will then fire off the _utm.gif tracker request on localhost. You can verify this by opening the developer tools in your favorite browser and watching the network requests during page load. If it is working you will see a request for _utm.gif in the network requests list.
Updated 2013 for Universal Analytics - analytics.js
Google released a new version of analytics called "Universal Analytics" (late 2012 or early 2013). As I write, this the program is still in BETA so the above code is still recommended for most users with existing installations of Google Analytics.
However, for new developments using the new analytics.js code, the Google Analytics, Advanced Configuration - Web Tracking Documentation shows that we can test Universal Analytics on localhost with this new code:
ga('create', 'UA-XXXX-Y', {
'cookieDomain': 'none'
});
Check out the linked documentation for more details on advanced configuration of Universal Analytics.
Update 2019
Both Global Site Tag - gtag.js and Universal Analytics - analytics.js will detect localhost automatically. You do not need to make any change to the configuration.
If gtag.js detects that you're running a server locally (e.g. localhost), it automatically sets the cookie_domain to 'none'.
- developers.google.com
Updated for 2014
This can now be achieved by simply setting the domain to none.
ga('create', 'UA-XXXX-Y', 'none');
See: https://developers.google.com/analytics/devguides/collection/analyticsjs/domains#localhost
I had the same problem, and all the solutions didn't work until I did two things:
Obvious code:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXXX-X']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
AND
I added localhost another FQDN - domain name. I did this on Windows sistem by editing:
C:\Windows\System32\drivers\etc\hosts
file, and I put in the following:
127.0.0.1 my.domain.org
Then I went to address http://my.domain.org/WebApp that is serving page with included google analytics JS.
If you are on unix, edit /etc/hosts for same result.
It think that Google should put Intranet configuration in ther GA FAQ. They just say that you need FQDA. Yes, you do, but not for them to access you, you need it just to have Host attribute in HTTP request.
I think another reason for FQDN is COOKIES! Cookies are used to track data and if you don't have FQDN, cookie can not be set, and JS code stops and doesn't get the gif.
After spending about two hours trying to come up with a solution I realized that I had adblockers blocking the call to GA. Once I turned them off I was good to go.
Answer for 2019
The best practice is to setup two separate properties for your development/staging, and your production servers.
You do not want to pollute your Analytics data with test, and setting up filters is not pleasant if you are forced to do that.
That being said, Google Analytics now has real time tracking, and if you want to track Campaigns or Transactions, the lag is around 1 minute until the data is shown on the page, as long as you select the current day.
For example, you create Site and Site Test, and each one ha UA-XXXX-Y code.
In your application logic, where you serve the analytics JavaScript, check your environment and for production use your Site UA-XXXX-Y, and for staging/development use the Site Test one.
You can have this setup until you learn the ins and outs of GA, and then remove it, or keep it if you need to make constant changes (which you will test on development/staging first).
Source: personal experience, various articles.
Now the answer for your question is yes, it will just work by copying the standard snippet. According to documentation, now the standard snippet has automatic cookie domain configuration: ga('create', 'UA-XXXXX-Y', 'auto'); where cookie domain is automatically determined.
In addition, if analytics.js detects that you're running a server
locally (e.g. localhost) it automatically sets the cookieDomain to
'none'.
It will work if you use an IP or set domain to none.
Details here:
http://analyticsimpact.com/2011/01/20/google-analytics-on-intranets-and-development-servers-fqdn/
An easier tool to monitor the tracking tags is to use the Chrome extension (probably available, or the equivalent for other browsers) - Google Tag Assistant. This will show what tags are firing, what problems it has found, and even breaks out stuff like eCommerce values for easy reading. Also works with the Google Tag Manager, and can handle multiple sets of tags on the page.
I just want to add to what's been said so far, it may save a lot of headache, you don't need to wait 24 hour to see if it works, yes the total overview take 24 hour, but in Reporting tab, there is a link on left side to Real-Time result and it will show if anyone currently visiting your site, also I didn't have to set 'cookieDomain': 'none' for it to work on localhost, my setting is on 'auto' and it works just fine (I'm using MVC 5), on top of that I've added the script at the end of head tag as google stated in this page:
Paste your snippet (unaltered, in its entirety) into every web page you want to track. Paste it immediately before the closing </head> tag.
here is more info on how to check to see if analytics works properly.
Following on from Tuong Lu Kim's answer:
Assuming:
ga('create', 'UA-XXXXX-Y', 'auto');
...if analytics.js detects that you're running a server locally (e.g. localhost) it automatically sets the cookieDomain to 'none'....
Excerpt from:
Automatic cookie domain configuration sets the _ga cookie on the highest level domain it can. For example, if your website address is blog.example.co.uk, analytics.js will set the cookie domain to .example.co.uk. In addition, if analytics.js detects that you're running a server locally (e.g. localhost) it automatically sets the cookieDomain to 'none'.
The recommended JavaScript tracking snippet sets the string 'auto' for the cookieDomain field:
Source: https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#automatic_cookie_domain_configuration
I came across this problem recently, and I found it helpful to explore the new documentation by Google on debugging Analytics. It didn't actually care about sending tracking info to Google Analytics, I just wanted to ensure that the events were firing correctly, and the debugging tools gave me the info I needed. YMMV, I realize doesn't exactly answer the question.
For those using google tag manager to integrate with google analytics events you can do what the guys mentioned about to set the cookies flag to none from GTM it self
open GTM > variables > google analytics variables > and set the cookies tag to none

Google Analytics - Goal Funnel Steps

Is there a way to test the url you're entering in a step, to see if Google Analytics will recognize it?
What I'd like to do is provide some web page or some web service with a URL, and get a pass or fail. It passes if Google Analytics recognizes a page hit to the url.
Let me give some context.
We've been having issues with our goal funnel steps in Google Analytics. The instructions on adding steps say not to use the domain.
e.g.
DO NOT use : http://www.mysite.com/step1.html
INSTEAD use: /step1.html
Our custom CRM uses friendly urls and as a result GA is having a hard time picking up on them. So we've experimented with changing around url we've placed in the step, however we've got to wait a day to see if the new url we've provided is going to work! Hence why we're looking for something quicker.
OK- so what you're doing is futzing around with the friendly URLs to see what's being tracked (so you can distinguish one URL from another), but you don't want to have to wait?
There are a few Firefox plugins which report on on-page GA (WASP & Observepoint), but the Firebug Net panel is as good as anything.
The other option is to pass a 'virtual URL' to GA in the _trackPageview, rather than depend on the friendly URL - maybe something like this
_trackPageview("/goal1/step1")
although I'd attempt to have the virtual URL (it's really just the path) named more like the actual steps in the process.
What I'd like to do is provide some web page or some web service with a URL, and get a pass or fail. It passes if Google Analytics recognizes a page hit to the url.
This would be a waste of time for someone to make, so you won't find it; it's a waste of time to make it because all that anyone needs to do to see if the page is being tracked by google analytics or not is to look at their 'content -> top content' report to see if the page is listed or not.
One can also go to the page with Firefox, and using the Firebug addon on can see if a call for the _utf.gif image is made, or not, and confirm that the ga account id's are correct, which would mean that GA is receiving the data, but this does not tell you if the data is making it past your ga profile filters. The only way to determine that the page is tracked and that the tracked page view is available in your profile is to check your content reports.

Does anyone use Google Analytics? How Google does it to avoid counting the owner of the website as visitor?

I don't want to be counted as visitor every time I test my page in the hosting. Does Google know i'm the owner of the site by checking if i'm logged in my Gmail account?
I don't think Google does anything like this automatically. But they do provide instructions for excluding based on IP address (or range) and apparently also now by cookie. If you use a CMS or admin interface, you could put the code they provide in an HTML file that you then include into the admin interface pages by IFRAME (to ensure that the cookie stays set for anyone who uses that interface).
One option is to install Ghostery addon your browser. Ghostery can block trackers and scripts used on webpages likes google analytics, google adword and other adwares.
You can also block or unblock the trackers for a specific site or specific tracker for a particular site.This add on is available for Firefox and chrome browsers. If you have this installed on your browser, your visit wont be counted as google analytic script wont be executed.
You can learn more about ghostery at: http://www.ghostery.com/about
There are also often application specific ways of blocking google from counting administrators. For example I've used a wordpress analytics plugin that would automatically not include the tracking code if the user was logged in as an administrator. If you are application has the concept as admin then you could write something similar that controls when the code is added.
If you visit your site frequently from connections with a dynamic IP address, eg. home broadband, then excluding IP addresses is not particularly practical. To go beyond IP exclusion, you can create an isolated page on your site that only you know about that includes a call to Analytics to label your cookie.
The Google Analytics _setVar() function lets you label yourself with an arbitrary string, eg. 'internal'. You only need to do this once per browser as long you don't clear your cookies.
Having labelled yourself as 'internal', you can create an Advanced Segment within Google Analytics to exclude visitors with that label.
Google Analytics relay on you embedding a call to their JavaScript see this link - do not confuse it with how Google does page ranking.
So the answer to your question is that your pages should be smart enough to recognize when the request comes from you and skip the call to the JavaScript.

Resources