propellerads adcombo
Dismiss Notice
Welcome to Our Community
Wanting to join the rest of our members? Feel free to sign up today.

Tracking Clicks And Viewport Width/Height With Some jQuery Code

Discussion in 'Guides, Case Studies and Tutorials' started by michael pehl, Jul 25, 2014.

  1. michael pehl

    michael pehl Get your fix Ninja! affiliate

    62
    21
    8
    trackingclicks.jpg
    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: Aug 29, 2014

Featured Resources (View All)

adsxposed