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

Force refresh userId #5683

Closed
TLadd opened this issue Aug 31, 2020 · 9 comments
Closed

Force refresh userId #5683

TLadd opened this issue Aug 31, 2020 · 9 comments
Assignees

Comments

@TLadd
Copy link
Contributor

TLadd commented Aug 31, 2020

Type of issue

Feature Request

Description

I would like for there to be a way to force refresh userId values. Currently, if I update a stored userId value in a cookie or localStorage, that new value will get pulled in on future page loads, but not the current one. The old value remains since submodules only get initialized once, which is when these values are read.

The use cases I have where this would be useful all boil down to being able to provide a better id sometime after the initial page load. For instance, after a user logs in, I can get a better identifier than was previously stored and I want to start using it in bids without refreshing the page.

I would propose something along these lines:

interface RefreshUserIdsOptions {
  // When performing the refresh, should it take the stored value, or force overriding it.
  // If the new value was written to the cookie/localStorage, it wouldn't be necessary to call `getId`.
  // True if you want to override the stored value and call `getId`.
  overrideStoredValue: boolean,
}

pbjs.refreshUserIds(options: RefreshUserIdsOptions)
pbjs.refreshUserId(name: string, options: RefreshUserIdsOptions)
@GLStephen
Copy link
Collaborator

GLStephen commented Sep 1, 2020

We have been looking at an option to reinitialize analytics for SPAs particularly focused on tracking an approximation to "pages". It seems there is a cluster of information generally thought of as occuring on page load that should have a "reinitialization" hook.

@bretg
Copy link
Collaborator

bretg commented Sep 2, 2020

@jdwieland8282 - please take a look at this request and consider assigning if you agree with it

@jdwieland8282
Copy link
Member

Hi @TLadd, just want to make sure I understand this request. User ids available post page load, like ones derived from a login event, will be more persistent but are not available to the getId function bc, that function renders on page load. The request is to design a feature that "reinitialization's" User ids, post page load?

@TLadd
Copy link
Contributor Author

TLadd commented Sep 2, 2020

@jdwieland8282 Yep, that's correct. The goal is to be able to refresh a userId value that gets sent with bids without having to refresh the page.

Right now, it is technically possible to overwrite a user id value by directly accessing the cookie or key in localStorage dictated by the config. However, this will only be reflected in bids after a page reload, since the submodules are only initialized once on load, at which point the values are either read from the cookie/localStorage or getId is called. Assuming getId would also return the same value, then clearing the cookie/key would also have the same effect. In either case, a page reload is necessary to get the value into memory and sent along with bids.

So I'm hoping for a function that I can call to trigger reinitializing the userId value(s). In my proposed API, I suggested an overrideStoredValue option. If overrideStoredValue were passed as false, it would presume that the cookie/localstorage value was already overwritten with the updated value. Thinking about it a little more, I would probably prefer just passing the value in directly if it can be known ahead of time without calling getId. If a value isn't passed, then getId would just be called and replace the existing value.

For my particular need (and I imagine most), it would actually be fine to just re-run getId and not pass in an updated value directly, so I would be fine completely foregoing these options altogether too. Just thought being able to pass in a known custom value might enable some use cases or make them more straightforward.

@smenzer
Copy link
Collaborator

smenzer commented Sep 3, 2020

I think this request makes sense. Much like we refresh if consent changes, if there's another event that could improve the accuracy/value/etc of the IDs, there should be a way to update for future bid requests on the same page (or for future page loads, for that matter).

A few things to consider:

  1. In some cases, the publisher's configuration for the userId submodules needs to be updated in order to take into consideration the improved signals (like a publisher ID, user login, etc), so it's not enough to just run getId() again, but the config needs to be updated first and then re-read in if this is to happen on the same page

  2. The normal flow for calling getId() on a new page is that it checks if the storage/cookie has expired, refreshInSeconds is reached, or if the consent string has changed. There would need to be another condition added that forces a refresh based on this new override that the publisher indicated somehow (depending on how this is built)

  3. If we can avoid another method that submodules need to implement, that would be my preference. Using getId() should do the trick and if a submodule needs a custom way to run a "refresh" then they should build it in there.

@coryhammon1
Copy link
Contributor

Added an initial pull request for this feature. It's a simple global function that reinitializes all of the user modules, populating them will any changes from the storage/cookie. Please take a look if you are interested.

@TLadd TLadd mentioned this issue Oct 2, 2020
9 tasks
@stale
Copy link

stale bot commented Oct 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 4, 2020
@smenzer
Copy link
Collaborator

smenzer commented Oct 5, 2020

not stale, PR is waiting on a 2nd review #5819

@stale stale bot removed the stale label Oct 5, 2020
@TLadd
Copy link
Contributor Author

TLadd commented Oct 13, 2020

Closed by #5819

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants