Editor's note:
Thanks for visiting GA Tip of the Day. All of my newer posts are published on the E-Nor blog. Please visit and sign up for updates.
- Eric Fettman

Use JavaScript setTimeout() to Create Time-on-Page Goal

Creating a Google Analytics goal for time on a specific page poses two challenges:

• Although you can create a goal for time on site, there is no built-in goal option for time on a specific page (or for any other page-level metric apart from pageview).

• Google Analytics calculates time on page A only when page B is viewed, since it compares the page B timestamp to the page A timestamp to make this calculation. This prevents any last-page-in-visit from generating a time on page. Of course, as mentioned above, this is moot for goal tracking, since you cannot directly define a goal based on a page metric such as time on page.

The solution is the very useful and straightforward setTimeout() JavaScript function that you can use with an event or virtual pageview call.

For instance, to generate a goal after one minute of visitor time on a detailed product page, you can use the following code:

setTimeout("_gaq.push(['_trackEvent', 'time-on-page', '1-minute'])",60000);

After a delay of 60000 milliseconds, or one minute, this code would generate an event that counted towards any corresponding Event goal. Instead of _trackEvent, you could call _trackPageview as a virtual pageview, which would count towards any corresponding URL Destination goal.

For another use of setTimeout() in Google Analytics, see "Adjusted" Blog Bounce Rate with Customized Tracking Code.

Please share this post:
Facebook Twitter Plusone Linkedin Email

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>