Answer the question
In order to leave comments, you need to log in
How to organize the sending of the Ya.Metrika goal when registering a user?
You need to send the Yandex.Metrica goal (reachGoal()) at the time of user registration. What is the best way to do this without changing kernel files? Assigning an onclick event to the "Sign up" button is not good because the form may not be submitted - the target should only be called when the form is submitted.
Answer the question
In order to leave comments, you need to log in
I solved the problem by blocking the form submission with the "submit" button and submitting it myself using an ajax request. Although, the option from the comments to the question seems to be more viable if "real" users are needed to verify their account, and not tracking the registration process itself. It depends on the task and what the advertisers want from you.
I'll describe my solution here.
1. "/template_name/components/bitrix/system.auth.registration/template_name/template.php"
Set the onclick event to the "submit button" here:
2. In the main script file (or in any other file loaded on the page):
function registerSubmit(event) {
event.preventDefault();
var form = jQuery(event.target).closest('.registration-form');
if (form.length) {
form.find('[name="USER_EMAIL"]').val(form.find('[name="USER_LOGIN"]').val());
BX.ajax.post(
form.attr('data-ajax'),
form.serialize(),
function(result) {
var parent;
result = jQuery(result);
if (result.attr('id') == 'bx_incl_area_1') {
yaCounter52684615.reachGoal('LK');
location.href = '';
}
else {
/*
Обработка действий в случае неудачной попытки регистрации,
в этом случае в result приходит разметка формы с текстом ошибок.
*/
}
}
);
}
return false;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question