S
S
Sergey2021-03-12 11:45:03
Google Analytics
Sergey, 2021-03-12 11:45:03

How to fix error in gtag event?

In the header of the site I connect

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-*******"></script>					
    <script>					
    window.dataLayer = window.dataLayer || [];					
    function gtag(){dataLayer.push(arguments);}					
    gtag('js', new Date());					
              
    gtag('config', 'UA-*******');					
    </script>


Then I write the event code:

<script type="text/javascript">
  $(document).ready(function(){

    gtag('event', button10, {
       event_category: 'successful_payment4',
       event_action: 'button10'
       });

  });

</script>


And in the console writes an error:

Uncaught ReferenceError: button10 is not defined
    at HTMLDocument.<anonymous> (test.php?clear_cache=Y:501)
    at e (jQuery-3.4.1.min.js?161458549188145:2)
    at t (jQuery-3.4.1.min.js?161458549188145:2)


Tell me what's wrong? Why is such an error being caught?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Denisov, 2021-03-12
@DeoZ

There is an error in the event code. "button10" must be enclosed in quotes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question