Display Views in the Google Analytics API

Using .NET MVC 3, I would like to display pageviews on every page of my site. I have Google Analytics installed.

I know there is an API, but I donโ€™t know where to start.

Any pointers to what I need, or rather, what should I look at to display pageviews?

+4
source share
1 answer

Create a file in your Views / Shared folder with the name _GoogleAnalytics.cshtml (using the underscore in the front is a method for specifying a partial view. It has no effect in MVC, it's just a practice that I see a lot in demo and screenshots.

Put your google analytic code in it. (do not forget to specify 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> 

Then on the _Layout.cshtml page add this line (if you are using Razor)

 @Html.RenderPartial("_GoogleAnalytics") 

Edit: Just re-read the question. It just occurred to me what you can look for, is it a tool to display only the hit counter using the data extracted from the Google Analytics API?

What if, in this case, I think I skipped this part. I did not do it myself, but can this be a good start? http://code.google.com/apis/analytics/docs/mgmt/mgmtFeedReference.html#profileFeed

+5
source

All Articles