Google Pageview Update When Content is ‘Inview’

jquery_black

I was asked to write up some code on a dynamic website so that as the page scrolls it fires a new pageview update with Google. This is done a variety of different ways but I found that using ‘inview’ was the most effective way of doing so.

To use is easy download the inview jquery plugin

The code below goes in your header of your wordpress site and what it does is it waits until a

tag with a class of ‘inview’ appears on the page and as soon as it does it fires a Pageview update with Google. Works great for infinitely loading pages.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
  $('p.inview').one('inview', function (event, visible) 
  {
    if (visible) 
	{
     
	  _gaq.push(['_trackPageview']);
    }
  });
});
</script>

Then to fire the code all you need to do is past this where you want the inview event to fire.

<p class='inview'></p>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s