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

MWPW-140481: Delayed modal #1939

Merged
merged 6 commits into from
Mar 20, 2024

Conversation

mirafedas
Copy link
Contributor

@mirafedas mirafedas commented Feb 28, 2024

This feature enables the delayed display of a modal, primarily intended for promotional purposes.

When parsing the promotional manifest, if we encounter the insertContentAfter rule containing a link with a delay parameter set to any positive number we dynamically generate a hidden link within the specified selector. The selector should point to any element inside 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.
When 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.

@mirafedas mirafedas requested a review from a team as a code owner February 28, 2024 14:06
@mirafedas mirafedas added needs-verification PR requires E2E testing by a reviewer @modal Run Modal Tests Nala labels Feb 28, 2024
Copy link

codecov bot commented Feb 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.34%. Comparing base (fa5f12a) to head (6aafe94).

❗ Current head 6aafe94 differs from pull request most recent head 7b9d092. Consider uploading reports for the commit 7b9d092 to get more accurate results

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.
📢 Have feedback on the report? Share it here.

@mirafedas mirafedas changed the title MWPW-140481: Delayed modal [WIP] MWPW-140481: Delayed modal Feb 28, 2024
@mirafedas mirafedas force-pushed the MWPW-140481-delayed-modal-stage branch from 67ae3e0 to 4f6aad4 Compare February 28, 2024 16:18
@@ -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=');
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

@mirafedas mirafedas force-pushed the MWPW-140481-delayed-modal-stage branch from 99c1d32 to f7468ce Compare March 1, 2024 10:55
@mirafedas mirafedas changed the title [WIP] MWPW-140481: Delayed modal MWPW-140481: Delayed modal Mar 1, 2024
@mirafedas mirafedas changed the title MWPW-140481: Delayed modal [WIP] MWPW-140481: Delayed modal Mar 1, 2024
@mirafedas mirafedas added the run-nala Run Nala Test Automation against PR label Mar 1, 2024
@mirafedas mirafedas changed the title [WIP] MWPW-140481: Delayed modal MWPW-140481: Delayed modal Mar 1, 2024
@mirafedas mirafedas force-pushed the MWPW-140481-delayed-modal-stage branch 3 times, most recently from ad0c379 to 8fc763f Compare March 7, 2024 10:26
@mirafedas mirafedas force-pushed the MWPW-140481-delayed-modal-stage branch from 7e05127 to 91f7b67 Compare March 7, 2024 11:17
@Roycethan
Copy link

@mirafedas

  1. Looks like modal-hash:modalOpen is not triggered during launch
    2)Click event outside the modal has web interaction name 'modalClose:buttonClose'
    Ideally it should be : 'modalClose:overlayClose' to distinguish between button click and outside clicks.
    3)Link clicks ( save, see terms) also should have defined web-interaction name

@mirafedas
Copy link
Contributor Author

@Roycethan

  1. I cannot reproduce, for me modal-hash:modalOpen is triggered every time. Could you please try in the browser dev tools > Application > Session storage > mwpw-140481-delayed-modal-stage--milo--mirafedas.hlx.live removing the key shown:#delayed-modal, and reload the page to check again?

  2. Currently on production for all modals we emit the modalClose: button-close event no matter if the button or overlay was clicked.
    Changing this falls outside of the scope of this ticket, we'd need to create a separate ticket to change event names for all modals.

  3. For this we also need a separate ticket, because this is related to the fragment links functionality, and not to the modal.
    Both 2 and 3 are not in the ticket AC.

@Roycethan
Copy link

Hi @mirafedas Since you asked analytics feedback in the ticket , updated these from my side as well
#1 was talking about analytics event and not session storage log
#2 Yes this existing a.com production behavior ex: https://www.adobe.com/creativecloud/plans.html#cct-all-apps-products-includes
#3 as well needed for tracking.
Plz add a future ticket for reference or create one when you have it... As far as Functionality perspective this looks good to me. Thank you

@mirafedas
Copy link
Contributor Author

@Roycethan
About analytics, I'll ask Samuel Wang to create the ticket and describe all the requirements, just to be sure we don't mess up the statistics with this change.
About the open event not being triggered, let's have a call and take a look at it together, I'll explain about the session storage key :)

const delayedModalRegExp = /\/.*?#.*?:delay=[1-9][0-9]*/; // matches 'anytext/#anytext:delay=anynumbers(followed by any text)
let isDM = false;
try {
isDM = delayedModalRegExp.test(url);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

@mirafedas mirafedas force-pushed the MWPW-140481-delayed-modal-stage branch from dea9408 to cf0e085 Compare March 12, 2024 16:36
@Roycethan Roycethan added verified PR has been E2E tested by a reviewer and removed needs-verification PR requires E2E testing by a reviewer labels Mar 12, 2024
@mirafedas mirafedas force-pushed the MWPW-140481-delayed-modal-stage branch 2 times, most recently from 2763227 to 8c1704e Compare March 19, 2024 10:42
@mirafedas mirafedas added run-nala Run Nala Test Automation against PR and removed run-nala Run Nala Test Automation against PR labels Mar 19, 2024
@mirafedas mirafedas marked this pull request as draft March 19, 2024 11:28
@mirafedas mirafedas force-pushed the MWPW-140481-delayed-modal-stage branch from 8c1704e to 7d0eb35 Compare March 19, 2024 11:30
@mirafedas mirafedas force-pushed the MWPW-140481-delayed-modal-stage branch from 7d0eb35 to 5557d8f Compare March 19, 2024 11:31
@honstar
Copy link
Contributor

honstar commented Mar 19, 2024

@mirafedas , what's the reason for marking this PR as draft? Draft PRs are generally discouraged, please see https://github.com/adobecom/milo/wiki/Submitting-PRs#drafts-prs.

@mirafedas mirafedas marked this pull request as ready for review March 19, 2024 12:26
@Blainegunn
Copy link
Contributor

Blainegunn commented Mar 19, 2024

@mirafedas PSI check is failing.
Can you get it to pass or give a reason why it won't hurt performance please?
I've looked into this and the reason is the test pages aren't meant to perform.
Please fix merge conflicts. thank you

@mirafedas
Copy link
Contributor Author

@Blainegunn
Merge conflicts resolved.
I did not place a marquee on my test page, so the image inside a delayed modal was considered an LCP, and as the modal was rendered with a delay, it impacted the statistics. I added the marquee, and now the page speed result is green.

@Blainegunn Blainegunn merged commit cdd1952 into adobecom:stage Mar 20, 2024
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@modal Run Modal Tests Nala Ready for Stage run-nala Run Nala Test Automation against PR verified PR has been E2E tested by a reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants