Implementing Google Analytics in Mvc4 / C #?

I am trying to implement Google Analytics on my mvc website. At first I tried to create a GA account, unfortunately, I am developing locally on localhost, which is not a valid site URL, but I found a fix that I hope will work here http://www.objectpartners.com/2011/ 05/26 / setting-up-google-analytics-on-localhost / # comment-5960 .

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

I assume that one of the solutions will create a new GA account, copy the JS tracking code and pass it to / Views / Shared / _Layout.cshtml.

Is it possible to nullify the experience of implementing Google Analytics in an MVC4 application?

Thanks!

+7
c # asp.net-mvc google-analytics nopcommerce
source share
1 answer

It's really that simple:

  • Create a partial view named GoogleAnalytics
  • Copy and paste the JavaScript code to track Google Analytics from Google.
  • Use @{ Html.RenderPartial("GoogleAnalytics"); } @{ Html.RenderPartial("GoogleAnalytics"); } in the template used by all pages
  • Publishing a site
  • Wait 24 hours for statistics to appear.

This is my organized approach, however you can put it anywhere while the code is visible on every page that you want to track.

+29
source share

All Articles