Title: Adding Google Analytics Tracking Code
Last modified: November 6, 2017

---

# Adding Google Analytics Tracking Code

 *  Resolved [jamesbester](https://wordpress.org/support/users/jamesbester/)
 * (@jamesbester)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/adding-google-analytics-tracking-code-3/)
 * Hi, I’m trying to add Google Analytics goal/event tracking code to this form,
   but I can’t seem to find the right place to put it. I’ve tried putting it inbetween
   the <button> </button> tags on the vscf-form.php but it causes a fatal error 
   and I’m nervous to try anything else at this point in case I break it again!

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/adding-google-analytics-tracking-code-3/#post-9656092)
 * Hi,
 * Whole form is executed on the same page. So what you’re trying to achieve will
   not work, I guess. But I might be wrong of course.. What did you try?
 * Guido
 *  Thread Starter [jamesbester](https://wordpress.org/support/users/jamesbester/)
 * (@jamesbester)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/adding-google-analytics-tracking-code-3/#post-9656123)
 * Hi,
 * The code I put in on the vscf-form.php file was:
 * <button type=”submit” name=”vscf_send” id=”vscf_send” class=”btn btn-primary”
   >’.esc_attr($vscf_atts[‘label_submit’]).’ .onClick=”ga(‘send’, ‘event’, { eventCategory:‘
   Contact Us’, eventAction: ‘Send’});”</button>
 * I’m not really great at PHP, but from what I could see that was the piece of 
   code that generates the button itself, so by putting the onClick code within 
   it would hopefully make it work.
 * I guess I could try wrapping it around the button in <script> tags if you think
   that’d work? I’m hesitant to try making too many changes too often as the site
   is live and the client is using it.
 * James
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/adding-google-analytics-tracking-code-3/#post-9656525)
 * Hi James,
 * My javascript knowledge is limited, what’s the purpose of this?
 * If you want a redirect to a thank you page, please check [this reply](https://wordpress.org/support/topic/submit-query-param/#post-8590811)
   in another thread. Is this what you want perhaps?
 * Guido
 *  Thread Starter [jamesbester](https://wordpress.org/support/users/jamesbester/)
 * (@jamesbester)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/adding-google-analytics-tracking-code-3/#post-9656598)
 * Hi Guidi,
 * It’s to track an event goal in Google Analytics. So when people click on the 
   submit button, it sends a ‘signal’ through to Google Analytics so we can see 
   that someone has submitted a form.
 * I didn’t know you could redirect it to another URL when you submit the form, 
   so that might help, so I’ll look into that as well.
 * James
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/adding-google-analytics-tracking-code-3/#post-9657146)
 * If you want this, you should change file vscf-form (and for widget file vscf-
   widget-form).
 * Open file vscf-form and remove line 232:
 *     ```
       return $anchor_begin . '<p class="vscf-info">'.esc_attr($result).'</p>' . $anchor_end;
       ```
   
 * Add this instead:
 *     ```
       $page = home_url('/?page_id=222'); 
       echo '<script type="text/javascript">'; 
       echo 'window.location="'.$page.'";'; 
       echo '</script>';
       ```
   
 * Create a thank you page and add the page ID in code above (where “222” is).
 * Now you can use your Google code on that thank you page.
 * Guido
 *  Thread Starter [jamesbester](https://wordpress.org/support/users/jamesbester/)
 * (@jamesbester)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/adding-google-analytics-tracking-code-3/#post-9658587)
 * Excellent, that worked fantastically, thank you! 🙂
 *  Plugin Author [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/adding-google-analytics-tracking-code-3/#post-9660796)
 * Great to hear this works for you!
 * Guido

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Adding Google Analytics Tracking Code’ is closed to new replies.

 * ![](https://ps.w.org/very-simple-contact-form/assets/icon-256x256.png?rev=1415751)
 * [VS Contact Form](https://wordpress.org/plugins/very-simple-contact-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/very-simple-contact-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/very-simple-contact-form/)
 * [Active Topics](https://wordpress.org/support/plugin/very-simple-contact-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/very-simple-contact-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/very-simple-contact-form/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Guido](https://wordpress.org/support/users/guido07111975/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/adding-google-analytics-tracking-code-3/#post-9660796)
 * Status: resolved