Reach Goal
-
HI!
I need to track registration on a website to achieve an online advertising goal. Where can I insert this code on the registration page?<script>
onsubmit=”ym(57238202,'reachGoal','um-submit-btn'); returns true;"
</script>The page I need help with: [log in to see the link]
-
Hello @nitrat
You can use specialized plugins like Code Snippets to add custom code snippets. This is the simplest way. For those with some web development experience, it is recommended to create a child theme and place all custom code in the child theme.
Your code is not correct. Is this HTML or JavaScript code? It seems you mixed them up.
Where did you get this example? It’s better to follow the official Google Analytics documentation to track custom events, see https://developers.google.com/analytics/devguides/collection/ga4/events?client_type=gtagRegards
Hi Yurii! This is javascript code. I waited a long time for an answer and posted a form from the Gravity forms plugin on the registration page. This task was solved easily there.
Hi Nitrat,
This can not be JavaScript code. This is similar to the HTML onclick attribute with a linear JavaScript code inside. But if it really is, then it’s completely wrong to wrap it in the
<script></script>tags.In any case, if you want to track the registration submit button click, then you can use this JavaScript code:
// Call custom code on the registration form submit button click.
jQuery('.um-register input[type="submit"]').on('click', function () {
// Add your code here.
return true;
});Regards
Hi Yurii! Thanks! Where should I insert this code?
maybe add a code like this to functions.php –
add_action( 'um_registration_complete', 'my_registration_complete', 10, 2 );
function my_registration_complete( $user_id, $args ) {
ym(57238201,'reachGoal','um-submit-btn');
}-
This reply was modified 2 months, 1 week ago by
Nitrat.
Hi @nitrat,
Please stop mixing languages. You previously mixed HTML and JavaScript, and now you’re mixing JavaScript with PHP. This won’t work. Mixing languages causes errors.
JavaScript code should be added to the file with the extension
.js
Do you have any custom JS file that you can edit?If you want to add JavaScript code to the
functions.phpfile, then you must wrap it into PHP code, see example:// Add custom code to the footer.
add_action( 'wp_footer', function () {
?>
<script type="text/javascript">
// Call custom code on the registration form submit button click.
jQuery('.um-register input[type="submit"]').on('click', function () {
ym(57238201,'reachGoal','um-submit-btn');
return true;
});
</script>
<?php
}, 20 );Regards
Hi Yurii
I added your code to functions.php but the goal is still not achieved.
Hello @nitrat,
I inspected your registration page. The way you added this code snippet is wrong. A new line between the comment and the code is lost. See screenshot here: https://ibb.co/yctG9ZtV
Try the simplified version, which doesn’t have any comments at all.
add_action( 'wp_footer', function () {
?>
<script type="text/javascript">
jQuery('.um-register input[type="submit"]').on('click', function () {
ym(57238201,'reachGoal','um-submit-btn');
return true;
});
</script>
<?php
}, 20 );Regards
Hello Yurii.
I changed the code. The goal is still not being achieved.
Hello @nitrat,
Your code seems odd, it doesn’t look like Google Analytics code. Is this code related to a service called Yandex Metrika? I can’t help you with this little-known service. You’ll need to verify this code yourself:
ym(57238201, 'reachGoal', 'um-submit-btn');But I can confirm that this code is triggered when the “Регистрация” button in the form is clicked. The code makes a request:
https://mc.yandex.com/clmap/57238201?page-url=https%3A%2F%2Fpojeni.ru%2Fregister%2F&pointer-click=rn%3A858949155%3Ax%3A47027%3Ay%3A33464%3At%3A161%3Ap%3APAA2FAAAAAA1AAAA1A%C2%841A%3AX%3A685%3AY%3A862&hidv2=351791990059565070&browser-info=u%3A1770208763148561957%3Av%3A2360%3Avf%3A6g20vg83qczf8bl2dhx6zh0rnscez%3Arqnl%3A1%3Ast%3A1770209194&t=gdpr(14)ti(1)I tested this on your website, see a screenshot of the test here: https://ibb.co/xtjgXygt
Regards
Yes, this is Yandex.Metrica. And as I was prompted, it is triggered when the Register button is pressed. But it also works even if not all fields are filled in. How do I make sure that the code is triggered only when the registration form is submitted, and not only when the Registration button is clicked?
Hi @nitrat,
Use the form
submitevent instead the buttonclickevent. But changing the event does not solve a problem because the form may be submitted with empty fields. You need to validate the fields in your code. The code for validating the fields may differ depending on your fields. Here’s a simple example:add_action( 'wp_footer', function () {
?>
<script type="text/javascript">
jQuery('.um-register form').on('submit', function (event) {
var emptyFields = [];
jQuery(event.target).find('.um-field :input').each(function(i,item){
if ( ! item.value ) {
emptyFields.push(item);
}
});
if ( 0 === emptyFields.length ) {
ym(57238201,'reachGoal','um-submit-btn');
}
return true;
});
</script>
<?php
}, 20 );Regards
Hello Yurii
Yes, the goal is working correctly now. Thank you so much for your help!
Hello Yurii!
The target is triggered, but for some reason twice. Why the second time?
Why don’t you answer? I have purchased your add-ons for the plugin.
-
This reply was modified 2 months, 1 week ago by
You must be logged in to reply to this topic.