简体   繁体   English

通过onclick按钮更新了Google Analytics(分析)事件跟踪

[英]Updated Google Analytics event tracking through onclick button

I have a form on my order page. 我的订单页面上有一张表格。 When the users click on the submit button the records is supposed to be the sessions that I can track in the google analytics event. 当用户单击“提交”按钮时,记录应该是我可以在Google Analytics(分析)事件中跟踪的会话。 However, the code is not working. 但是,该代码无法正常工作。 The code for my page is below: 我页面的代码如下:

       <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8" />
        <title>Keepsake Florals</title>
        <!--link to external css file-->

    <link rel="stylesheet" type="text/css" href="keepsakeflorals.css"/>
    <link rel="stylesheet" type="text/css" href="ksform.css" />
    <link rel="shortcut icon" href="favicon.ico" />
       <script src="scripts/jquery-1.11.3.min.js"></script>

          <script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-87810245-1', 'auto');
  ga('send', 'pageview');

</script>

        <!--[if lt IE 7]>
          <style type="text/css">
            #mainnav {left: 0px;}
            li img {left: -42px;}
          </style>
        <![endif]-->
        <!--[if IE]>
            <style type="text/css">
            legend span {top: 0;}
            legend {color: black;}
            #submit {position: relative; left: -80px;}
        </style>
          <![endif]-->
          <script>

    $('#contact-form').on('submit', function(event) {
      // Prevent the browser's default form submission action.
      event.preventDefault();

      ga('send', 'event', {
        eventCategory: 'Contact',
        eventAction: 'Information Request',
        eventLabel: 'Contact Form',
        hitCallback: function() {
          $('contact-form').trigger('submit');
        }
      });
    });

          </script>
    </head>
    <body>

    <div id="box">
    <h1><a href="index.html" title="click here to return home"> KEEPSAKE FLORALS </a> </h1>
    </div>

    <div>
    <nav id="mainnav"> 
    <a href="index.html"> Home</a> |
    <a href="aboutus.html"> About Us  </a> |
    <a href="flowers.html"> Flowers </a> |
    <a href="order.html"> Order </a> |
    <a href="review.html"> Review </a> |
    </nav>
    </div>



    <form action="thankyou.html" id="contact-form">

      <fieldset id="contactinfo">
      <legend> <span> Contact Information </span> </legend>
        <label> 
        Name
        <input type="text" name="name" id="nameinput" placeholder="First and last name"  />
        </label>
          <label>
          Email
          <input type="email" name="email" id="emailinput" placeholder="address@example.com" />
          </label>
          <label>
          Phone
          <input type="text" name="phone" id="phoneinput" placeholder="phone number" />
          </label>

         </fieldset>

            <fieldset id="orderflower">
              <legend> <span> Flowers to order </span> </legend> 
              <label for="mother" >
                 <input type="radio" name="flower" id="mother" value="mother" checked="checked"  />
                 Mother's day flower 
                 </label>
                     <label for="father">
                             <input type="radio" name="flower" id="father" value="father" />
                            Fathers day flower
                 </label>
                         <label for="otheroccasion">
                        <input type="radio" name="flower" id="occasion" value="occasion"  />
                        Other occasion flower
                                </label>

                 <label for="valentinesday">
                     <input type="radio" name="flower" id="vday" value="vday" />
                      Valentine's Day
                      </label>

                 <label for="others">
                    <input type="radio" name="flower" id="others" value="others"  />
                      Others

                      <input type="text" name="other" id="otherinput">
                      </label>    
                  </fieldset>
              <fieldset id="delivery">
              <legend> <span> How to contact you ? </span> </legend>
              <label for "question">
                  <input type="radio" name="flower" id="phone"  />
                     Via my handphone number
                     </label>
                      <label for "question">
                  <input type="radio" name="flower" id="email"  />
                     Via my email
                     </label>     
              </fieldset>
              <fieldset id="helpneeded" >

              <legend> <span> Any help needed? </span> </legend> 
              <textarea id="helpneeded" name="helpneeded" rows="4" cols="20"> </textarea>
              </fieldset>    
               <input type="submit" id="submit" value="Validate and Submit" onclick=”ga('send', 'event', 'form', 'submit', 'order sent', 10);”/>
    </form>
    </body>
    </html>

您没有在页面上的任何地方加载实际的Google Analytics(分析)JavaScript

First you must add Google Analytics on your page 首先,您必须在页面上添加Google Analytics(分析)

Check this link 检查此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM