Kissmetrics Blog

A blog about analytics, marketing and testing

Built to optimize growth. Track, analyze and engage to get more customers.

How to Set Up Virtual Pageviews in Google Analytics (The Video)

In our last video, we went over how to set up conversion funnels in Google Analytics. Today, we continue and cover how to set up virtual pageviews. Virtual pageviews allow you to track:

  • Button, image and link clicks.
  • Video stops, pauses or volume changes.
  • How much of a video has been watched.
  • File downloads and basically any action a user can take on a webpage.

First we will simply go over how virtual pageviews work. Then we’ll move on and show you how to insert virtual pageview tracking into event handler code, so that you can learn how to do it on your own website.

More Resources

Video Transcription


Bryan: Hi, I’m Bryan with KISSmetrics, and I’m here to help you get the most out of your Google Analytics account.

Last week, we talked about sales funnels.

Today, I’m going to show you a cool trick that allows you to track and analyze how your users interact with the forms that are embedded on your website. First, I’ll introduce you to the concept of virtual page views, and then we’ll cover how to integrate these with conversion tracking funnels to give you greater insights into your site. So, let’s get going.

First, let’s talk about virtual page views. We all know how normal page view tracking works. First, you install the big, nasty block of code at the bottom of every page on your site, and then anytime a visitor comes to your site, that block of code recognizes it and registers that person as being a visitor on your site.

So, when you go to the back end of your Google Analytics reports, you can see how many visitors have come to your site. Virtual page views work exactly the same way, except with virtual page views you’re able to track anything that a user does on your site instead of just the fact that they visited the site at all.

So, let’s consider two examples to see what that looks like in real life. Suppose that you have a video embedded on your website. Normal page view tracking will tell you if a visitor has seen the page with the video, but it won’t tell you how many times the user has pressed the play button, the pause button, changed the volume, or how much of the video they have actually watched. All it will tell you is that a visitor has seen the page.

With virtual page views, we can change that. We can track each one of those things. We can know how many times they’ve played, how many times they’ve paused, the changing of the volume button, and the duration of the time that they have watched the video.

Or suppose that you have a file download on your site. The normal steps to download would be for a visitor to come to the page and then click a link or a button that automatically starts downloading that file. With normal page view tracking, the act of a user downloading the file would go untracked. However, we can track every instance of a user downloading a file as a page view with virtual page view tracking.

Those are the basics of how virtual page views operate. Now, let’s look at how to install them and set them up on your own website.

It’s actually fairly simple. Just like installing the main Google Analytics code, we’re going to take a predefined block of code and put it in each instance that we want to track. Now all you have to do is copy and paste it into whatever event handler that you want to use to initiate the page view.

So, if you want to track the play button, simply paste this code into the event handler that controls the play button, and every time a user clicks the play button it will be registered as a page view in your Google Analytics account.

You will need to modify this section of the code. This parameter gives the virtual page view a name, and this will be the name of the page that is reported in your page view tracking report.

All right, let’s do a quick recap. Now we know what virtual page views are. We know how to set ’em up and install them on our website. Now let’s look specifically at how to set them up inside of a form and then tie that form to a conversion tracking funnel so we can see where we can improve.

We’re going to start by looking at a basic form. To install virtual page view tracking into a form field, we’ll include the parameter onBlur=. onBlur is an event handler that is called when a visitor clicks the mouse or enters a keystroke outside of this field.

Next, we’ll look at the second section of this code. This part simply states that if the form field is not empty, then do whatever comes next. So, if the user has entered any data into this specific form field, then do the next part, but if he hasn’t, don’t do anything at all.

And then lastly, we’re going to paste in our virtual page view code that we looked at earlier and give this specific form field a name. Calling the trackPageView function with the corresponding field name generates a virtual page view for the completion of that field.

So, if somebody enters a value in there and then goes to the next section or clicks off of that section, as soon as they do that, that code sends a note to Google and says, “Hey, that was a page view. Count it as a page view,” and then you can see that page view in your Google Analytics reporting.

You don’t have to submit the form. All you have to do is fill out the form field, and then take the focus off of that form field, and this code registers that as a page view. Now, we’re simply going to do this for each field in the entire form [pause] and we’re all set up.

Now that all of our tracking code is installed, we can set up a conversion funnel to give us an easy to use report for how our users are interacting with the form. To do this, we’ll first go to Admin. Then we’ll select the property and profile for the site that we’re working on.

Next, choose Goals underneath the profile column. And now select Create a Goal, and then we will enter the name we want to use to refer to this funnel. For our purposes, we’ll call it the Contact Us funnel. We’ll now choose destination as the type and press Next Step.

The destination field will be the page name that we gave to our submit button. Since our submit button is the last item in this form, we want to track it as the goal. In our case, we named it “submit button,” so we’ll enter that here. Next, turn the funnel option to On. And now we’ll enter the URL for each field in our form in the order that they appear in the form. Then, lastly, press Create Goal, and we’re all done.

All right, that’s it! We’re all finished. We now know what virtual page views are, we’ve seen how to install them and set them up on our website, and we also know how to tie them to conversion funnels to track the interaction with forms on our website.

