Loading ads with Zaraz cause error


I tried Zaraz to load Google Analytics 4 and it works perfectly!
Now I want to load my ads (not Adsense). I tried to add the js files in custom HTML.
The files look like this:
<script async src='https://myadfile.js'></script>

Now the ad on the page returns an error because the ad depends on myadfile.js and didn’t find it.
The ad on the page looks like this:


The error: cnx is not defined. (because the cnx is defined in the myadfile.js which is loaded by Zaraz).

So how to solve this issue?


Why not set your Custom HTML to

<script async src='https://myadfile.js'></script>

@yoav_zaraz I make it as you said. Now ads are showing, but the page speed degraded from 99 to 60 !!!
I was doing lazy load (load ads when users interact with the page), but after enabling Zaraz, I disabled lazy loading it and run Zaraz only to see what it will do.

I thought Zaraz will improve the CWV INP and page performance, but it looks like it’s not suitable.

Zaraz does not and cannot optimize Custom HTML snippets. See FAQ · Cloudflare Zaraz docs for more information