Expand my Community achievements bar.

Adobe Summit is live! Tune in to take part in the premier digital experience event.
SOLVED

Adobe target test for last page visited and showing continue link with link to previous page visited in the previous session

Avatar

Level 1

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.

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @GauravDu1 

what an interesting case. I would approach it this way.

  1. Create a profile scripts (visitNumber) that counts the visit number. You'll use this to create a segment so you only target visitors on their #2 visit.
    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.

  2. Create a profile script (pageUrl) that captures the URL of the page on every page view, to ensure you get the page URL of their last page they visit.
    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.

  3. The popup itself to be hosted in your activity.
    <!-- 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.


I share weekly Adobe tips on LinkedIn—connect with me!

Every Wednesday: "Something a client recently asked..."

LinkedIn Profile

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @GauravDu1 

what an interesting case. I would approach it this way.

  1. Create a profile scripts (visitNumber) that counts the visit number. You'll use this to create a segment so you only target visitors on their #2 visit.
    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.

  2. Create a profile script (pageUrl) that captures the URL of the page on every page view, to ensure you get the page URL of their last page they visit.
    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.

  3. The popup itself to be hosted in your activity.
    <!-- 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.


I share weekly Adobe tips on LinkedIn—connect with me!

Every Wednesday: "Something a client recently asked..."

LinkedIn Profile