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

UserID module: better initialization logic; new global function #8201

Merged
merged 7 commits into from
Apr 14, 2022

Conversation

dgirardi
Copy link
Collaborator

@dgirardi dgirardi commented Mar 21, 2022

Type of change

  • Bugfix
  • Does this change affect user-facing APIs or examples documented on http://prebid.org?

Description of change

This updates the userID module to avoid premature initialization (#5447):

  • pbjs.getUserIds and pbjs.getUserIdsAsEids no longer force initialization of the ID system
  • ID submodules are now initialized after after GDPR consent has been resolved and userSync configuration has been set
  • added pbjs.getUserIdsAsync(), which returns a promise to user IDs, completing only once all ID submodules have completed init
  • pbjs.refreshUserIds now forces an immediate refresh regardless of userSync config and returns a promise that completes when all ID submodules have filled in their data. pbjs.refreshUserIds({refresh: false}) will just return the promise without refreshing.

Note that until #8185 gets merged, GDPR data cannot be resolved without an auction, so this will prevent any ID from being resolved if the consentManagement module is installed and no auction is started. No additional action should be required to fix this besides the merge.

Other information

Fixes #5447
Documentation PR: prebid/prebid.github.io#3698

This updates the userID module to avoid premature initialization (prebid#5447):

 - `pbjs.getUserIds` and `pbjs.getUserIdsAsEids` no longer force initialization of the ID system
 - ID submodules are now initialized after after GDPR consent has been resolved *and* `userSync` configuration has been set
 - both `pbjs.getUserIds` and `pbjs.getUserIdsAsEids` now accept a callback that, if provided, is scheduled run after all ID submodules have filled in their data. Depending on `userSync` configuration, this may neeed to wait for an AUCTION_END event
 - `pbjs.refreshUserIds` now forces a fetch regardless of `userSync` config and returns a promise that completes when all ID submodules have filled in their data. `pbjs.refreshUserIds({refresh: false})` will return the promise without reinitialization.
@patmmccann patmmccann requested review from SKOCHERI and smenzer and removed request for SKOCHERI March 23, 2022 17:51
@patmmccann patmmccann added the needs 2nd review Core module updates require two approvals from the core team label Mar 23, 2022
@patmmccann
Copy link
Collaborator

@dgirardi please note the merge conflict

@EskelCz
Copy link
Contributor

EskelCz commented Mar 30, 2022

@dgirardi Thanks for this, looks promising.
One suggestion for readability though, pbjs.refreshUserIds({refresh: false}) is just what we want, but it's not immediately clear what it does. Can it separated into a new method, something like pbjs.getUserIdsAsync()?

@dgirardi
Copy link
Collaborator Author

What about adding getUserIdsAsync but removing callbacks from the other methods' signatures? Since all of these are part of the public API I'd like to keep changes to a minimum.

@EskelCz
Copy link
Contributor

EskelCz commented Mar 31, 2022

Sounds good, that would leave the current implementations that are working as they are... and whoever is having issues would switch to the async version.

Copy link
Collaborator

@smenzer smenzer left a comment

Choose a reason for hiding this comment

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

Overall this looks good. I'm not an engineer so I can't say that every bit of code is written in the best way, but the logic makes sense and I like that it doesn't break existing implementations.

I would like to see the examples page updated to show how to properly use the pbjs.getUserIds() method with the new callback function, as well as any related docs (I know the docs PR is still pending). Once all of that is done, I'm happy to approve.

We will need another engineer to review and approve since this is core.

@smenzer smenzer requested a review from Fawke March 31, 2022 12:30
@dgirardi
Copy link
Collaborator Author

Documentation PR: prebid/prebid.github.io#3698

Comment on lines 151 to 155
// TODO: this whole suite needs to be redesigned; it is passing by accident
// some tests do not pass if consent data is available
// (there are functions here with signature `getId(config, storedId)`, but storedId is actually consentData)
// also, this file is ginormous; do we really need to test *all* id systems as one?
resetConsentData();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree completely. a lot of this was from the first iteration of the user id module, so a lot of copy/paste from newer modules and signatures weren't necessarily updated as we made changes.

I think we need to have a few tests that do test all id systems for basic processing, but the majority of these tests could probably just be mock id systems to test core functionality

@smenzer
Copy link
Collaborator

smenzer commented Apr 14, 2022

We've got 2 approvals on this, so I'm going to go ahead and merge it in. Thanks for all the work on this one everyone, especially @dgirard and @EskelCz!

@smenzer smenzer merged commit 8035272 into prebid:master Apr 14, 2022
@smenzer smenzer removed needs review needs 2nd review Core module updates require two approvals from the core team labels Apr 14, 2022
@EskelCz
Copy link
Contributor

EskelCz commented Apr 14, 2022

@smenzer @dgirardi Awesome, thanks a lot for quick resolution. Looking forward to testing it out.

@patmmccann patmmccann changed the title UserID module: better initialization logic UserID module: better initialization logic; new global function Apr 14, 2022
JoelPM pushed a commit to JoelPM/Prebid.js that referenced this pull request Apr 25, 2022
* UserID module: better initialization logic

This updates the userID module to avoid premature initialization (prebid#5447):

 - `pbjs.getUserIds` and `pbjs.getUserIdsAsEids` no longer force initialization of the ID system
 - ID submodules are now initialized after after GDPR consent has been resolved *and* `userSync` configuration has been set
 - both `pbjs.getUserIds` and `pbjs.getUserIdsAsEids` now accept a callback that, if provided, is scheduled run after all ID submodules have filled in their data. Depending on `userSync` configuration, this may neeed to wait for an AUCTION_END event
 - `pbjs.refreshUserIds` now forces a fetch regardless of `userSync` config and returns a promise that completes when all ID submodules have filled in their data. `pbjs.refreshUserIds({refresh: false})` will return the promise without reinitialization.

* Add `pbjs.getUserIdsAsync` instead of tacking on callbacks to every other method

* Remove out of date typedef
dgirardi added a commit to dgirardi/Prebid.js that referenced this pull request May 3, 2022
… infinite loop

In some situations userID submodules can throw exceptions (prebid#8360) which then, after prebid#8201, causes the ID system to get stuck in an infinite loop.
dgirardi added a commit that referenced this pull request May 4, 2022
… infinite loop (#8362)

In some situations userID submodules can throw exceptions (#8360) which then, after #8201, causes the ID system to get stuck in an infinite loop.
tpmn-admin pushed a commit to tpmn-admin/Prebid.js that referenced this pull request May 9, 2022
… infinite loop (prebid#8362)

In some situations userID submodules can throw exceptions (prebid#8360) which then, after prebid#8201, causes the ID system to get stuck in an infinite loop.
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.

User ID module not getting data from GDPR consent module
6 participants