-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Summary
Analytics vendors use a client-size session id to track an active session. Today AMP provides the PAGE_VIEW_ID and the high entropy PAGE_VIEW_ID_64 that stays the same for a given site during what the AMP viewer defines as a session. The PAGE_VIEW_ID is persisted in RAM.
The proposal is to support a session id that stays the same for a given site during a time period (e.g. 30 mins). Such session information will be stored in localStorage.
See #1612 for more context.
Design document
Macro
SESSION_ID(opt_expirationTime)
The above macro will be added to <amp-analytics>.
opt_expirationTime is an optional duration in seconds. 1800 (30 minutes) will be used as default value if it is not provided. The expirationTime needs to be in the range of [30, 86400] (30 seconds to one day) due to performance and privacy concerns.
The returned value will be a random base64 string with a high 128 bit entropy. For example U6XEpUs3yaeQyR2DKATQH1pTZ6kg140fvuLbtl5nynb
When retrieved, the stored value will be returned if its set timestamp is within the expiration time, its timestamp will also be updated to the current time.
If a stored value doesn't exist, or has expired. A new random session id will be generated and stored along with the current timestamp.
Storage
The session id will be stored under localStorage entry amp-analytics:session-id. The reason AMP doesn’t allow storageKey customization is to prevent multiple sessions from being created under different names.
The localStorage API between the AMP page and the AMP viewer will keep unchanged. It’s up to the <amp-analytics> service to remove stored value after expiration time.
opt_expirationTime is only used when the storage value is read. Since get/set storage value is asynchronous in AMP. We need to make sure that multiple calls to SESSION_ID are handled in order.
Multiple Vendors
Since there will be only one session id stored. In the case where multiple vendors are using the SESSION_ID, the same id with the same duration will need to be shared.
Launch tracker
/cc @ampproject/wg-approvers on adding the storage entry
@ampproject/wg-analytics on the macro design