-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Backup CID in Storage for non-proxy origin #30375
Conversation
a837605
to
65ef96d
Compare
65ef96d
to
8a1ecb6
Compare
src/service/cid-impl.js
Outdated
@@ -51,6 +51,8 @@ const CID_OPTOUT_STORAGE_KEY = 'amp-cid-optout'; | |||
|
|||
const CID_OPTOUT_VIEWER_MESSAGE = 'cidOptOut'; | |||
|
|||
const AMP_CID_BACKUP_PREFIX = 'amp-cid-backup-'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that all AMP stored value in origin are stored under the same localstorage key already. amp-store:${origin}
.
How important it is for vendors to access the storage backup value? Shall we reuse the namespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the design doc, we stated that we wanted to give publishers the option to access (and potentially change) the backup value. I think reusing the name space is ok as long as it doesn't hinder this goal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my concern: reusing the namespace might hinder the goal.
One need to access the data like this
ampStorage = JSON.parse(atob(localStorage.getItem('amp-store:myorigin')));
cidStorage = ampStorage['amp-cid-backup-scope']
Keeping all AMP stored value under the same key is neat but the tradeoff is that it may be confusing to developers who want to access it outside of AMP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to keep it neat and rely on good documentation and examples to explain how to retrieve and change the values. Do you have a preference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline: We agreed that from the feedback from the original issue thread, AMP is not responsible for changes made to the local storage values in the non-AMP case. If vendors/pubs wish to change the values, it will be up to them to correctly decode the values and then encode and store them back in the proper location. B/c this backup CID is stored under the same namespace as other information, faulty encoding could lead to information being dropped (i.e. stored consent info would be lost).
861464e
to
6f25d61
Compare
6f25d61
to
6f62b0f
Compare
3d91ae2
to
04374ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Left a few nitpicks and test requests. Please also confirm with the owner of individual extensions based on the affected components list you had. Thanks!
420cbe7
to
df26520
Compare
df26520
to
8bdd915
Compare
return item ? item['v'] : undefined; | ||
const timestamp = item ? item['t'] : undefined; | ||
const isNotExpired = | ||
opt_duration && timestamp != undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is 0 or negative value a valid opt_duration value? We need to handle them specially if so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not valid values, so I don't think we need to handle them specifically.
FYI, this will change the CID service to store the CID in local storage as a backup when the document is served from a non-proxy origin. The following extensions currently use the CID service: amp-subscription, amp-access, amp-user-notification, and amp-story-interactive. @dvoytenko @erwinmombay @ampproject/wg-stories |
Thank you for cc'ing us here! Just to clarify as I don't have so much knowledge on CID things: this change will make the CID a bit more persistent on non-proxy origins? That sounds like a good things for the way we use CIDs in |
Yes, in this scenario, it will backup the scoped CID ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
presubmit-check change lgtm 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OWNERS check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Owners bump again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
owners bump
/cc @jridgewell and @lannka for bundle size check for v0 and ads. I think it makes sense that the bundle size increases for these files as we have added functionality to the |
src/service/cid-impl.js
Outdated
if (isBackupCidExpOn && !disableBackup) { | ||
return Services.storageForDoc(ampdoc).then((storage) => { | ||
const key = getStorageKey(cookieName); | ||
return storage.get(key, BASE_CID_MAX_AGE_MILLIS).then((backupCid) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Unnest this promise chain.
e0716b8
to
d38344d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approval for bundle-size
* init * Added experiment flag * Refactor * Better tests
For #29484
Change the cid-impl's
GetCidDef
to include theoptOutBackup
property.Adds the
opt_optOutBackup
parameter to theCLIENT_ID
macro in url-replacements, (defaulting to false)When the document is served from a non-proxy origin, and
optOutBackup
is false, we will store any AMP generated CIDs in storage as a backup, as well as search for backup CID value in storage if the cookie does not exist.It will be stored in local storage in the following manner:
The cid-impl is used in other parts of the code base (extensions and src/ad-cid.js), and we have elected to not opt-out to use this new feature in any of these cases.
No changes to inabox as CIDs are not allowed in that environment.
This feature is guarded by an experiment flag:
amp-cid-backup
. Publishers and vendors will be able to opt into this experiment to test out the feature. After this PR is merged we will turn the flags on for canary and prod, which will give pubs/vendors 2 weeks to change their configs to opt out of this feature.