Tracking firewalls and passes in Google Analytics?

I am going to collect page load speed data using Google Analytics and would like to split it between the pages that were returned using the Varnish HIT cache and those with the MISSED cache.

Before embarking on this issue, I just suggested that I get JS to look at the varnish headers in the response to the page and create a custom var var to track this for each page. Of course, JS does not have access to page titles, so I'm losing a little now. I did GA server-side tracking in the past (via php-ga), but this is necessary to bind to the real page load time.

+4
source share
1 answer

Just a thought, but you can set a cookie in the "vcl_deliver" routine. Something like that:

sub vcl_deliver { if (obj.hits > 0) { set resp.http.Set-Cookie = "VarnishHit=Yes;Path=/;"; } return (deliver); } 

It basically says: if obj has more than one hit, set a cookie by saying so. You will need to make sure that you do not write any other cookies, so maybe just connect this to your existing Set-Cookies if you use cookies. For more information about obj.hits objects, see here: https://www.varnish-cache.org/docs/3.0/reference/vcl.html

Here is the important line:

obj.hits The approximate number of times the object was delivered. A value of 0 indicates cache miss. This variable is also available in vcl_deliver.

This will give you access to this information from Javascript using the document.cookie variable. I believe jQuery has several plugins to make it easier, here is what I found: https://github.com/carhartl/jquery-cookie on Google. Once you can check for a cookie in JS, you can use the GA API to register the event. Hope this helps.

+1
source

Source: https://habr.com/ru/post/1446077/


All Articles