Hello everyone! Just messing with the google ads i...
# support
r
Hello everyone! Just messing with the google ads integration with rudderstack and I noticed something odd. If i dispatch an event with rudderstack that maps to a conversion event on click of a link, the event doesn’t get dispatched (according to ga debugging tools) but if I directly access the
window.dataLayer
that is created by the google ads tag, then it works fine. My suspicion is the rudderstack is doing something async and not immediately dispatching before the navigation event occurs and it’s unloaded. Wondering if anyone else has run into this
m
Hey There! 👋 Your message has been received by the RudderStack team. We will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
Hi Paul that should not be the case. Can you see that RudderStack and the Goggle Ads SDK loaded correctly and the same event is called in both the cases?
r
google ads is loaded (i see the initialization messages). I’ve basically done something like:
Copy code
function onLinkClick() {
  window.rudderanalytics?.track("my-custom-event");
  window.dataLayer?.push("event", "conversion", { send_to: "..." });
}
In the google analytics debugger, I see the conversion event, but not the conversion event that i’ve mapped to “my-custom-event” in the rudderstack UI
m
Hi Paul, why are you doing the below? If your integration is setup correctly, RudderStack will automatically create this Google Ads event when you do a rudderanalytics.track("my-custom-event")
Copy code
`window.dataLayer?.push("event", "conversion", { send_to: "..." });`⁣
r
I’m only using the above as an example. I was trying to figure out why i’m not seeing these specific conversion events. If I just do:
Copy code
window.rudderanalytics?.track("my-custom-event");
then I’m not seeing the events in logs. If I replace it with the dataLayer push, I see the log. It’s also weird because this only happens in production mode. If i’m running nextjs in development mode, it dispatches fine as well.
since it works in dev mode, I must assume that the mapping in my google ads integration is configured properly
m
Does window.rudderanalytics exist? Do you see an error thrown when you do (without the question mark)
Copy code
`window.rudderanalytics.track("my-custom-event");`⁣
r
I’ll double check.
hmm, it does not… Well that’s weird
Alright so yeah, the problem lay in how the sdk was loading. Somehow google ads was still loading but we never initialized rudderstack.
ah yeah, i see why i was loading it twice 🤦
Slightly unrelated, would be really nice if I could import the
rudder-sdk-js
package in nextjs without it complaining about
window
not existing
m
Hey Paul sorry I am not very fimiliar with NextJS, but I do have a react demo app and I installed rudder-sdk-js using the NPM package. I do not see any such errors/warnings
r
It works fine in
npm run dev
, but it blows up in
npm run build
basically the problem is due to server side generation, where the package is being loaded in the nodejs environment, where window doesn’t exist
m
Oh ok. But is that a blocking issue for you or a mere inconvenience?
r
Correct, I was able to load it separately, it just is much less intuitive
which is why my code had all those
?
, since we can’t guarantee it exists, since it has to load separately
m
Oh ok. I understand, since you are using NextJS and our code examples are more for vanillaJS, you ran into this issue.
r
yep