15 Replies Latest reply on Nov 10, 2016 11:12 AM by Sanford Whiteman

    Issue with Submitting marketo forms with events in GA

    Manish Khemani

      Hello There,

       

      I have created a Marketo Form and inserted its embed code in the (External) Landing page

      http://sites.tcs.com/marketo-form-test/

       

      Also, I have added code for from validation - to restrict any personal email ids i.e. gmail, hotmail, etc. - This is working fine.

       

      We also need a ga event (ga('send', 'event', 'Download', 'Click', 'GTS-2016-Download');) fired on Successful form fill; for this we have used the onSuccess handler, But the event is NOT firing; Attaching the code used in Title of the document below: Could Anyone guide what is that We are doing Wrongly to not fire the Event. We have implemented GA code via GTM in the head section of the page.

      -------------------------------------------------------------------------------

       

      <form id="mktoForm_3683">

      <div style="margin-left:275px; margin-bottom:10px;">

      <script src="https://www.linkedin.com/autofill/js/autofill.js" type="text/javascript" async></script><script type="IN/Form2" data-form="mktoForm_3683" data-field-firstname="FirstName" data-field-lastname="LastName" data-field-phone="MobilePhone" data-field-email="Email" data-field-company="Company" data-field-title="Title"></script>

      </div></form>

      <br>

      <link type="text/css" rel="stylesheet" href="form2.css" />

      <script>MktoForms2.loadForm("//app-sji.marketo.com", "120-PTN-868", 3683, function (form){MktoForms2.lightbox(form).show();});</script>

      <script>

      (function (){

        var invalidDomains = ["@gmail.","@yahoo.","@hotmail.","@live.","@aol.","@outlook."];

       

       

        MktoForms2.whenReady(function (form){

        form.addHiddenFields({

          ReferringSite : document.referrer

        });

          form.onValidate(function(){

            var email = form.vals().Email;

            if(email){

              if(!isEmailGood(email)) {

                form.submitable(false);

                var emailElem = form.getFormElem().find("#Email");

                form.showErrorMessage("Please use your business email. Thank you!", emailElem);

              }else{

                form.submitable(true);

              }

            }

          });

        /* --------------------------------------------- */

        form.onSuccess(function (values, url){

        /////var url ="https://www.google.com" (https://www.google.com%27) ;

       

       

        //alert("VAL :"+values);

        //alert("URL :"+url);

                          // Send a "Event" to google analytics to trigger a premium content download for this piece of content

                          ga('send', 'event', 'Download', 'Click', 'GTS-2016-Study-Known-User');

       

       

       

       

                          // Opens the form's Follow Up URL on successful completion (the asset is specified in the Marketo form config)

                          ////window.open(url, 'myWindow');

                          ///form.getFormElem().hide();

                          // add the custom thank you message and download link to the actual asset

       

       

                         //// var thankYou = "";

                          ////form.getFormElem().before("<p style='padding:10px;width:283px;font-size:14px;color:white;height:100px;text-align:center'>Thank you for downloading.<br/><br/>Your content will open in a new window.</p>"); 

                          return true;

                      });

          /* --------------------------------------------- */

        });

       

        function isEmailGood(email) {

          for(var i=0; i < invalidDomains.length; i++) {

            var domain = invalidDomains[i];

            if (email.indexOf(domain) != -1) {

              return false;

            }

          }

          return true;

        }

       

       

      })();

      </script>

      ----------------------------------------------------------------