Using Javascript to run Google Ads conversions tracker

I’m using the Javascript plugin from Bubble to try to fire a conversion for when something is clicked:

.

Normally, you’d include the Google Ads click tracker as an onClick element. I’m trying to do this:
image

Which throws an “invalid return statement” error.

When I wrap it in a function, I get an “invalid or unexpected token” error:
image

Any idea how to make this work properly?

Thanks!
Matt

I now have the tracking event running properly, except: now when a user clicks the item in question, the event script fires, but also a dialogue of “Leave site? You’ll lose any unsaved changes.” pops up. Any idea why that might be occurring?

How did you get it to work, dealing with this now… ?

How did you get it to work, dealing with this now… ? Thanks

Just to be clear, that plug-in is not “from Bubble”. It was created by a third-party developer. Bubble does “no code”.

Interesting, and good find. I’ll test this out and see if I need to add it into my plug-in. I’ve read about something in the gtag docs where you have to manage timing issues when navigating away from the page.

Yes, I ran into exactly the same issue with a Stripe integration. Disabling / removing the handler for the beforeunload event resolved it for me. See if adding the following to the start of your script solves the problem:

window.onbeforeunload = null

1 Like

Inside Google Ads you’re provided with tracking codes - snippets of Javascript code that you or your developer will place on your website or within your app

@MPB What’s the correct JS syntax that you got to work?

1 Like