I am doing a test where the user is to be shown a pop up with continue link that will take him to previous page link . Now that pop up will come in the users next visit . And link will be from his last session last page which he exited . The pop up should show only only on the home page and should show only on the next visit and once shown should not be shown again . I am having trouble in writing the script where these conditions are met. Can someone pls help in this ?
Conditions-
1. Activity only on Home Page
2. Activity to be shown in the next visit only once.
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @GauravDu1
what an interesting case. I would approach it this way.
if (user.sessionId !== user.getLocal('lastSessionId')) {
user.setLocal('lastSessionId', user.sessionId);
return (user.get('visitNumber') || 0) + 1;
}
Note: important you activate this script same time as the activity, so you start counting visits when the activity is live.
if (user.get('visitNumber') === 1) {
return page.url;
}
return null;
Notice the logic which ensures it only captures this in their first visit. Otherwise it would result in the most recent URL in their #2 visit that would be in the popup.
<!-- Popup container (initially hidden) -->
<div id="popup" style="display: none;">
<p>Continue where you left off</p>
<a id="continueLink" href="${profile.pageUrl}">Continue my journey</a>
</div>
<script>
// Display the popup
function showPopup() {
document.getElementById('popup').style.display = 'block';
}
// When the page loads, show the popup
document.addEventListener('DOMContentLoaded', function() {
showPopup();
});
</script>
Notice that the href is dynamically set by referencing the profile script containing the URL, so the popup always will link to the most recent URL that the user visited in their first visit.
There are most likely others and potentially also more elegant ways to achieve the same. Hopefully this is still helpful.
Hi @GauravDu1
what an interesting case. I would approach it this way.
if (user.sessionId !== user.getLocal('lastSessionId')) {
user.setLocal('lastSessionId', user.sessionId);
return (user.get('visitNumber') || 0) + 1;
}
Note: important you activate this script same time as the activity, so you start counting visits when the activity is live.
if (user.get('visitNumber') === 1) {
return page.url;
}
return null;
Notice the logic which ensures it only captures this in their first visit. Otherwise it would result in the most recent URL in their #2 visit that would be in the popup.
<!-- Popup container (initially hidden) -->
<div id="popup" style="display: none;">
<p>Continue where you left off</p>
<a id="continueLink" href="${profile.pageUrl}">Continue my journey</a>
</div>
<script>
// Display the popup
function showPopup() {
document.getElementById('popup').style.display = 'block';
}
// When the page loads, show the popup
document.addEventListener('DOMContentLoaded', function() {
showPopup();
});
</script>
Notice that the href is dynamically set by referencing the profile script containing the URL, so the popup always will link to the most recent URL that the user visited in their first visit.
There are most likely others and potentially also more elegant ways to achieve the same. Hopefully this is still helpful.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies