Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Speculation Rules Prerender page activation in Prebid.js #12724

Open
gilbertococchi opened this issue Feb 4, 2025 · 8 comments · May be fixed by #12763
Open

Handle Speculation Rules Prerender page activation in Prebid.js #12724

gilbertococchi opened this issue Feb 4, 2025 · 8 comments · May be fixed by #12763

Comments

@gilbertococchi
Copy link

Hello everyone, since version 109 Chrome has introduced support to Speculation Rules Element that allow developers or publishers to prefetch or prerender next page navigations before the user clicks on links.

You can read about the technology here: https://developer.chrome.com/docs/web-platform/prerender-pages

The Prerender logic is great as it fully load the target page into an invisible tab, including running JS etc.

The possible issues may come if Analytics or Ads providers (such as Prebid.js) may run on an Inactive tab that may never be visited by the user.

It's definitively possible that more and more publishers will start to adopt this technology leading to some data measurement issues on 3Ps that have not implemented the necessary logic.

In the article here it's possible to view the suggested way to handle this.

In a nutshell a Prerendered page as document.prerendering = true, and there is an event prerenderingchange that could be used by 3Ps to intercept when the page becomes active to trigger some logics.

For example, Google Publisher Tag (GPT) and AdSense, as well as Google Analytics and other 3Ps are using this method to avoid triggering either PageView for GA or the Ad Request in the case of GPT.

I think it would be ideal for Prebid.js library to decide what to do here, an internal implementation logic in Prebid.js would make it possible for publishers to speed up pages, anticipate Ad Requets, improve Ads KPIs without messing up with metrics from the pages that may never become active.

Hope you appreciate the suggestion here.
Gilbert0

@gilbertococchi gilbertococchi changed the title Handle Speculation Rules page activation in Prebid.js Handle Speculation Rules Prerender page activation in Prebid.js Feb 4, 2025
@dgirardi
Copy link
Collaborator

dgirardi commented Feb 4, 2025

I'd love the opportunity to speed things up but I'm not sure how Prebid could use this. The only pre-renderable "pages" I can think of are creatives, which we load and show as soon as we have enough info to do so. Is there a use case I'm missing?

@gilbertococchi
Copy link
Author

Hi Demetrio, thanks for your answer, please let me better elaborate the situation here to highlight what may be happening.

Speculation Rules is used by Publishers or Developers in general, not by AdTech, the issue is that its usage can cause unnecessary requests to prebid being sent.

Scenario:

  • Page A implements Speculation Rules, asking Chrome to Prerender Page B and C when user hovers on the links (logic eagerness=moderate).

  • User loads Page A and with the mouse would stop over Links to Page B and C respsectively (without clicking).

  • on the background Page B and C would fully load, running Prebid.js queue, running a bid and request, but user would not see any Ad.

  • User actually clicks on Page C and then gets the page loaded immediately and with the Ad being loaded.

Issue: Page B was fully loaded, running Prebid.js Action but for no reason because the page never became active.

Desired scenario:

  • Prebid.js would intercept that the page when Prebid.js is running is prerendered and not visible to the user, delays the Ad Request/Bid chain until the page becomes active by using the prerenderingchange event.

Let me know if this example is intuitive enough, happy to build a small demo if helpful.

Gil

@dgirardi
Copy link
Collaborator

dgirardi commented Feb 4, 2025

Desired scenario:

Why is it desired? Wouldn't it defeat the purpose of prerendering and worsen UX?

Either way, we could make it optional - it looks relatively easy to implement.

@gilbertococchi
Copy link
Author

Hi Demetrio, you are right, I am not yet sure what is the desired scenario, as you said it depends.

Speculation Rules Prerender impacts the page prerendering first but also positively influence the Ads KPIs dynamic, beacuse the Ad request chain would trigger earlier than without it.

Some Ad Tech decided not to do anything until the page is activated (like GPT) but others may not have the same issues or may take another approach.

If running Auctions on page loads that may never become user visible is not a concern I guess there might not be issues while running Prebid.js on prerendered pages before activation but I guess it would still mean running more auctions than normal and perhaps impacting Inventory KPIs.

I can provide some demos and real live examples if you would like to discuss it better.

Thanks for your feedback and help as always Demetrio!
Cheers
Gil

@patmmccann patmmccann moved this from Triage to Needs Req in Prebid.js Tactical Issues table Feb 10, 2025
@gilbertococchi
Copy link
Author

Example page of the current behaviour:

  • Load https://output.jsbin.com/xeyapog/3

  • use Desktop, no Mobile emulation

  • move the the mouse cursos over the link

  • Chrome will Prerender the target page and also would run the Prebid.js Bid (not the GPT one because it's preventing it).
    See screenshot below because it's possible to inspect the background prerendered page where the Prebid Bid happened and there is an Ad being queued to be display already.

Image
  • If I click on the link I would actually go to the page and the Ad would display almost immediately because the Auction has already happened.
Image

This is great but Publishers may have multiple links per page, so it's possible that some Auctions will result into an Ad that will never become visibile that I don't believe it's desirable.

Happy to share more examples and info if required.

@patmmccann patmmccann moved this from Needs Req to Ready for Dev in Prebid.js Tactical Issues table Feb 12, 2025
@patmmccann
Copy link
Collaborator

We'll go ahead and implement Chrome's suggestions by default, but also implement an override for publishers. We won't consider the change that considered the prerendering status as breaking and it can be in a minor version. We should add a logInfo message describing current state in debug mode.

@dgirardi
Copy link
Collaborator

dgirardi commented Feb 12, 2025

Proposal:

  • before starting to go through pbjs.que, check whether the page is prerendered (performance.getEntriesByType('navigation')[0].activationStart !== 0 document.prerendering, see here)
  • if it is, suspend the queue until we get a prerenderingchange event
  • allow pubs to disable this behavior with setConfig({allowPrerendering: true})

@gilbertococchi
Copy link
Author

Thanks both @dgirardi and @patmmccann for the feedback!

One small suggestion, I think it would be better to listen to document.prerendering instead of the activationStart.

document.prerendering triggers when the page is prerendered but invisible, that is the best place to handle this at pbjs.que.

performance.getEntriesByType('navigation')[0].activationStart is used to detect when a prerendered page becomes active and it would be too late to act here from the Prebid POV if you ask me and prerenderingchange would not work.

More info here: https://developer.chrome.com/docs/web-platform/prerender-pages#impact-on-analytics

@dgirardi dgirardi linked a pull request Feb 13, 2025 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for Dev
Development

Successfully merging a pull request may close this issue.

3 participants