Tag Archives: Google Analytics

Google Analytics Click Event Tracking on LinkButton in ASP.NET (VB)

Google Analytics integration with .NET web parts requires more planning and execution than with straight HTML. To apply dynamic event tracking to a LinkButton we can attach a function to the OnClientClick attribute of the LinkButton.

First, a review of how the event tracking method is set up directly from Google:

_gaq.push(['_trackEvent', 'category', 'action', 'optional_label', 'optional_value']);

category (required)

The name you supply for the group of objects you want to track.

action (required)

A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.

label (optional)

An optional string to provide additional dimensions to the event data.

value (optional)

An integer that you can use to provide numerical data about the user event.

To set it up on the LinkButton:

<asp:LinkButton ID="lb_mylinkbutton"
OnClientClick='<%# GetGoogleAnalyticsEventTracking("Downloads", "PDF", "/link/to/myPDF.pdf") %>'
runat="server">My Link Button</asp:LinkButton>

In the code above the values are hard coded, but you can use variables in their place for dynamic links:

<asp:LinkButton ID="lb_mylinkbutton"
OnClientClick='<%# GetGoogleAnalyticsEventTracking(Eval("link_category"), Eval("link_action"), Eval("link_label")) %>'
runat="server">My Link Button</asp:LinkButton>

And, the .NET function, VB flavor:

Protected Function GetGoogleAnalyticsEventTracking(ByVal link_category As String, ByVal link_action As String, ByVal link_label As String) As String

        Return String.Format("_gaq.push(['_trackEvent','{0}','{1}','{2}']);", link_category, link_action, link_label)

End Function

When the user clicks the LinkButton, the Google Analytics track event method will fire and, provided Google Analytics tracking is set up properly on the site, you will see the click events tracked within a day.

Custom Variable Not Showing Up in Google Analytics

Attempting to track authenticated users within the site, I added a custom variable to my Google Analytics tracking. It went something like this:

_gaq.push(['_setCustomVar', 1, 'User_Status', 'Authenticated', 2]);

I placed this right after my Google Analytics tracking code in the head section of the page. Like so:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
_gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

//custom variable for logged in users
_gaq.push(['_setCustomVar', 1, 'User_Status', 'Authenticated', 2]);

Seemed like the logical place based on other Google Analytics code I have added in the past.

This function calls the _setCustomVar method, sets it to slot 1, creates a category of ‘User_Status’, sets the value to ‘Authenticated’, and sets the scope of the custom variable to session level.

And then I waited and waited. After two days I saw absolutely no custom variables in my Google Analytics reports that corresponded to the one I had set.

Going back to the documentation Google provides on setting custom variables, I found this little nugget at the bottom of the page:

Call the _setCustomVar() function when it can be set prior to a pageview or event GIF request.
In certain cases this might not be possible, and you will need to set another _trackPageview() request after setting a custom variable. This is typically only necessary in those situations where the user triggers a session- or visit-level custom var, where it is not possible to bundle that method with a pageview, event, or ecommerce tracking call.

I moved the custom variable code, and, like magic, it all worked out.

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-1']);

//custom variable for logged in users
_gaq.push(['_setCustomVar', 1, 'User_Status', 'Authenticated', 2]);

_gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

It pays to read ALL the documentation. It would have been nice, though, if Google had put that important piece of information in a more prominent location.

Google Analytics Core Reporting API (Data Export) with Google Chart Visualizations

Updated 12/20/11 and 01/04/12 to reflect Google’s API changes

You can punch into the Google Analytics Core Reporting (Data Export) API, pull out some stats, and stuff them into some nice graphical charts using Google Chart Visualizations. This demo is done in PHP.
Google Chart Visualizations

Authenticate the User

The user can authenticate via the ClientLogin or using the AuthSub login which is actually more secure. For the ClientLogin, a typical username/password form is used. For the AuthSub login a link is used to send the user to Google to log in. Both are shown below. Normally you would use one or the other.

* Use ClientLogin ONLY for installed apps and not web apps

<form name="loginForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
		    <label for="email">Gmail:</label>
		    <input id="email" type="text" name="email" />
		    <label for="password">Password:</label>
		    <input type="password" name="password" id="password"/>
		    <br /><br />
		    <button type="submit" id="submitLogin">Submit</button>
		</form>
        <p><a class="button" href="https://www.google.com/accounts/AuthSubRequest?next=http://your-return-url&scope=https://www.googleapis.com/auth/analytics.readonly&secure=0&session=1">Or,authenticate using AuthSub through Google.</a></p>

