1
1
1dzanami2019-09-27 13:01:43
JavaScript
1dzanami, 2019-09-27 13:01:43

How to correctly set the goal of a metric / analytics using js?

Tell me please. How to set a goal so that it works.
The site has feedback forms, I'm trying to add onsubmit through the script, but for some reason it is not attached to the form. On the button via onclick is not an option, since there are no unique classes

<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#yw1').attr("onsubmit","yaCounter46372170.reachGoal('zakazbistr'); gtag('send', 'event', { 'event_category': 'sub', 'event_action': 'btnsub'}); return true;");
});
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Neverov, 2019-09-27
@1dzanami

Why are you using the .attr() method? It's easier to do this:

jQuery(document).ready(function(){
  jQuery('#yw1').on("submit", function() {
    yaCounter46372170.reachGoal('zakazbistr');
    gtag('send', 'event', { 'event_category': 'sub', 'event_action': 'btnsub'});
  });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question