Reputation: 642
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
Upvotes: 0
Views: 5079
Reputation: 32532
By default, the on-page GA code snippet will record the URL, minus protocol and domain. That means if you have
www.example.com/events?eventId=1234
vs.
www.example.com/events?eventId=4567
You will see 2 separate entries in your pages reports:
/events?eventId=1234
/events?eventId=4567
So out-of-the-box you should be good to go.
However...one issue you brought up in a comment:
does it work even if there are other parameters as well?
Yes it will, and that presents a problem. Because these 2 will also count as 2 separate entries:
www.example.com/events?eventId=123&a=b
www.example.com/events?eventId=123&a=c
In order to get around this, you will need to as tszming mentioned in his answer: track with a custom event (or custom variable), or else override the default page name with something of your choice. Or you can do both; each method is basically a different way of looking at the same basic data, and allows you to do slightly different things. But for answering your basic question of "how many people went to {eventId} version of the page, all of the options will answer that.
sidenote: in any case, all of these solutions involve getting a query string param. GA does not have a built in method for grabbing a query string parameter value, so you will have to grab that value yourself. Unfortunately, javascript does not have a built in way of doing it either. Fortunately, it's pretty easy to write a function that will do it for you (just google "javascript get query param").
Upvotes: 1
Reputation: 2084
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
Upvotes: 2