And, of course, the two authentication methods use different http calls to return a token that can be used to access the API.

//ClientLogin: try to log in and get session token for multiple API calls
if(isset($_POST['email']) && isset($_POST['password'])){
	$_SESSION['sessionToken'] = googleLogin($_POST['email'],$_POST['password']);
}
//AuthSub: exchange token for session token so multiple calls can be made to api
if(isset($_REQUEST['token'])){
	$_SESSION['authSub'] = true;
	$_SESSION['sessionToken'] = get_session_token($_REQUEST['token']);
}

//returns sessionToken for multiple calls to API
function googleLogin($email,$passwd){

    $clientlogin_url = "https://www.google.com/accounts/ClientLogin";
     $clientlogin_post = array(
    "accountType" => "GOOGLE",
    "Email" => $email,
    "Passwd" => $passwd,
    "service" => "analytics",
    "source" => "my-analytics"
	);

	$curl = curl_init($clientlogin_url);

	curl_setopt($curl, CURLOPT_POST, true);
	curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post);
	curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	$response = curl_exec($curl);

	preg_match("/Auth=([a-z0-9_\-]+)/i", $response, $matches);
	$sessionToken = $matches[1];

	if (strlen($sessionToken) == 0){
		$sessionToken = "Authentication Failed.";
	}

 	return $sessionToken;
}

//AuthSub returns session token for multiple calls to API
	function get_session_token($onetimetoken) {
		$output = call_api($onetimetoken, "https://www.google.com/accounts/AuthSubSessionToken");

		if (preg_match("/Token=(.*)/", $output, $matches))
		{
			$sessionToken = $matches[1];
		} else {
			echo "Error authenticating with Google.";
			exit;
		}

		return $sessionToken;
	}

Data Requests

Once authenticated to a Google Analytics account and a multi-use session token is acquired, the data requests can be made. The first one will request the profiles (websites) associated with the account. If there is more than one, a dropdown select is populated allowing for the selection of the profile from which to pull data.

The key is added to the request per this post by Google.

$accountxml = call_api($_SESSION['sessionToken'],"https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties/~all/profiles?key=Axxxxxxxxxxxxxxxxxx4");
// Get an array with the available accounts
$profiles = parse_account_list($accountxml);

The call_api function is going to return the XML data from Google based on the request URL sent in. In this case, it is getting the profile data and the parse_account_list function is rolling through that XML and putting the profile data in an array.

//gets the data
function call_api($sessionToken,$url){
	$curl = curl_init($url);

	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	if (isset($_SESSION['authSub'])){
		$curlheader[0] = sprintf("Authorization: AuthSub token=\"%s\"/n", $sessionToken);
	} else {
		$curlheader[0] = "Authorization: GoogleLogin auth=" . $sessionToken;
	}
	curl_setopt($curl, CURLOPT_HTTPHEADER, $curlheader);

	$response = curl_exec($curl);
	curl_close($curl);

	return $response;
}

//returns accounts list as array
function parse_account_list($xml){
	$doc = new DOMDocument();
	if(stripos($xml,"<") !== FALSE)
	{
		$doc->loadXML($xml);

		$entries = $doc->getElementsByTagName('entry');
		$i = 0;
		$profiles= array();
		foreach($entries as $entry)
		{
			$profiles[$i] = array();

			$properties = $entry->getElementsByTagName('property');
			foreach($properties as $property)
			{
				if (strcmp($property->getAttribute('name'), 'ga:accountId') == 0)
					$profiles[$i]["accountId"] = $property->getAttribute('value');

				if (strcmp($property->getAttribute('name'), 'ga:profileName') == 0)
					$profiles[$i]["title"] = $property->getAttribute('value');

				if (strcmp($property->getAttribute('name'), 'dxp:tableId') == 0)
					$profiles[$i]["tableId"] = $property->getAttribute('value');
			}

			$i++;
		}

		return $profiles;
	} else {
		$sessionToken = "Authentication Failed.";
	}
}

The dropdown of the profile array:

echo "<form name='siteSelect' id='siteSelect' method='post' action='" . $_SERVER['PHP_SELF'] . "'><p><label for='tableId'>Select Site:</label><select name='tableId' id='tableId'>";
		foreach($profiles as $profile)
		{
			if($profile["tableId"] == $table_Id)
				$selected = "selected='selected'";
				echo "<option value='" . $profile["tableId"] . "|" . $profile["title"] . "'" . $selected  . ">" . $profile["title"] . "</option>";
				$selected = " ";
		}
		echo "</select></p>";

