Manage Google Analytics Account in One Place


I have 6 websites (all put on the same VPS), and I would like to manage all 6 google analytics account in one place instead of using the account variables in different page. So this is simple, just create a PHP file that is accessible from all website document roots. for example, /home/googleana.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  $google_ana['steakovercooked.com'] = 'UA-XXXX';
  $google_ana['rot47.net'] = 'UA-XXXX';
  $google_ana['helloacm.com'] = 'UA-XXXX1';
  $google_ana['codingforspeed.com'] = 'UA-XXXX';
  $google_ana['uploadbeta.com'] = 'UA-XXXX';
  $google_ana['justyy.com'] = 'UA-XXXX';
  $current_domain = strtolower($_SERVER['HTTP_HOST']);
  $google_ana_id = $google_ana[$current_domain];
 
  function insert_google_ana() {
    global $google_ana_id;
    echo "
       <script language='Javascript'>\n
      
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '$google_ana_id']);
_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>
    ";
  }
  $google_ana['steakovercooked.com'] = 'UA-XXXX';
  $google_ana['rot47.net'] = 'UA-XXXX';
  $google_ana['helloacm.com'] = 'UA-XXXX1';
  $google_ana['codingforspeed.com'] = 'UA-XXXX';
  $google_ana['uploadbeta.com'] = 'UA-XXXX';
  $google_ana['justyy.com'] = 'UA-XXXX';
  $current_domain = strtolower($_SERVER['HTTP_HOST']);
  $google_ana_id = $google_ana[$current_domain];

  function insert_google_ana() {
    global $google_ana_id;
    echo "
       <script language='Javascript'>\n
      
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '$google_ana_id']);
_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>
    ";
  }

Then for the pages that require the google analytics, just simple call:

1
2
3
4
<?php
  require_once("/home/googleana.php");
  insert_google_ana();
?>
<?php
  require_once("/home/googleana.php");
  insert_google_ana();
?>

Actually, with slight modifications, this can be applied to google adsense, or other similar usages.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
272 words
Last Post: How to Show Chart Statistics of Monthly Number of Posts in WordPress?
Next Post: Correctly Serving SSL Certificate for Multiple Domains on the Same Server if You have Multiple IPs

The Permanent URL is: Manage Google Analytics Account in One Place

Leave a Reply