Skip to content

✨[amp-analytics] Introduce Session ID concept and SESSION_ID macro#34521

Merged
micajuine-ho merged 7 commits intoampproject:mainfrom
micajuine-ho:session_id
Jun 18, 2021
Merged

✨[amp-analytics] Introduce Session ID concept and SESSION_ID macro#34521
micajuine-ho merged 7 commits intoampproject:mainfrom
micajuine-ho:session_id

Conversation

@micajuine-ho
Copy link
Copy Markdown
Contributor

@micajuine-ho micajuine-ho commented May 25, 2021

Closes #29324
Partial for #33990

A Session Id is per user per domain per vendor persisted for 30 minutes (extended each time session_id is used) in localStorage, via the Storage API, on both the origin and within the viewer.

The Session Id value is a low entropy pseudorandom number from 0-9999.

This PR introduces this concept and creates the manager to store/retrieve this information (SessionManager) along with the SESSION_ID macro only to be used by amp-analytics. The session manager is a service installed by amp-analytics and shared between all amp-analytics elements, similar to the Linker. We store the session information under the key amp-session: + ${vendorType}. We also keep the accessed session information in memory to avoid reading from localStorage each time SESSION_ID is used/extended.

Following PRs will add additional Session Analytics for each session (see #33990), stored under the same key in localStorage.

Copy link
Copy Markdown
Contributor

@rsimha rsimha left a comment

Choose a reason for hiding this comment

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

Build changes LGTM.

@micajuine-ho micajuine-ho requested a review from jridgewell May 28, 2021 16:06
@micajuine-ho
Copy link
Copy Markdown
Contributor Author

/cc @jridgewell for bundle size check

@micajuine-ho
Copy link
Copy Markdown
Contributor Author

@rebeccanthomas PTAL

@micajuine-ho micajuine-ho requested a review from alanorozco June 3, 2021 14:42
@micajuine-ho
Copy link
Copy Markdown
Contributor Author

@rebeccanthomas @alanorozco PTAL when you can

/**
* Checks if a session has expired
* @param {SessionInfoDef} session
* @return {!Promise}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* @return {!Promise}
* @return {boolean}

Consider making it a standalone function as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What's the benefit of doing so?

Copy link
Copy Markdown
Member

@alanorozco alanorozco Jun 16, 2021

Choose a reason for hiding this comment

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

@micajuine-ho It's more flexible to use a function when the instance state is not looked at. You can move functions around, use them outside a specific class, and they get DCE'd more easily.

Copy link
Copy Markdown
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

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

Build size

@micajuine-ho micajuine-ho merged commit ef178d1 into ampproject:main Jun 18, 2021
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

Successfully merging this pull request may close these issues.

I2I: Session Id Support in AMP Analytics

4 participants