This is a 3 part series on cross domain tracking with Google Analytics in non-standard situations:

  1. Part 1
  2. Part 2
  3. Part 3

In this final of our three part series, we’re going to look at adding the Google Analytics query string parameters used to accomplish cross-domain tracking to other variables we may be passing.

If we want to append additional query string variables to the end of our destination URL string we might try something along the lines of the following:

function redirectFunction()
{
window.location.replace(GoogleAnalyticsCookieAppend('http://www.xxx.yyy/
RedirectTarget.html?mookie=pookie'));
}
 

If we do this, it’s possible that we might also notice that our cookie passing solution no longer works.

Uh-oh.

If you find yourself in this situation, it might be because of this:

http://www.xxx.yyy/RedirectTarget.html?mookie=pookie#__utma=
1.283748562613819500.1212185562.1212185562.1212189988.2&__utmb=
-&__utmc=1&__utmx=-&__utmz=1.1212185562.1.1.utmcsr=
(direct)|utmccn=(direct)|utmcmd=(none)&__utmv=-&__utmk=100666753
 

The Google query string parameters were appended at the end of our query string, but with a “#” separator. Not exactly what we were expecting.

A cheap, quick and dirty fix is obvious: replace the “#” with a “&” and be on our way. But keep in mind that a simple replacement may create a problem with existing query string variables if being built dynamically, since we must have a “?” to start the query string parameters and must separate them with a “&” in a URL.

One solution is to extract the existing query string variables first, then call the GA function, then deal with the #/?/& issue,  and then append the old variables at the end.  We update our function to take care of this below:

function GoogleAnalyticsCookieAppend(uri)
{
//grab existing query string variables
var queryStringIndex = uri.indexOf('?');
var queryString =(queryStringIndex == -1) ? "" : uri.slice(queryStringIndex+1);
var myURI = (queryStringIndex == -1) ? uri : uri.slice(0, queryStringIndex-1);
//Use the Google Analytics function to get GA variables
var c = pageTracker._getLinkerUrl(myURI, window);
//Explicitly check in case GA is using #
c = c.replace("#", "?");
alert(c);
//reappend querystring variables
c += "&"+ queryString;
return c;
}
 

And that’s it for this mini-series on exploring the ins and outs of Google Analytics with non-standard tracking across top level domains.  Happy Google Analytics-ing!

Go to Part 1 or Part 2

Message Sent

Thank you for registering.

Cardinal Path hosted a live session to connect with you and answer all your questions on Google Analytics.
Get all the expertise and none of the consultancy fees in this not-to-be-missed, rapid-fire virtual event.

Thank you for submitting the form.

Thank you for submitting the form.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you.

Click here to download access the tool.

Message Sent

Thank you for registering.

Message Sent

Thank you.

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Success!
Your message was received.

Thank you.

Thank you for registering.

Cardinal Path is continuing with its series of free training. Next we are conducting training on Google Data Studio. Check it out here.

Message Sent

Thank you for registering.

Thank you for your submission.

Your request has been submitted and a rep will reach out to you shortly.

Message Sent

Thank you for your interest.

Thank you for registering.

You should receive a confirmation email from GoToWebinar with your unique webinar login information. If you do not receive this email or have trouble logging in to the event, please email asmaa.mourad@cardinalpath.com.

Thank you for subscribing!

You're now looped into the world's largest GMP resource hub!

Thank you for your submission.

Thank you for your submission.

Thank you for your submission.

Thank you for your submission.

Message Sent

Thank you for registering.

Message Sent

Thank you for your submission.

Thank you for your submission.

Message Sent

Thank you for registering.

Thank you for registering.​

Paid media spend by Government websites increased a whopping 139% YoY in 2020.

2020 Online Behavior Live Dashboard

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

2020 Online Behavior Live Dashboard

Thank you for your submission.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Success! Thank you
for reaching out.