Google Analytics API显示网页浏览量 [英] Google Analytics API display page views

查看:320
本文介绍了Google Analytics API显示网页浏览量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用.NET MVC 3,我想在我的网站的每个页面上显示页面浏览量。我有谷歌分析设置。

Using .NET MVC 3, I'd like to display page views on each page of my site. I have google analytics set up.

我知道有一个API,但不知道从哪里开始。

I'm aware there is an API, but have no idea where to start.

任何我需要的指针,更具体地说,显示页面视图时需要注意什么?

Any pointers for what I need, and more specifically what to be looking at for displaying page views?

推荐答案

创建一个名为_GoogleAnalytics.cshtml的视图/共享文件夹中的文件(使用前面的下划线是一种指示局部视图的方法,它在MVC中没有效果,这只是我在演示和屏幕演示中看到的很多做法。

Create a file in your Views/Shared folder called _GoogleAnalytics.cshtml (using the underscore in the front is a method of indicating a partial view. It has no effect in MVC, it's just a practice I see done a lot in demo's and screen casts.

将Google Analytics(分析)代码放入其中(确保从Google中输入您自己的标识符)

Put your google analytics code in it. (make sure to put in your own identifier from Google)

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-########-1']);
  _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>

然后在您的_Layout.cshtml页面中添加此行(假设您使用的是Razor)

Then in your _Layout.cshtml page add this line (assuming you are using Razor)

@Html.RenderPartial("_GoogleAnalytics")

编辑:只需重新阅读问题,我想到您可能正在寻找的是仅使用Google Analytics中提供的数据显示点击计数器的方法API?

Just re-read the question, It just occurred to me what you may be looking for is a means to display just the hit counter using data pulled from Google Analytics API?

如果是这种情况,我想我错过了那部分。我自己并没有这样做,但这可能是一个好的开始?
http://code.google.com/apis /analytics/docs/mgmt/mgmtFeedReference.html#profileFeed

Which if that's the case I think I missed that part. I've not done this myself but this may be a good start? http://code.google.com/apis/analytics/docs/mgmt/mgmtFeedReference.html#profileFeed

这篇关于Google Analytics API显示网页浏览量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