// set $tableId
if(isset($_POST['tableId'])){
    $tableId = substr($_POST['tableId'],0,strpos($_POST['tableId'],"|"));
}

The parse_data function below is going to roll through the data returned from Google Analytics and spit out an array that can be used to create the Google Visualization graphs.

//returns data as array
function parse_data($xml){
		$doc = new DOMDocument();
		$doc->loadXML($xml);

		$entries = $doc->getElementsByTagName('entry');
		$i = 0;
		$results = array();
		foreach($entries as $entry)
		{
			$dimensions = $entry->getElementsByTagName('dimension');
			foreach($dimensions as $dimension)
			{
				$results[$i][ltrim($dimension->getAttribute("name"),"ga:")] =  $dimension->getAttribute('value');
			}

			$metrics = $entry->getElementsByTagName('metric');
			foreach($metrics as $metric)
			{
				$results[$i][ltrim($metric->getAttribute('name'),"ga:")] =  $metric->getAttribute('value');
			}

			$i++;
		}
		return $results;
}

Graph Generation

Request the data

// For each website, get referrals
$requrl = sprintf("https://www.googleapis.com/analytics/v2.4/data?ids=%s&dimensions=ga:source&metrics=ga:visits&filters=ga:medium==referral&start-date=%s&end-date=%s&sort=-ga:visits&max-results=10",$tableId,$start_date,$end_date);

$referralsxml = call_api($_SESSION['sessionToken'],$requrl);
$referrers = parse_data($referralsxml);

$requrlvisitsgraph = sprintf("https://www.googleapis.com/analytics/v2.4/data?ids=%s&dimensions=ga:date&metrics=ga:visits&start-date=%s&end-date=%s",$tableId,$start_date,$end_date);
$visitsgraphxml = call_api($_SESSION['sessionToken'],$requrlvisitsgraph);
$visitsgraph = parse_data($visitsgraphxml);

Google Visualizations requires the inclusion of a javascript file in the head tag and empty div’s that will be the target for the graphs:

<script type="text/javascript" src="//www.google.com/jsapi"></script>

The target div’s should be placed on the page where you want them to appear.

<div id='barchart_div'></div>
<div id='piechart_div'></div>

Finally, the data can be added to the chart generation javascript:

<script>
function drawPieChart() {
	var data = new google.visualization.DataTable();
    data.addColumn('string', 'Referrer');
    data.addColumn('number', 'Visits');
    data.addRows(<?php echo sizeof($referrers) ?>);
    <?php
    $row = 0;
    foreach($referrers as $referrer)
		{
	?>
	data.setValue(<?php echo $row ?>,0,'<?php echo $referrer["source"] ?>');
	data.setValue(<?php echo $row ?>,1,<?php echo $referrer["visits"] ?>);
	<?php
	$row++;
	}
	?>

	var chart = new google.visualization.PieChart(document.getElementById('piechart_div'));
    chart.draw(data, {width: 600, height: 440, is3D: true, title: 'Referrer/Visits'});
}

function drawBarChart() {
	var data = new google.visualization.DataTable();
    data.addColumn('string', 'Day');
    data.addColumn('number', 'Visits');
    data.addRows(<?php echo sizeof($visitsgraph) ?>);
	<?php
    $row = 0;
    foreach($visitsgraph as $visits)
		{
	?>
		data.setValue(<?php echo $row ?>,0,'<?php if ($visits_graph_type === "month"){echo date("M", mktime(0, 0, 0, $visits["month"]))." ".$visits["year"];}else{echo substr($visits['date'],6,2)."-".date('M', mktime(0, 0, 0, substr($visits['date'],4,2)))."-".substr($visits['date'],0,4);} ?>');
		data.setValue(<?php echo $row ?>,1,<?php echo $visits["visits"] ?>);
		<?php
		$row++;
		}
		?>
    var chart = new google.visualization.ColumnChart(document.getElementById('barchart_div'));
    chart.draw(data, {'width': 700, 'height': 400, 'is3D': true, 'title': 'Visits'});
}

google.load("visualization", "1.0", {packages:["corechart"]});
google.setOnLoadCallback(drawPieChart);
google.setOnLoadCallback(drawBarChart);

</script>

Recommended

Demo

Download code

Generating Signatures in ColdFusion with RSA-SHA1 for Secure AuthSub in Google Analytics

To send secure AuthSub requests to Google Analytics, you have to sign the request with a private key that is verified against the certificate you upload to Google. Google has a library where this can be done in Java that is specific to Google Analytics and, provided you can add .jar files to your ColdFusion server or use javaloader, you can run them using ColdFusion. If you need to roll your own or simply want to control the process, this example may help.

