Google Analytics

Enabling cross domain tracking with unsupported navigation – Part 3

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

CP Marketing

Share
Published by
CP Marketing

Recent Posts

Optimizing user experiences with Digital Experience Analytics (DXA) platforms

As consumers become increasingly digitally savvy, and more and more brand touchpoints take place online,…

1 month ago

Enabling Value-Based Bidding with Google Tightlock

Marketers are on a constant journey to optimize the efficiency of paid search advertising. In…

2 months ago

Resolving “Unassigned” Traffic in GA4

Unassigned traffic in Google Analytics 4 (GA4) can be frustrating for data analysts to deal…

2 months ago

This website uses cookies.