Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google gtag_report_conversion: how can I use it without reloading my page?

I have the form in the popup. I need to use this script:

function gtag_report_conversion(url) {
  var callback = function () {
    if (typeof(url) != 'undefined') {
        window.location = url;
    }
  };
  gtag('event', 'conversion', {
    'send_to': 'id_of_analytics',
    'event_callback': callback
  });
  return false;
}

And on submit I use:

onclick="return gtag_report_conversion('my_page_url')"

But when I click submit-button, my page get reloaded and popup with form get closed. And no error- or success-messages are displayed.

How can I use this script without reloading my page?

like image 368
humster_spb Avatar asked Oct 31 '18 11:10

humster_spb


Video Answer


1 Answers

Change this line

  window.location = url;
to
// window.location = url;
like image 76
user138821 Avatar answered Oct 03 '22 21:10

user138821