GTM 网络跟踪 jQuery().submit(函数不适用于 AngularJS 表单

GTM web tracking jQuery().submit(function not working with AngularJS form

我们想使用 Google 跟踪代码管理器来跟踪表单提交。当我从 GTM 添加 jQuery 脚本并对其进行测试时,该脚本甚至没有触发 - 甚至没有一个“你好。我已经删除了 AngularJS {{expression}} 值来保护我们的公司 属性。我希望这些信息足够了。

<div id="login_signIn" class="">
  <form id="login_form" name="loginForm" novalidate>
    <fieldset>
      <legend>Sign In</legend>
      <label for="u_name" ng-class=""> Email address </label>
      <input name="u_name" id="u_name" type="email" maxlength="50" ng-model="" required ng-class="" />
      <label for="Password1" ng-class=""> Password </label>
      <input name="passwd" id="Password1" type="password" maxlength="50" ng-model="" required ng-class="" />
      <div class="login_forgot p-bottom clearfix"> <span class='loading f-left' ng-show=""> <img src="/images/loading.gif" width="48" height="47" alt="Loading" /> </span> <span class="f-right"><a href="/forgot-password/"><em>Forgot Password?</em></a></span> </div>
      <div class="form-error p-bottom clearfix" ng-show=''></div>
      <input type="submit" value="Sign In" name="new_submit_img" ng-click="" class="cliq-submit" />
      <script type="text/javascript">
        jQuery('#login_form').submit(function(e){
            alert("hello");
            window.dataLayer = window.dataLayer || [];
            window.dataLayer.push({
                'event' : 'formSubmissionSuccess',
                'formId' : 'login_form'
            }); 
        });
      </script>
    </fieldset>
  </form>
</div>

谢谢你的想法。

我发现这篇文章是关于在上面的 GTM 脚本不起作用时添加 GTM 脚本的不同方法:

http://www.simoahava.com/analytics/track-form-abandonment-with-google-tag-manager/

在标题下:基本自定义 HTML 标签我在 GTM 脚本块上方使用了这个脚本,我们将其放置在开始 body 标签之后,效果非常好。:

    <script>
      (function() {
        window.addEventListener('beforeunload', function() {
          window.dataLayer.push({
            'event' : 'formSubmissionSuccess',
            'formId' : 'login_form'
          });
        });
      })();
    </script>