If you want to see the in depth reporting on your funnel, simply go to the funnel visualization report in the reporting section of your Google Analytic account. That’s it for this week. Happy virtual page viewing.

  1. Great video, but I for one would recommend setting up events for those actions, instead of “artificially” increasing pageviews… In your opinion are there situations when virtual pageviews are more recommended than events?

  2. I love the article!, My question is this is great for inline coding if you only have a few video or forms. What if you have many videos & pdf files? Do you have a good reference to writing a script that handles all these functions instead from inline?


  3. Please help, how can I activate this? I think I’m using a different version of Analytics :(

  4. Hi – great video, I also agree with Csilla Incze that these should really be used as event tracking rather than increasing page views when they are not.

    Google tag manager makes this really easy now.

  5. Kamlesh Nishad Nov 16, 2013 at 9:05 am

    Awesome post…. well explained.Thanks for sharing…

  6. Wow – great quick, helpful tip. Thanks.

  7. Michael McMahon Nov 17, 2013 at 8:49 am

    Unless KISS metrics only works with pageviews and not goals/events, I’m also confused about why you wouldn’t use events. Does anyone have any ideas about why you’d want to use virtual pageviews?

  8. Great post and really helpful video, thanks for it!

  9. Great article. Like most other people commenting, I am a little confused as to why you would use virtual page views for tracking video or file download rather than utilising the Event Tracking Function.

    However, your process for developing virtual page views for the form was interesting – is this your work-round for developing and managing form analytics?

  10. Siddharth Sharma Nov 18, 2013 at 4:39 am

    Wow! A Very Helpful post is here on Kiss Metrics blog! I’m glad to see this article here. because this will help me in Analytics too much.

    Thanks to share this awesome Tricks :)

  11. Hey guys,

    Good pickup on the Virtual Page View vs. Event tracking conundrum. There are pros and cons to using both.

    One of the big pros to using Virtual Page View is the ability to tie it to Funnel Tracking. This gives you super reporting into how your users are navigating through the form fields.

    Certainly this isn’t needed in every use case but it is one of the big reasons we use it in this instance.

    Here are three articles you can checkout that go into more detail on some of the nuances of which is better for your particular use case:

  12. Hey nice tutorial, but I am not sure why I got this problem. After following the tutorial and adding the fields to one of my forms about 5-10 minutes after that GA doesn’t track visits. The real time tracking stopped for the all the pages. Am I missing something or what?

  13. Hello, This video is something unique what i was looking for. This is really helpful for the Digital Marketing People. Goal-Funnel setup, Conversion setup – some of the important topics about Google Analytics. This Tutorial will really help the SEO people. Thanks for sharing and Keep it up! I have tweeted this to my followers.

  14. Dominic Hurst Mar 14, 2014 at 7:45 am

    Informative video guys. Virtual page views has it’s positives (can track something we previously didn’t) however id use event tracking to avoid skewed metrics

  15. Hello,

    Once all the code mentioned in the video is copied, how/where can I see on Google Analytics the keywords that users have typed on the form?

    Thanks and great article!

  16. Good morning!

    I have a question regarding your “How to Set Up Virtual Pageviews in Google Analytics” article. My website doesnt have a query parameter, in fact the URL for every keyword searched is /Search.

    I included all the javascript code in my .html page inside my input tag. My question is:

    When configuring the new Goal in Google Analytics, what do I have to type in the Destination input form? Is it the “form-field-data” name inside de _gaq.push()?

    Also, where exactly will I be able to see the Search terms once it is finally working?

  17. Hi,

    what about a situation when I want to fire a virtual pageview only when the form is submitted, that is when there is no error in the form? I want to be sure that a virtual pageview will be not fired when a user will click on the submit button, but only when the form will be submitted.

    Thanks in advance for suggestions.


  18. Hi,

    I have tried implementing this on one of my websites. but i can’t see the pageviews in Google Analytics.

    I am trying to track the number of applications we receive. Here is the code I have added (i was originally tracking it as an event, but once this funnel has been created, i will turn this off)

    _gaq.push([‘_trackEvent’, ‘Job application completed’, ‘click’, ‘Job application completed’]);_gaq.push(‘_trackPageview’,’Job-application-completed-PV’);

    Can some please help!?

  19. Hi,

    I am trying to implement virtual pageviews (to track affiliate link clicks) on my site but after following your advice I only found out that it is not working.
    I am using Universal analytics code but after code implementation on link and setting up goals there is no change whatsoever.

    Any advice?

  20. Hi, i am struggling to add a virtual page associate to a banner click, using Google Tag Manager, without access to the code. anybody can help?

  21. Hi! Thank you for this! I do have a question for this amazing way to track forms. What if I have more than 20 different forms with different field names in my website to track in Google Analytics, how can I track this since GA Goals can just cater 20 goals?

    Thanks for your help.

    Have a good day ahead.

  22. Is this still up to date?

  23. No, this code is outdated. Right now you should use
    ga(‘send’, ‘pageview’, ‘name-of-the-page’);

    I personally usually add vpv in front of the page so I can see virtual pageviews in Analtyics separately

    ga(‘send’, ‘pageview’, ‘/vpv/name-of-the-page’);


Please use your real name and a corresponding social media profile when commenting. Otherwise, your comment may be deleted.

← Previous ArticleNext Article →