Is there a way to implement the Google Analytics (GA) code snippet functionality in PHP?
Basic GA web page tracking requires insertion of the following JavaScript code snippet right before the </head> tag:
Code: Select all
<script type="text/javascript">
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';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
For example, imagine a set of URL's as follows:
http://www.example.com/coffee/colombia
http://www.example.com/coffee/kenya
http://www.example.com/coffee/costa_rica
Each of them log a visit via the GA code snippet before redirecting the user to http://www.coffee.com/. How can I implement the GA code using PHP before sending them to the new site via the header() command?
Thanks for your help!
Love, tangoking