Ads not updating on navigation
Unanswered
Keyhole wasp posted this in #help-forum
Keyhole waspOP
I am trying to integrate AdSterra ads using script tags. The ads have shown up in the UI, but I am facing two issues.
1: When I navigate to another page, the ad placed on that page does not display in the UI.
2: There is an error in the console that says: Prop
The way I am using script:
<div
dangerouslySetInnerHTML={{
__html:
}}
></div>
Iframe tag is in the Markup before navigating (Ad is showing in the UI):
The Iframe tag is not in the markup after navigating (Ad is not showing in the UI):
The error that I am seeing in the console:
1: When I navigate to another page, the ad placed on that page does not display in the UI.
2: There is an error in the console that says: Prop
dangerouslySetInnerHTML did not match. Server...The way I am using script:
<div
dangerouslySetInnerHTML={{
__html:
<script type="text/javascript" async>
var atOptions = {
'key' : '5b206889eba27ffa3faf57a6c6112191',
'format' : 'iframe',
'height' : 50,
'width' : 320,
'params' : {}
};
document.write('<scr' + 'ipt type="text/javascript" async src="//www.topcreativeformat.com/5b206889eba27ffa3faf57a6c6112191/invoke.js"></scr' + 'ipt>');
</script>,}}
></div>
Iframe tag is in the Markup before navigating (Ad is showing in the UI):
The Iframe tag is not in the markup after navigating (Ad is not showing in the UI):
The error that I am seeing in the console:
6 Replies
i don't know the exact problem but the
document.write looks sus, probably shouldn't be doing thatwhy can't you use
<Script>? https://nextjs.org/docs/app/api-reference/components/script@josh why can't you use `<Script>`? https://nextjs.org/docs/app/api-reference/components/script
Keyhole waspOP
The problem is same with <Script>. It does not reload when I navigate to other pages.
@Keyhole wasp The problem is same with <Script>. It does not reload when I navigate to other pages.
add a
key prop to Script tag and make sure it changes on every route changethis will force react to re render that tag hence updating the ad
@@ts-ignore this will force react to re render that tag hence updating the ad
Keyhole waspOP
Not working. The script does not execute when I navigate. I used usePathname but did not work.