feat: add tutorial redirect modal #584
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

This modal should appear only to users that land on a lesson page from a search engine result, mostly.
The logic for this is as follow:
Breaking it down:
typeof document !== 'undefined' && // not available in prerenderDon't prerender the pages with the modal
tutorialRedirectModal.referrer.SEARCH_ENGINES.some(searchEngine => document.referrer.includes(searchEngine.url))The document referrer indicates where the user came from. So if it's present, then we know for sure the user was linked from another website to this lesson page.
In this condition we are only show the modal to users if they came from a search engine result link.
this.lesson.id !== 1Do not show users the modal if they landed on the first lesson of the tutorial.
this.lesson.type !== 'resources'Do not show users the modal if they landed on the resources page.
!isLessonPassed(this.tutorial, this.lesson)Do not show users the modal if they already passed the lesson.
Considerations
document.referrerproperty comes up when linked from another website, but it is absent when users use bookmark links or OS apps. For example, when opening a lesson from Slack, referrer will be empty, but if the user clicks a link from google.com search results, the referrer will behttps://google.com. This means the referrer will also have a value in situations when any blog or social media post links to ProtoSchool lessons.https://protos.school/blog/02?noTutorialRedirectModal=true. UPDATE: instead, we opted to only show it to users who are coming from search engines. With this users won't get the modal when coming from direct links or other situations, except for search engines.How to test this PR
document.referrerproperty, we need to simulate it.Because opening lessons from within the ProtoSchool website doesn't work, we can search on google for "filecoin storage verification" and then edit the link to one specific lesson, eg, lesson 6 through the dev tools, using the preview domain of this PR. When clicking the link it should show up the modal.