M
michael pehl
Guest
Tracking Clicks And Viewport Width/Height With Some jQuery Code
Hi there, just thought I could give you some more of my useful codes.
Requirements:
jQuery Javascript Library
Google Analytics added to your website
Tracking the viewport width & height of your site visitors can be a very imporant information regarding your content!
Code
Here are the jQuery lines I am using:
Code:
/* find out viewport dimensions */
function tellviewport() {
var viewportwidth = $(window).width();
var viewportheight = $(window).height();
// send event to Google Analytics
ga('send', 'event', 'viewport', viewportwidth+'x'+viewportheight+' pixels');
}
tellviewport();
Tracking links on your website is also very imporant.
Here are the jQuery lines I am using:
Code:
$(".ptcsite a").on("click", function(){
var label = $(this).attr("href");
ga('send', 'event', 'banner or link', 'clicked', label);
});
That's all.
Very useful when you are using "Realtime Overview" in Google Analytics... you will get the information within some seconds
Michael
Last edited by a moderator: