Difference between revisions of "Functions:googleTrack"

From Whirlwind eCommerce Wiki
Jump to: navigation, search
(added $pageCode)
 
Line 16: Line 16:
 
<pre>
 
<pre>
 
<script type="text/javascript">
 
<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"));
+
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>
  

Latest revision as of 13:10, 17 June 2009

Description

eV::googleTrack() returns tracking code for google analytics. If used, echo the returned value before the </body> tag.

Syntax

$string = eV::googleTrack($trackerCode,$pageCode=NULL);

Paramaters

  • $trackerCode STRING
The unique tracking id assigned by Google to track your site. Will be in the format "UA-1234567-1".
  • $pageCode STRING OPTIONAL
Argument to specify a name for the event. By default Google will track the event using the URL - this argument allows you to override that default and enter your own event specification, such as "/checkout/shipaddress.html".

Return Values

Returns a String containing the complete javascript, including the <script> and </script> bounding tags. Example of returned value is below:

<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-1234567-1");
	pageTracker._trackPageview("/pageCode/Override/if/specified");
	} catch(err) {}
</script>

Examples

Basic example
echo "<html>";
 
echo "<head>";
echo "<title>$metaTitle</title>";
echo "</head>";
 
echo "<body>";
echo $copy;
// display googleTrack code
echo eV::googleTrack('UA-1234567-1');
 
echo "</body>";
echo "</html>";
Example using pageCode override
echo "<html>";
 
echo "<head>";
echo "<title>$metaTitle</title>";
echo "</head>";
 
echo "<body>";
echo $copy;
// set pageCode
// tell system to send the fuseaction as the override pageCode 
// if the fuseaction is anything other than PAGE.view
$pageCode = ($attributes['fa'] == 'PAGE.view') ? NULL : $attributes['fa'];
// display googleTrack code
echo eV::googleTrack('UA-1234567-1',$pageCode);
 
echo "</body>";
echo "</html>";


See Also