すでにRoute53を使用していて、異なるタッキングコードを別々にトラッキングしても問題がなければ、サーバーサイドコードを少し使ってそのIDの正しいトラッキングコードを選択できます。以下は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>
しかし、1つのトラッキングコードを使用してカスタム変数をサーバー名またはipに設定する方がずっと簡単です。これは後でレポートでフィルタとして使用できます。
<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>