在 Mvc4/C# 中实现 Google Analytics? [英] Implementing Google Analytics in Mvc4/C#?

查看:27
本文介绍了在 Mvc4/C# 中实现 Google Analytics?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 mvc 网站中实施 Google Analytics.首先,我尝试创建一个 GA 帐户,不幸的是我在本地本地开发,这不是一个有效的站点 URL,但我找到了一个修复程序,希望在这里工作 http://www.objectpartners.com/2011/05/26/setting-up-google-本地主机分析/#comment-5960.

Im trying to implement Google Analytics in my mvc website. First i tried creating a GA account, unfortunately i'm developing locally on localhost which isn't a valid site URL but i found a fix that will hopefully work here http://www.objectpartners.com/2011/05/26/setting-up-google-analytics-on-localhost/#comment-5960.

然后我将生成的 JS 跟踪代码复制并粘贴到视图中.但是我发现这篇文章(http://analyticsimpact.com/2011/01/20/google-analytics-on-intranets-and-development-servers-fqdn/) 关于使用 NuGet 包GoogleAnalyticsTracker"的信息,应该让您通过使用.NET 框架.我按照这些步骤将代码添加到控制器,但视图中没有显示任何内容.

Then i copied the generated JS tracking code and paisted it to a view. However i found this article (http://analyticsimpact.com/2011/01/20/google-analytics-on-intranets-and-development-servers-fqdn/) about using NuGet package "GoogleAnalyticsTracker" whitch is supposed to let you track your site by using .NET framework. I followed these steps by adding the codeto a controller but the nothing is shown in the view.

我想一种解决方案是创建一个新的 GA 帐户,复制 JS 跟踪代码并将其粘贴到/Views/Shared/_Layout.cshtml 中.

I guess one solution would be creating a new GA account, copy the JS tracking code and paiste it into /Views/Shared/_Layout.cshtml.

大家有没有在 MVC4 应用程序中实现 Google Analytics 的经验?

Has annyone anny experiance implementing Google Analytics in a MVC4 application?

谢谢!

推荐答案

其实很简单:

  1. 创建一个名为 GoogleAnalytics 的局部视图
  2. 复制&粘贴来自 Google 的 Google Analytics(分析)跟踪 JavaScript 代码
  3. 使用@{ Html.RenderPartial("GoogleAnalytics");} 在所有页面使用的模板中
  4. 发布网站
  5. 等待 24 小时以显示统计信息
  1. Create a partial view named GoogleAnalytics
  2. Copy & Paste the Analytics tracking JavaScript code from Google
  3. Use @{ Html.RenderPartial("GoogleAnalytics"); } in a template which is used by all pages
  4. Publish the site
  5. Wait 24 hours for statistics to appear

这是我的有组织的方法,但是您可以将其放在任何位置,只要代码在您要跟踪的每个页面上都可见.

This is my organised approach however you can put it in any location as long as the code is visible on every page you want to track.

这篇关于在 Mvc4/C# 中实现 Google Analytics?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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