Adding an GA event tracking to PHP submit button

Discussion in 'Google Analytics' started by faizzsheikh, Oct 29, 2014.

  1. #1
    I am not an experienced coder/developer. I want to add an Google Analytics event tracking to the websites contact form submit button. Below is the exact php code of the contact form, can someone please update this code with event tracking parameters so I will just copy it from here and paste in the webpage.

    <form id="contact" action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
                                <div>
                                    <input class="text_box full_name" name="full_name" placeholder="Name" type="text" value="" />
                                </div>
                                <div>
                                    <input class="text_box phone" name="phone" placeholder="Phone" type="text" value="" />
                                </div>
                                <div>
                                    <textarea name="message" placeholder="Message" value=""></textarea>
                                </div>
                                <div>
                                    <input class="text_box email" name="email" placeholder="Email" type="text" value="" />
                                </div>
                                <div>
                                    <input class="bnt_send btn btn-1 btn-1a" name="send" type="submit" value="Send" />
                                </div>
                            </form>
                            <script type="text/javascript">
                                $(document).ready(function(){
                                    $('#contact').submit(function(event){
                                        if(quote_check() == 0) {
                                            event.preventDefault();
                                        }
                                    });
                                });
                                function quote_check(){
                                    var quote_check = 0;
                                    if($('.full_name').val() == ''){
                                        $('.full_name').addClass('ErrorValidate');
                                        quote_check = 1;
                                    }
                                    else{
                                        $('.full_name').removeClass('ErrorValidate');
                                    }
                                   
                                    if($('.phone').val() == ''){
                                        $('.phone').addClass('ErrorValidate');
                                        quote_check = 1;
                                    }
                                    else{
                                        $('.phone').removeClass('ErrorValidate');
                                    }
                                   
                                    if($('.email').val() == ''){
                                        $('.email').addClass('ErrorValidate');
                                        quote_check = 1;
                                    }
                                    else{
                                        $('.email').removeClass('ErrorValidate');
                                    }
                                   
                                    if(quote_check == 1) return false;
                                }
                            </script>
                            <?php
                                if(isset($_POST["send"])){
                                    $rs_name = $_POST['full_name'];
                                    $rs_phone = $_POST['phone'];
                                    $rs_message = $_POST['message'];
                                    $rs_email = $_POST['email'];
                                   
                                    $to = 'contact@lemontreeexhibition.com';
                                    $subject = "Email contact form " .$rs_name;
                                    $txt = "";
                                    $txt .= "Name: " .$rs_name. "\n";
                                    $txt .= "Phone: " .$rs_phone. "\n";
                                    $txt .= "Message: " .$rs_message. "\n";
                                    $txt .= "Email: " .$rs_email. "\n";
                                   
                                    $headers = "From: " .$rs_email;
                                    mail($to,$subject,$txt,$headers);
                                }
                            ?>
                        </div>
                    </div>
                </div>
    PHP:

     
    faizzsheikh, Oct 29, 2014 IP