Before you implement any code that signs requests, the keys and certificate must be generated and then registered with Google you are attempting to access. Google has instructions on how to generate the keys and certificate using OpenSSL and how to register the certificate with Google. You will need the private key in the PKCS#8 format.

Google also supplies instructions for signing the AuthSub requests which is what we will step through here.

To get a single-use token for secure AuthSub, you send the user to authenticate through Google with a link similar to this:

<a href="https://www.google.com/accounts/AuthSubRequest?next=YOUR_PAGE_HERE?secureAuth=yes&scope=https://www.google.com/analytics/feeds/&secure=1&session=1">Log in using Secure AuthSub through Google</a>

Notice that secure is set to 1 indicating we want to send secure requests. Session is also set to 1 indicating we want a multi-use authorization token for multiple calls to the Google Analytics Data Export API. If you are only making one call to the API, you can set session to 0 (zero).

Google will then the user to your page designated by the next parameter with the token attached as a URL parameter called “token.” After getting this single-use token back from Google, you then need to send it back to Google to exchange for your multi-use token. This is where the signing begins. Every request from this point forward needs to be signed.

Secure AuthSub differs from AuthSub in that it requires several parameters to be added to the Authorization header of the request. They are:

  1. token: single-use token (or multi-use token once you get it) from Google
  2. sigalg: rsa-sha1
  3. data: the http-method, request URL, timestamp, and nonce all separated by a space.
  4. sig: the signature made by the private key generated against the data parameter above.

Generating this only requires a few lines of ColdFusion code:

        <cfset Math = createObject('java','java.lang.Math') />
        <cfset randNum = createObject('java', 'java.security.SecureRandom') />
        <cfset numeric_nonce = Math.abs(JavaCast("long",randNum.nextLong())) />
        <cfset nonce = numeric_nonce.toString() />
        <cfset timestmp = DateDiff("s",DateConvert("utc2Local", "January 1 1970 00:00"), Now()) />

        <cfset appSignature = rsa_sha1(rsaPrivateKey, 'GET https://www.google.com/accounts/AuthSubSessionToken ' & timestmp & ' ' & nonce) />

        <cfset authHeaderValue = 'AuthSub token="' & URL.token & '" data="GET https://www.google.com/accounts/AuthSubSessionToken ' & timestmp & ' ' & nonce & '" sig="' & appSignature & '"  sigalg="rsa-sha1"' />

The rsa_sha1 function creates the signature. It was written by Sharad Gupta and used here with permission.

<cffunction name="rsa_sha1" returntype="string" access="public" descrition="RSA-SHA1 computation based on supplied private key and supplied base signature string.">
    <!---Written by Sharad Gupta sharadg@gmail.com (used with permission)--->
           <cfargument name="signKey" type="string" required="true" hint="base64 formatted PKCS8 private key">
           <cfargument name="signMessage" type="string" required="true" hint="msg to sign">
           <cfargument name="sFormat" type="string" required="false" default="UTF-8">

           <cfset var jKey = JavaCast("string", arguments.signKey)>
           <cfset var jMsg = JavaCast("string",arguments.signMessage).getBytes(arguments.sFormat)>

           <cfset var key = createObject("java", "java.security.PrivateKey")>
           <cfset var keySpec = createObject("java","java.security.spec.PKCS8EncodedKeySpec")>
           <cfset var keyFactory = createObject("java","java.security.KeyFactory")>
           <cfset var b64dec = createObject("java", "sun.misc.BASE64Decoder")>

           <cfset var sig = createObject("java", "java.security.Signature")>

           <cfset var byteClass = createObject("java", "java.lang.Class")>
           <cfset var byteArray = createObject("java","java.lang.reflect.Array")>

           <cfset byteClass = byteClass.forName(JavaCast("string","java.lang.Byte"))>
           <cfset keyBytes = byteArray.newInstance(byteClass, JavaCast("int","1024"))>
           <cfset keyBytes = b64dec.decodeBuffer(jKey)>

           <cfset sig = sig.getInstance("SHA1withRSA", "SunJSSE")>
           <cfset sig.initSign(keyFactory.getInstance("RSA").generatePrivate(keySpec.init(keyBytes)))>
           <cfset sig.update(jMsg)>
           <cfset signBytes = sig.sign()>

           <cfreturn ToBase64(signBytes)>
     </cffunction>

The request for and parsing out of the multi-use token looks like this:

