If you already use Route53 and do not mind tracking different binding codes separately, you can use the server-side code bit to select the correct tracking code for this identifier. Here is an example in PHP.
<?php var $serverIp_trackingCodes_map = array( '192.168.1.1' => 'UA-XXXXX-1', '192.168.1.2' => 'UA-XXXXX-2', '192.168.1.3' => 'UA-XXXXX-3', '192.168.1.4' => 'UA-XXXXX-4' ); ?> <script type="text/javascript"> //The usual ga tracking code var _gaq = _gaq || []; //Pass in the tracking code for that server _gaq.push(['_setAccount', '<?php echo $serverIp_trackingCodes_map[ $_SERVER["SERVER_ADDR"] ] ?>']); _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>
But it would be much easier to use a single tracking code and set a custom variable with the name of the server or ip. This can later be used as a filter in reports.
<script type="text/javascript"> //The usual ga 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'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); //Set the custom variable _gaq.push(['_setCustomVar', 1, 'ServerIP','<? echo $_SERVER["SERVER_ADDR"]?>']); </script>
Chris gunawardena
source share