我是否需要通过互联网运行的网站才能使用Google API访问Google分析数据

时间:2012-09-29 03:45:01

标签: javascript google-analytics google-api

我是Google分析API的新手。我想使用其API访问我的Google Analytics数据。我有一个本地网站,通过局域网部署在IIS上。使用此设置可以使用其API访问Google Analytics数据,或者我需要一个通过互联网运行的网站。如果是的,请建议如何使用javascript完成。

1 个答案:

答案 0 :(得分:0)

Google Analytics(分析)的工作原理是,只要有人访问您的HTML网页(不需要在网络上),就会向Google服务器发送信息。但是,您需要访问互联网才能将数据发送到Google服务器。如果您在Google Analytics上设置帐户,则可以跟踪任何“网站”,只需将以下代码添加到您希望跟踪的任何网页(在</head>标记之前,如Google所说):

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'TrackingID']);
  _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>

TrackingID必须替换为您的Google Analytics帐户的跟踪ID。