Search code examples
google-analyticsgoogle-analytics-api

Google Analytics Simple visitors count


I am new to GA and I have the following scenario: I have a website that does not require the GA services at all except for one page. This page's URL something like this: http://example.com/events?eventId=1234

What I try to achieve is to count the visitors for the different events specified in the parameter. (So later I can retrieve this information and I can show how many people visited a particular event's site).

I have been looking at https://www.google.com/analytics for a while however I could not figure out how to make the GA distinguish by the parameters. So far I registered at GA and I have the unique code and I can include this to the page:

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

Additionally this web application is implemented with Play framework


Solution

  • You can use event tracking or just log a virtual pageview

    e.g.

    _gaq.push(['_trackPageview', '/events/{id}']);
    

    Replace the {id} with the actual id