How to Setup a Goal in Google Analytics with a Virtual Pageview

Google Analytics and Virtual Pageviews

We all know why we create goals in Google Analytics, it is to see conversions. What good is a click or a visit if you are trying to sell a product or service and the visitor doesn’t purchase your product, fill out your web form, or give you a call? Sure a lot of traffic is great to look at in Google Analytics, but if it doesn’t convert then you might as well be looking at a line graph sketched by a three year old. The standard convention for tracking a web form submission is to setup a goal in Google Analytics to look at your “Thank You” page to see if they hit it. While this still works 99% of the time, I will show you another method. We will be creating a virtual page view so that you don’t have to create an unnecessary 2nd page. Also, unless you set it up right, people might be hitting your thank you page and skewing your conversion data. I have seen a lot people accidentally index their “Thank You” page and then start ranking the page in Google.

In this example I will be using WordPress and the Contact Form 7 plugin.

Step 1

In WordPress, go down to the “Contact” section and click on “edit” on your form.

wordpress contact form 7

Step 2

Scroll down to the bottom and under the “Additional Settings” section add the following piece of code. Then hit save.

on_sent_ok:"_gaq.push(['_trackPageview', '/funnel_G1/complete.html']);"

virtual pageview

Step 3

Now we will go over to your Google Analytics account. On the top right-hand side click into “Admin.” Then click into “Goals.”

google analytics create goal

Step 4

Click on “Create a Goal” and then give it a name. In my example I am naming the goal “Web Form.” Then select “Destination” as the type. And click Next.

google analytics name goal

Step 5

In the Destination box put the following: /funnel_G1/complete.html And click on “Save Goal.”

google goal destination

Step 6

To view your Goals, go back to your Analytics account, go down to the “Overview” under Conversion Goals. Whenever someone fills out a form in Contact Form 7, they receive their message about successful submission, they aren’t posted to a separate page, and the javascript for the virtual pageview is run (meaning a completion of your goal).

google goal destination

Get More Advanced

You can also get a little more advanced with your form and goals. Below is an example of a dropdown with two different selections. And depending on the selection in the form they choose it registers a different virtual pageview (different goal).

on_sent_ok:"if(jQuery('#dropdown-1').val()=='Dropdown Selection 1'){_gaq.push(['_trackPageview', '/funnel_G1/complete.html']);}else if(jQuery('#dropdown-2').val()=='Dropdown Selection 2'){_gaq.push(['_trackPageview', '/funnel_G2/complete.html']);}else{}"

As always feel free to leave your comments below!

Get More Stuff Like This

Marketing, WordPress, Blogging Tips, SEO and Reviews, once a week.

Thank you for subscribing.

Something went wrong.

1 thought on “How to Setup a Goal in Google Analytics with a Virtual Pageview”

  1. Thanks for this. I have 2 questions

    1. You have used wordpress. What if we don’t have wp site ?
    2. What are the benefits of this method cpmpared to traditional method

    Many Thanks for this useful post

Leave a Comment