我在页面上有一个按钮,并且单击了成功触发该按钮的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
放弃使用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>
现在,如果有更简单的方法,请告诉我。