-
Notifications
You must be signed in to change notification settings - Fork 175
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
MWPW-140481: Delayed modal #1939
MWPW-140481: Delayed modal #1939
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## stage #1939 +/- ##
==========================================
- Coverage 96.36% 96.34% -0.02%
==========================================
Files 166 166
Lines 42531 42562 +31
==========================================
+ Hits 40986 41008 +22
- Misses 1545 1554 +9 ☔ View full report in Codecov by Sentry. |
67ae3e0
to
4f6aad4
Compare
@@ -109,7 +109,8 @@ const createFrag = (el, url, manifestId) => { | |||
let href = url; | |||
try { | |||
const { pathname, search, hash } = new URL(url); | |||
href = `${pathname}${search}${hash}`; | |||
const isDelayedModal = hash?.includes(':delay=') && hash.includes(':display='); |
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.
Does display
have to be a required property? I guess it'd be annoying to have a delayed modal every time.
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.
good point, I guess I can make one of the display values a default one, so that authors would need to specify this only if they want a second value to be applied. I will ask Fred which one should be a default one, 'pageload' or 'session' and update the PR
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.
UPD: turns out I misunderstood the requirements, instead of two display modes there will be only one. The modal should be shown on every page a user visits only once during one browser session. I updated the code, tests, and documentation.
99c1d32
to
f7468ce
Compare
ad0c379
to
8fc763f
Compare
7e05127
to
91f7b67
Compare
|
|
Hi @mirafedas Since you asked analytics feedback in the ticket , updated these from my side as well |
@Roycethan |
const delayedModalRegExp = /\/.*?#.*?:delay=[1-9][0-9]*/; // matches 'anytext/#anytext:delay=anynumbers(followed by any text) | ||
let isDM = false; | ||
try { | ||
isDM = delayedModalRegExp.test(url); |
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.
When does regex test
throw an error? I'm not aware of any value that would cause it to.
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.
The line break can cause the error, e.g.
const delayedModalRegExp = /\/.*?#.*?:delay=[1-9][0-9]*/;
delayedModalRegExp.test('This is a string
with a line break.')
// Uncaught SyntaxError: Invalid or unexpected token
I know it's pretty unlikely this may happen, but authors may copy-paste such string into Excel from somewhere else, so I decided to add this checking as we don't have any validation on the authoring side.
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.
Do you think there is a use case where a delayed modal would be triggered by a cta on the page? I can't think of why that would ever be needed. If that's the case, then I think we can move this logic directly into modal.js.
function delayedModal
could directly add el.classList.add('hide-block');
to the modal link.
Then we don't even need any support for #hide
, and there's no code changes needed in personalization.js
dea9408
to
cf0e085
Compare
2763227
to
8c1704e
Compare
8c1704e
to
7d0eb35
Compare
7d0eb35
to
5557d8f
Compare
@mirafedas , what's the reason for marking this PR as |
@mirafedas PSI check is failing. |
@Blainegunn |
This feature enables the delayed display of a modal, primarily intended for promotional purposes.
When parsing the promotional manifest, if we encounter the
tag. The inserted link behaves conventionally, triggering a modal upon click. Following this setup, we introduce a delay of some seconds before unveiling the modal, simultaneously appending a modal hash to the browser's URL. After the modal is displayed once on the page, we remember this in sessionStorage to prevent subsequent displays upon page reload.insertContentAfter
rule containing a link with adelay
parameter set to any positive number we dynamically generate a hidden link within the specified selector. The selector should point to any element inside theWhen the modal is opened, we send the analytics event with the following name format:
modal-hash:modalOpen
.The rest of the analytics events remain the same as before.
Resolves: MWPW-140481
Authoring documentation
Test URLs:
Before: not applicable, because this is a newly added feature
After:
First page
Second page
Third page
Feel free to change the
delay
params in this file.