I’m loving Varnish, I have a bit of a problem though.
I’m counting pageviews for some resource on my site. Pageviews increment are limited via session in order not to count multiple views for each user.
I’ve made some tweakings to the varnish conf and the cache would work neatly, but unluckily my previous counter will be nullified until the page will expire (and the pageviews in between lost like tears in the rain).
do you have any idea of how i could keep this feature?
i thought about an Ajax call, but that isn’t the best option.
is there another way to do it that you can thing of?
thanks!
Google Analytics Event Tracking
I would simply allow Google Analytics to track the events. This allows you to track unique visits to the resource. I have implemented this with great success on many sites.
Documentation
category (required)
The name you supply for the group of objects you want to track.
action (required)
A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.
label (optional)
An optional string to provide additional dimensions to the event data.
value (optional)
An integer that you can use to provide numerical data about the user event.
There are more details on the Event Tracking Guide page.
Examples
Is implemented as javascript calls in the page like so:
Google Analytics Data Export API
To retrieve the data you can use the Google Analytics Data Export API. The API allows you to narrow the returned statistics for certain
filters.In your case you are interested in the following filters:
So you could narrow it down with something like:
Which translates to:
You can even try it out with the API explorer in the documentation.