Reputation: 193
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?
Upvotes: 8
Views: 12948
Reputation: 8962
Basically the callback function will forward you to the url you call with the gtag_report_conversion
function. So if you just don't pass the url, then this check
if (typeof(url) != 'undefined') {
window.location = url;
}
will evaluate to false and the forwarding won't be triggered.
Upvotes: 4
Reputation: 444
Change this line
window.location = url;
to
// window.location = url;
Upvotes: 10