<cfhttp url="https://www.google.com/accounts/AuthSubSessionToken" method="GET">
 <cfhttpparam name="Authorization" type="header" value="#authHeaderValue#">
</cfhttp>

<cfset output = cfhttp.filecontent />

<cfset authSubSessionToken = Mid(output, FindNoCase("Token=",output) + (Len("Token=")), Len(output)) />

Any more requests of the Data Export API have to be made in the same manner except now you will use the multi-use token (authSubSessionToken) as the token in the Authorization header.

Recommended

Google Analytics Third-Party Shopping Cart (Cross-Domain) Tracking Using Traditional and Asynchronous Snippet

Cross-domain tracking is used for several situations the most obvious for third-party shopping carts. Proper installation of the Google Analytics (GA) tracking code is essential for accurate tracking of visitors and sales.

GA offers two tracking code snippets for you to choose from: traditional (synchronous) and asynchronous.

First, a short review of the basic installation for both the traditional and the asynchronous:

Basic Tracking Code Installation

Traditional (Synchronous) Tracking Code

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}
</script>

Traditional (synchronous) basic installation is done by placing the above GA tracking code, after replacing “UA-xxxxxx-x” with your account number, before the closing body (</body>) tag on all pages of your site. This placement is supposed to decrease the likelihood that it will interfere with other javascript on your page.

The drawbacks with this installation include increased page load time and the possibility it won’t run at all if the user clicks away from the page before it fully loads.

More on the traditional tracking code installation from Google.

Asynchronous Tracking Code

var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
  })();

Asynchronous basic installation is done by placing the above GA tracking code, after replacing “UA-xxxxxx-x” with your account number, before the closing head (</head>) tag on all pages of your site. Like the traditional code, this placement is meant to decrease the likelihood that it will interfere with other javascript on your page.

According to Google, the asynchronous code has the following advantages:

  • Faster tracking code load times for your web pages due to improved browser execution
  • Enhanced data collection and accuracy
  • Elimination of tracking errors from dependencies when the JavaScript hasn’t fully loaded

More on the asynchronous tracking code installation from Google.

Third-Party Shopping Cart (Cross-Domain) Tracking

It is essential that your GA tracking code is installed correctly for this to work properly.

GA tracks with first-party cookies. If you do not install this correctly, the cookies will be set incorrectly, have the wrong data in them, or both. More on this later…

Traditional (Synchronous) Tracking Code

Put the following code, replacing “UA-xxxxxx-x” with your account number, on ALL pages of your site and the shopping cart pages anywhere between the body tags but ABOVE any calls to pageTracker:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._setDomainName("none");
pageTracker._setAllowLinker(true);
pageTracker._trackPageview();
</script>

Links to the shopping cart when adding items to the cart, for example, must include onclick="pageTracker._link(this.href); return false;"

Forms that submit to the shopping cart must include onsubmit="pageTracker._linkByPost(this)"

Do not forget to put that on ALL forms if checkout is a multi-form (multi-step) process. Your data will be incorrect if you do not do this.

If your third-party cart already includes built-in GA code, follow their instructions exactly.

More on the traditional code installation of third-party shopping cart tracking from Google.

Asynchronous Tracking Code

Put the following code, replacing “UA-xxxxxx-x” with your account number, on ALL pages of your site and the shopping cart pages just above the closing head (</head>) tag:

 var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxx-x']);
  _gaq.push(['_setDomainName', 'none']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
  })();

Links to the shopping cart when adding items to the cart, for example, must include onclick="_gaq.push(['_link', 'https://your-cart.com/cart.html']); return false;"

Replace “https://your-cart.com/cart.html” with the actual link to your cart.

Forms that submit to the shopping cart must include onsubmit='_gaq.push(['_linkByPost', this]);'

Do not forget to put that on ALL forms if checkout is a multi-form (multi-step) process. You will data will be incorrect if you do this incorrectly.

Do not add the asynchronous tracking to third-party cart that have their own GA solution built-in unless specifically instructed to do so.

More on the asynchronous code installation of third-party shopping cart tracking from Google.

Why It’s Important to Do This Correctly

The cookies set by GA when the setDomainName parameter is set to “none” may in some cases have different HOST setting. That is, it may have a www.mydomain.com when the original code without the setDomainName may set HOST to just .mydomain.com. Or, worse still, you could lose all the visitor data and have the sale appear to have been referred from your site and nothing else.

This results in bad data coming into GA particularly in the referrer area. It probably disassociates your keywords to your sales as well.

Recommended Reading