amp-windowContextCreated not firing
Description
It seems the amp-windowContextCreated event is not firing. I'm trying to call context.noContentAvailable to collapse an ad slot (out of view) once the amp-windowContextCreated event fires, but that is not occurring. This has been working for almost a decade, but suddenly stopped working very recently (this was reported to me last week).
The code we're using:
if (!window.context) {
//must add listener for the creation of window.context
window.addEventListener('amp-windowContextCreated', () => {
console.log('AMP - Blank ::: collapsing ad slot for creative %ecid!');
window.context.noContentAvailable();
});
//load amp js which will create window.context
ampContextScript = document.createElement('script');
AMPversion = window.AMP_CONTEXT_DATA.ampcontextVersion;
ampContextScript.src = 'https://3p.ampproject.net/'+AMPversion+'/ampcontext-v0.js';
document.head.appendChild(ampContextScript);
}
I'm never seeing the console log "collapsing ad slot for creative", which tells me that the event is not firing.
Reproduction Steps
https://www.cbsnews.com/amp/brandstudio/news/a-mothers-love-and-daughters-fight-facing-alzheimers-together/?pbjs_debug=true
- open Developer Tools
- click into the Console tab
- filter by "AMP - Blank"
- you will see a console log "AMP - Blank ::: creative id = NUM, pos = 2"
- in the DOM you can see that the ampcontext js was successfully inserted
- you will not see a console log "AMP - Blank ::: collapsing ad slot for creative NUM" which means that event never fires which means that
context.noContentAvailableis never called (which is responsible for the collapsing)
Relevant Logs
Browser(s) Affected
No response
OS(s) Affected
No response
Device(s) Affected
No response
AMP Version Affected
No response
@keithwrightbos @lannka @zhouyx @jasti @taymonbeal I know it's been a while, but you all were very helpful with various AMP bugs/issues I encountered in the past and I'm wondering if you have any insights here. Nothing changed with our code to collapse an ad space, but it stopped working last week? Thanks!
@coreyb-cbs taking a look
i can confirm that the event is at least fired as it executes the following lines:
const windowContextCreated = new Event('amp-windowContextCreated');
window.context = new AmpContext(window);
window.dispatchEvent(windowContextCreated);
I'm trying to figure out why your code path isn't being reached. could you provide me some help in maybe creating a reduction which i can test locally and in isolation. (just a simple amphtml page with a single ad that fails)
its a bit hard to debug because the code is a string in the attribute that eventually gets code executed so i cannot step through the code
@erwinmombay Thanks so much for taking a look. I built out a simplified test page to demonstrate the issue. https://rev.cbsi.com/corey/test/amp/amp_blank_300x250.html
notes:
- the "lorem ipsum" chunks of text occupy visual space so the ad slot is out of view (required to collapse an ad slot)
- "ad above" and "ad below" text act as bookends to the ad slot
- as you scroll down you will see in the console logs "AMP - Blank ::: creative id = 138512971481"
- you should see in the console logs "AMP - Blank ::: collapsing ad slot for creative 138512971481" once the AMP context event "amp-windowContextCreated" fires, but alas we do not (as documented in my original post)
- immediately after this log, our code would call
window.context.noContentAvailable()which would collapse the slot, but this is also not occurring
The ad code (which you can view by inspecting the DOM in the test url above) is:
console.log('AMP - Blank ::: creative id = 138512971481, pos = ');
if (!window.context) {
//must add listener for the creation of window.context
window.addEventListener('amp-windowContextCreated', () => {
console.log('AMP - Blank ::: collapsing ad slot for creative 138512971481');
window.context.noContentAvailable();
});
//load amp js which will create window.context
ampContextScript = document.createElement('script');
AMPversion = window.AMP_CONTEXT_DATA.ampcontextVersion;
ampContextScript.src = 'https://3p.ampproject.net/'+AMPversion+'/ampcontext-v0.js';
document.head.appendChild(ampContextScript);
}
@coreyb-cbs thank you so much for the detailed example and reduction this will help me a lot in testing locally.
We haven't made any changes recently besides one ad change from last week that hasn't even made it to canary yet so its making me think that maybe its a Chrome 135 change (it got announced April 1st but i dont know when it actually got released). I'll keep you posted if i have more questions while i debug
@coreyb-cbs actually i forgot to ask, could you confirm to me that you are seeing the same behavior in safari as well?
@erwinmombay I see the same behavior in Safari and Firefox. Are you able to replicate what I'm seeing where the ad space does not collapse and the "collapsing ad slot" log is not present in the console (which indicates the amp-windowContextCreated is not firing)?
@coreyb-cbs , yes i am able to reproduce it.
@coreyb-cbs if im understanding correctly the ad code you posted is an "Active View" correct? Is that input somewhere on some ads account?
apologies for the dumb question here, I'm not an ads expert so im trying to understand the ads side of the code right now.
@erwinmombay The ad code gets automatically inserted into the .GoogleActiveViewElement div element.
@erwinmombay Just curious if you had another opportunity to investigate why the context event is not firing here? Thanks so much!
heya @coreyb-cbs im reaching out to some of our team members to help me out on and get more eyes to debug. Could you give me a sense of what the current impact is on your side so I can try and convey it to them.
@erwinmombay The product managers are considered removing ad slots from amp pages until this can be resolved. That obviously leaves ad revenue on the table and is not ideal.
@coreyb-cbs i think i've identified the issue. Working on getting a fix in
@erwinmombay I see your fix was merged. When might this roll out to production? Thanks so much!
I am having QA test it right now in opt-in/experimental 1%. I also verified that it works using your example.
The fix should be fully in production by Tuesday
i've verified that the fix is in production. feel free to re-open if there are still issues surrounding this.
@erwinmombay Thank you so much for quickly resolving this issue! I verified in prod. Thank you again!
@coreyb-cbs thank you for the super detailed reproduction and your patience. could have taken longer if it weren't for your great help and i appreciate the bug report!