it looks like you are trying to write your own ads extension?
what about using one of the ads extensions, which are already available?
for example
there are more ads extensions available after doing a search here in the community or in the extensions directory
Taifun
1 Like