Difference between revisions of "Functions:googleTrack"
From Whirlwind eCommerce Wiki
(→Return Values) |
|||
Line 14: | Line 14: | ||
<pre> | <pre> | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
− | var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); | + | 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> | ||
Line 28: | Line 27: | ||
== Example == | == Example == | ||
<source lang="php"> | <source lang="php"> | ||
− | echo "<html> | + | echo "<html>"; |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | "; | + | |
+ | echo "<head>"; | ||
+ | echo "<title>$metaTitle</title>"; | ||
+ | echo "</head>"; | ||
+ | |||
+ | echo "<body>"; | ||
+ | echo $copy; | ||
+ | // display googleTrack code | ||
echo eV::googleTrack('UA-1234567-1'); | echo eV::googleTrack('UA-1234567-1'); | ||
− | echo "</body></html>"; | + | |
+ | echo "</body>"; | ||
+ | echo "</html>"; | ||
</source> | </source> |
Revision as of 14:34, 29 May 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);
Paramaters
- $trackerCode STRING
- The unique tracking id assigned by Google to track your site. Will be in the format "UA-1234567-1".
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(); } catch(err) {} </script>
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>";