How exactly do you put your custom code on the page? Via a target activity using the VEC and an HTML element? Or via something else?
I can only think of two experiences at the moment - but they don't have to have anything to do with your problem.
If you use remote offers that bring code to the page via a JCR path - depending on the setup this may require that you first have to check what exactly arrives in the remote offer in the request. Once had the case that depending on the RemoteOffer of AEM corresponding scripts were automatically added to the page. But this can be easily fixed with a small script and only allow scripts that are not yet included on the page.
With a customer was once the current live stand differently than expected. There was still an at.js implemented for testing purposes. In addition, the normal rule implemented the appropriate target. This was noticed when we checked the request in the network tab and found that a completely different at.js was loaded.