Skip to content

BidViewability: Refactored the init function #13141

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

Merged
merged 13 commits into from
Jun 25, 2025

Conversation

pm-azhar-mulla
Copy link
Contributor

Type of change

  • Refactoring (no functional changes, no api changes)

Description of change

Previously, the module was initialized by adding a listener to the AUCTION_INIT event. With this refactor, the listener is registered during module initialization, improving efficiency and aligning with standard initialization practices.

Copy link

Tread carefully! This PR adds 1 linter error (possibly disabled through directives):

  • modules/bidViewability.js (+1 error)

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the module initialization for BidViewability by replacing the AUCTION_INIT event listener with a configuration callback.

  • Replaces event-driven initialization with a config.getConfig callback.
  • Updates the handling of the global module configuration during initialization.
Comments suppressed due to low confidence (1)

modules/bidViewability.js:93

  • The callback from config.getConfig does not provide an event object, causing a reference error when accessing 'event'. Remove or replace the use of 'event' based on the intended behavior.
impressionViewableHandler(globalModuleConfig, event.slot, event);

// do nothing if module-config.enabled is not set to true
// this way we are adding a way for bidders to know (using pbjs.getConfig('bidViewability').enabled === true) whether this module is added in build and is enabled
if (globalModuleConfig[CONFIG_ENABLED] !== true) {
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OP does not call this a bugfix, but I think the previous version would attach duplicate GPT event listeners on every auction. This fix, to be complete, should detach it here (when the module is turned off) IMO.

https://developers.google.com/publisher-tag/reference#googletag.Service.removeEventListener

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the changes as per the GPT document. where we are removing the listener before firing the handler.
Also consumed the event object to extract the slot to handle Co-pilot's suggestion.

@patmmccann patmmccann requested a review from dgirardi June 13, 2025 14:20
@pm-azhar-mulla
Copy link
Contributor Author

@dgirardi Can you please check this

@patmmccann patmmccann merged commit 5e3b878 into prebid:master Jun 25, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants