Inserting a custom script after Header

Yes, but that is only a nuance, not the entire picture of how ad context is created.

All sites which run Adsense are crawled by the Google Adsense crawler, so Google servers ads in context to the site based on the crawler which crawls the site.

This means that a tech site which discusses Ruby on Rails, which get served ads relevant to that context (if available), on a site level.

However, on the page level, of course there is an issue with context in nested IFRAME tags.

Not all ad tags served in IFRAME tags are nested.

Here is an example of nested IFRAME tags:

<iframe src="http://www.w3schools.com" width="1000" height="1000" id="frame1" name="frame1">
   <iframe width="200" height="200" src="http://www.bing.com" id="frame2" name="frame2">
   </iframe>
</iframe>

Personally, I have rarely seen this happen on a practical manner, to be honest; and when we check it (which we have done many times over the past 15 years or so), the only time we have seen this issue is with passback tags.

Hope this helps.