Hello guys, Most of the time I'm using Visual Buil...
# ask-questions
c
Hello guys, Most of the time I'm using Visual Builder for A/B testing in a website, however using JS codes to modify or add new elements with queryselector, insertbefore, etc. My problem is, that Growthbook sometimes runs the code twice, therefore the new element placed on the website twice, probably because load timing, etc. Of course, I can write that to check If the code already placed before insert, but wondering is there an out of the box solution for that or how do you guys solve this in an efficient way?
this is fine fire 1
h
I know that this is a common issue if your site is SPA (dynamic). Have you implemented this -
Copy code
// Call this every time a navigation event happens in your SPA
function onRouteChange() {
  gb.setURL(window.location.href);
}
c
Yes, not trough onroute, but with GTM setAttribute option, with other variables. Do you think this can be caused by GTM?
h
I know from experience that GTM can cause some issues, but i'm not knowledgable enough to know if it is causing the issue here. I'd feel safer however with doing the implementation in my application though so if you have the possibility to quickly do so to rule it out i'd go for it.
c
It's not a quick solution based on different values we set earlier, and because await function for G Tag as an id, but thank you I will run it.
f
Is it a SPA?
c
Yes, of course, NextJS
f
I can check with team, it shouldn't be firing twice
unless your attributes are changing, which might be the case
c
That's possible, we send id attribute later, because of waiting for gtag api and the url may change before or after that. Let me check on that.
m
that Growthbook sometimes runs the code twice
oh yes,.. we have this issue tooo And some times it does not run when required.
reacting on navigation is pain point ..