小赖子的英国生活和资讯

在同一个地方管理 所有 google analytic 帐号

阅读 桌面完整版

我已经把6个网站全部都移动到同一台VPS上, 这样为了更好的管理 GOOGLE ANA帐号 可以在所有网站目录都可以访问得到的一个公共目录下 如: /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>
    ";
  }

存上不同网站的 帐号 这样只需要用的时候只需要 调用:

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

即可. 这样的好处是在同一个地方就可以管理所有的帐号 当然同样的 稍做修改 就可以应用到 google adsense 或者其它类型的代码上.

英文: https://helloacm.com/manage-google-analytics-account-in-one-place/

强烈推荐

微信公众号: 小赖子的英国生活和资讯 JustYYUK

阅读 桌面完整版
Exit mobile version