Difference between revisions of "Functions:googleTrack"

From Whirlwind eCommerce Wiki
Jump to: navigation, search
(added $pageCode)
Line 3: Line 3:
  
 
== Syntax ==
 
== Syntax ==
$string = eV::googleTrack($trackerCode);
+
$string = eV::googleTrack($trackerCode,$pageCode=NULL);
  
 
== Paramaters ==
 
== Paramaters ==
 
*$trackerCode STRING
 
*$trackerCode STRING
 
:: The unique tracking id assigned by Google to track your site. Will be in the format "UA-1234567-1".
 
:: 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 ==
 
== Return Values ==
Line 20: Line 22:
 
try {
 
try {
 
var pageTracker = _gat._getTracker("UA-1234567-1");
 
var pageTracker = _gat._getTracker("UA-1234567-1");
pageTracker._trackPageview();
+
pageTracker._trackPageview("/pageCode/Override/if/specified");
 
} catch(err) {}
 
} catch(err) {}
 
</script>
 
</script>
 
</pre>
 
</pre>
  
== Example ==
+
== Examples ==
 +
;Basic example
 
<source lang="php">
 
<source lang="php">
 
echo "<html>";
 
echo "<html>";
Line 37: Line 40:
 
// display googleTrack code
 
// display googleTrack code
 
echo eV::googleTrack('UA-1234567-1');
 
echo eV::googleTrack('UA-1234567-1');
 +
 +
echo "</body>";
 +
echo "</html>";
 +
 +
</source>
 +
 +
;Example using pageCode override
 +
<source lang="php">
 +
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 "</body>";

Revision as of 13:09, 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