Answer the question
In order to leave comments, you need to log in
How to set up Yandex goal in Ajax form?
Hello. I have a regular feedback form on Bitrix. I want to set Yandex a goal after a hasty form submission. The form is passed by ajax
template.
<?if(strlen($arResult["OK_MESSAGE"]) > 0){?>
<div class="mf-ok-text"><?=$arResult["OK_MESSAGE"]?></div>
<?}else{?>
<form action="<?=POST_FORM_ACTION_URI?>" method="POST">
<?=bitrix_sessid_post()?>
<fieldset>
<div><span><?=$arResult["ERROR_MESSAGE"]["ERR_NAME"]?></span></div>
<label for="popup-online-name">Имя:<span>*</span></label>
<input type="text" name="user_name" id="popup-online-name" value="<?=$arResult['AUTHOR_NAME']?>"/>
</fieldset>
<fieldset>
<div><span><?=$arResult["ERROR_MESSAGE"]["ERR_COMPANY"]?></span></div>
<label for="popup-online-usluga">Компания:</label>
<input type="text" name="company" id="popup-online-company" value="<?=$arResult['COMPANY']?>"/>
</fieldset>
<input type="hidden" name="PARAMS_HASH" value="<?=$arResult["PARAMS_HASH"]?>">
<input id="SUBMIT_ORDER" type="button" name="submit" value="Отправить">
</form>
<?}?>
$('.order').click(function(){
$.ajax({
type: "POST",
url: "/ajax/ajax_product.php",
beforeSend: function () {
$('.o-content').empty();
},
success: function (data) {
$('.o-content').append(data);
$('#SUBMIT_ORDER').click(sendSubmit);
$('.popup-online').fadeIn(300);
$('.modalWindow').fadeIn();
}
});
});
<form action="<?=POST_FORM_ACTION_URI?>" method="POST" onsubmit="yaCounterXXXXX.reachGoal('Order'); return true;">
doesn't work <input id="SUBMIT_ORDER" type="button" name="submit" value="Отправить" onsubmit="yaCounterXXXXX.reachGoal('Order'); return true;">
doesn't work $('.order').click(function(){
$.ajax({
type: "POST",
url: "/ajax/ajax_product.php",
beforeSend: function () {
$('.o-content').empty();
},
success: function (data) {
$('.o-content').append(data);
$('#SUBMIT_ORDER').click(sendSubmit);
yaCounterXXXXX.reachGoal('Order'); return true;
$('.popup-online').fadeIn(300);
$('.modalWindow').fadeIn();
}
});
});
- works only on click <?if(strlen($arResult["OK_MESSAGE"]) > 0){?>
<div class="mf-ok-text"><?=$arResult["OK_MESSAGE"]?></div>
<script>
yaCounterXXXXX.reachGoal('Order'); return true;
</script>
<?}else{?> ..........
- does not work. Answer the question
In order to leave comments, you need to log in
$('body').on('submit', 'ваша форма', function(){
yaCounterXXXXX.reachGoal('Order');
})
And why do you send the form to the success event after the Ajax call?
success: function (data) {
$('.o-content').append(data);
$('#SUBMIT_ORDER').click(sendSubmit);
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question