The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

Track Window Resizes through Google Analytics

Last updated on:

Sparkbox has this snippet to help figure out how often browser windows really are resized.

(function() {
  var resizeTimer;
  // Assuming we have jQuery present
  $( window ).on( "resize", function() {
    // Use resizeTimer to throttle the resize handler
    clearTimeout( resizeTimer );
    resizeTimer = setTimeout(function() {

     /* Send the event to Google Analytics
      * _trackEvent(category, action, opt_label, opt_value, opt_noninteraction)   
      var $window = $( window );
      _gaq.push( [ "_trackEvent", "User Actions", "Browser Resize", $window.width() + " x " + $window.height() ] );
    }, 1000);

Note how easy it is to track events in Google Analytics. That can be used for just about anything.


  1. TJ
    Permalink to comment#

    Pretty cool idea. Is there any reason you wouldn’t cache $(window) up with resizeTimer?

  2. agence web strasbourg
    Permalink to comment#

    Pretty cool yes but for which purpose do you track such events?

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed