I'm attempting to use Gogole Analytics event tracking to track browser viewport size.

I'm using event tracking already in a bunch of other user-initiated places with jQuery and everthing works fine. This doesn't seem to be working though:

I have this at the bottom of my html page:

<script type="text/javascript">
<!--
    $(function() {
        _gaq.push(['_trackEvent', 'Viewport Width', $(window).width(), $(window).width() + 'x' + $(window).height(), 0, true]);
        _gaq.push(['_trackEvent', 'Viewport Height', $(window).height(), $(window).width() + 'x' + $(window).height(), 0, true]);       
    });
//-->
</script>

Not quite sure why nothing is being registered in Google Analytics. Half the day and nothing tracked. Also, Google analytics has Real-Time event reporting and I'm seeing other events come in but not these.

Not sure if it helps, this one has the parameters in a different order.

I think you have the wrong link there :)

Parameter order shouldn't matter though since it's freeform, but interested to see the link u've got for me.

I was just able to et this to work:

<script type="text/javascript">
<!--
    $(function() {
        var viewport_width = $(window).width();
        var viewport_height = $(window).height();
        _gaq.push(['_trackEvent', 'Viewport Dimensions', 'Viewport Width', viewport_width + 'x' + viewport_height, viewport_width, true]);
        _gaq.push(['_trackEvent', 'Viewport Dimensions', 'Viewport Height', viewport_width + 'x' + viewport_height, viewport_height, true]);
    });
//-->
</script>

Interesting. So the functions are not resolved, but with variables it works?

I think it perhaps didn't like numbers in the thrid parameter? I'm really not sure.

have you tried screen.width & screen.height
or document.width, document.height ?

or even top.document.width...

No because I stuck with jQuery and it's all working. Fetching the dimensions was never the issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.