无法实现:按钮的onClick,获取当前页面URL并发布到zapier webhook

问题描述 投票:0回答:1

我在页面上有一个按钮,并且单击了成功触发该按钮的GTM标签。我似乎无法弄清楚应该发生的自定义HTML,因此当人们单击按钮时,它将获取按钮所在的页面URL,然后将其发布到Zapier Webhook(然后可以从中进行解析和处理) )。

仅供参考,页面网址是这种格式:https://www.example.com/free-report-download/?EM=johndoe%40gmail.com&FN=John&MB=8005555555&cid=d9e8d0ed-fe53-4443-b55e-1c3dcfe4db37

google-tag-manager zapier
1个回答
0
投票

修补后几小时内更新

放弃使用GTM。使用javascript和jQuery之后,我得到了想要的结果!

<form id="my-form">
  <input type="hidden" id="location" name="location" value="" />
    <input type="submit" value="Get this Freebie" onclick="window.location.href='https://example.com/subpage'" />
</form>
<script type="text/javascript">//<![CDATA[

document.getElementById('location').value = window.location.href;

document.getElementById('my-form').addEventListener('submit', function(event) {
  event.preventDefault();
});

  //]]></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
    (function($){
        function processForm( e ){
            $.ajax({
                url: 'https://hooks.zapier.com/hooks/catch/1234567/xxxxxxx/',
                dataType: 'hidden',
                type: 'post',
                contentType: 'application/x-www-form-urlencoded',
                data: $(this).serialize(),
                success: function( data, textStatus, jQxhr ){
                    $('#response pre').html( data );
                    console.log(data)
                },
                error: function( jqXhr, textStatus, errorThrown ){
                    console.log( errorThrown );
                }
            });

            e.preventDefault();
        }

        $('#my-form').submit( processForm );
    })(jQuery);
</script>

现在,如果有更简单的方法,请告诉我。

© www.soinside.com 2019 - 2024. All rights reserved.