• Resolved Suyta

    (@suygenneris)


    Hi there

    I have created a few events like this:

    $(".mypop").on("click", function(e){
      e.preventDefault();    
     ga('send', 'event', 'Popup', 'click', 'PopupReservation', '1');
    console.log('popup');
    });

    After update I get: ga is not defined

    I added manually the snippet:

    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)
        [0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    
        ga('create', 'G-XXXXXXXXX', 'auto') ; 
    
        ga('send', 'pageview');

    Now it works because ga is defined but I think it is not correct

    Some idea about what I’m doing wrong?

    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author yuvalo

    (@yuvalo)

    Hi @suygenneris ,

    Why are you using javascript code instead of using a click event?

    In any case, how have you configured the plugin to work with Google Analytics? Did you add the Measurement Id?

    Best,

    Yuval

    Thread Starter Suyta

    (@suygenneris)

    Hi @yuvalo

    Yes, I added the Measurement ID correctly.

    You right, in this case (click on Popup) I can use the click event but I have different events on form submissions, that is why I use javascript to control the success submission.

    Anyway my error was because I was using the old tags:

    ga('send', 'event', 'Popup', 'click', 'PopupReservation', '1');

    With GA4 I must use:

    gtag('event', 'screen_view', {
            'event_name': 'Popup',
            'event_label': 'PopupReservation'
          });
    

    Thanks a lot for your help and patience!

    Plugin Author yuvalo

    (@yuvalo)

    Ah, totally overlooked that.

    Glad to see you got it working.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘GA is not defined’ is closed to new replies.