简体   繁体   English

在Mvc4 / C#中实现Google Analytics(分析)?

[英]Implementing Google Analytics in Mvc4/C#?

Im trying to implement Google Analytics in my mvc website. 我试图在我的MVC网站中实施Google Analytics(分析)。 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 . 首先,我尝试创建一个GA帐户,很遗憾,我正在本地主机上进行本地开发,该主机名不是有效的网站URL,但我发现了一个修补程序,有望在此工作http://www.objectpartners.com/2011/05/26/设置google-analytics-on-localhost /#comment-5960

Then i copied the generated JS tracking code and paisted it to a view. 然后,我复制了生成的JS跟踪代码并将其粘贴到视图中。 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. 但是我发现这篇有关使用NuGet包“ GoogleAnalyticsTracker”的文章( http://analyticsimpact.com/2011/01/20/google-analytics-on-intranets-and-development-servers-fqdn/ )应该可以帮助您使用.NET框架跟踪您的网站。 I followed these steps by adding the codeto a controller but the nothing is shown in the view. 我按照以下步骤将代码添加到控制器中,但是视图中未显示任何内容。

I guess one solution would be creating a new GA account, copy the JS tracking code and paiste it into /Views/Shared/_Layout.cshtml. 我想一种解决方案是创建一个新的GA帐户,复制JS跟踪代码,然后将其粘贴到/Views/Shared/_Layout.cshtml中。

Has annyone anny experiance implementing Google Analytics in a MVC4 application? annyone anny是否有在MVC4应用程序中实施Google Analytics(分析)的经验?

Thank you! 谢谢!

It's really as simple as: 真的很简单:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM