DEV Community

Cover image for Enhancing User Experience: The Importance of "Pick Up Where You Left Off"
Vivek Mengu
Vivek Mengu

Posted on • Updated on

Enhancing User Experience: The Importance of "Pick Up Where You Left Off"

In the vast landscape of the digital world, where users navigate through a multitude of websites, the ability to pick up where you left off can significantly impact user experience. Whether it's an online shopping cart, a content-rich platform, or a productivity tool, remembering user selections plays a crucial role in fostering a seamless and personalised interaction.

In this blog, we'll explore why it's important to remember user selections and delve into the necessary steps to enhance user experience through storing information in various browser storage mechanisms.


Importance of Remembering User Selections:

 
Continuity of Experience:

One of the key reasons to remember user selections is to provide a continuous and uninterrupted experience. Imagine a scenario where a user has spent time customising their preferences on a website or application, only to lose all that data upon closing or refreshing the page. By storing this information, users can seamlessly resume their activities without frustration.

Personalisation:

Remembering user selections enables a more personalised experience. Whether it's the preferred language, theme, or saved items in a shopping cart, tailoring the user interface to individual preferences enhances engagement and encourages users to return to the platform.

Efficiency and Time-Saving:

For users engaging in complex or time-consuming tasks, remembering selections can save valuable time. This is particularly true for forms, where users often need to fill in multiple fields. By storing entered information, users can quickly pick up where they left off, avoiding the need to re-enter data.

 

Understanding User Persistent State:

The concept of remembering user selections is often referred to as "persistent state" or "user persistence" It involves the ability of a system or application to retain and recall specific user choices or configurations across different sessions or interactions. Persistent state is crucial for creating a seamless and personalised user experience by allowing users to pick up where they left off, maintaining their preferences, settings, and selected options over time.

In web development and software design, achieving persistent state often involves storing relevant information on the client-side, utilising technologies such as localStorage, sessionStorage, cookies, IndexedDB or URL Params. These storage mechanisms enable the application to remember and retrieve user selections, providing continuity and customisation in the user's interaction with the platform.


Real-Life Example: Customising e-Commerce Platform Experience

Meet Alex, an enthusiastic shopper who regularly engages with an e-commerce platform to explore the latest products and make purchases. Alex has distinct preferences, including navigating to specific product categories, applying filters to refine search results, utilising sorting options for a more organised view, and opting for a visually appealing dark mode for extended browsing sessions.

 

Data Storage for Specific Scenarios:

Choosing the most suitable storage mechanism is crucial, requiring thoughtful consideration to align with the unique requirements of your implementation and ensure optimal performance.

Transactional Data:
Use sessionStorage for storing temporary data related to a specific transaction or interaction, ensuring that it is cleared once the user leaves the session.

User Authentication:
Utilise cookies to securely store and recall user login details, offering a convenient and streamlined authentication process during subsequent visits to the platform.

User Preferences:
Store user preferences and settings in localStorage to maintain a consistent experience across sessions.

Long-Term Data:
For applications requiring long-term data storage, such as a recent search history, utilise IndexedDB to ensure reliable and efficient retrieval of information.

Page State via URL:
URL parameters can also be used to maintain state. This is particularly useful if you want to share the state via a URL.


Let's integrate the lionxstorage library to enhance Alex's experience on the e-commerce platform.

lionxStorage is a Javascript and React library that provides a unified interface for storing and retrieving data using various storage mechanisms such as localStorage, sessionStorage, cookies, and indexedDB. It is designed to work seamlessly in both Javascript and React environments.

For more detailed information, refer to the lionxstorage library documentation available at: lionxStorage GitHub Repository.

 

Let's Begin....

Alex, a devoted visitor to our e-commerce store, deserves a seamless experience. To ensure he doesn't need to log in daily, we can use cookies for authentication. By setting an expiry date, we can maintain the authentication for a specified duration, providing seamless access for Alex.


// Code to store authentication in cookies
const authenticationData = {
  userId: 'Alex123',
  emailId: 'alex@email.com',
  token: 'Bearer ...'
};

const cookiesData = new lionxStorage("cookies");

const expireData = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000); // Set to expire in 30 days
cookiesData.set("authData", authenticationData, { expires: expireData, path: '/'});

const retrieveData = cookiesData.get("authData");

console.log( retrieveData );

Enter fullscreen mode Exit fullscreen mode

Understanding Alex's preferences, we want to streamline his product discovery. Storing his favourite product details, such as preferred sizes, colours, and price ranges, in localStorage ensures these specifications are pre-selected or prominently displayed.


// Code to store preferred product details in localStorage
const preferredDetails = {
  sizes: ['M', 'L'],
  colours: ['Blue', 'Black'],
  priceRange: '$50 - $100',
};

const localStorageData = new lionxStorage("localStorage");
localStorageData.set("preferredDetails", preferredDetails);

const retrieveData = localStorageData.get("preferredDetails");

console.log( retrieveData );

Enter fullscreen mode Exit fullscreen mode

Now, each time Alex performs a search, the platform intelligently stores the search title and url in the IndexedDB. This strategic move is designed to empower Alex with the ability to quickly revisit his recent searches, offering him a convenient way to click on a title and promptly retrieve the desired product.

This thoughtful integration not only streamlines Alex's exploration process but also contributes to a more personalised and user-friendly shopping journey, ensuring he can effortlessly find what he's looking for


const indexedDBData = new lionxStorage("indexedDB", "userData", 1);

async function indexedDBStorage() {
  try {
    indexedDBSDK.init(["search"]);

    indexedDBSDK.set("search", { id: 1, title: "running shoes in red", url: 'https://example.com?search=...' });
    indexedDBSDK.set("search", { id: 2, title: "sports wear", url: 'https://example.com?search=...' });

    const retrieveData = await indexedDBSDK.get("search");

    console.log( retrieveData );

  } catch (error) {
    console.log("IndexedDB caught error : ", error);
  }
}

Enter fullscreen mode Exit fullscreen mode

As Alex explored the e-commerce store, he found a product he liked and proceeded to checkout. Halfway through, he decided to change the product's colour from blue to black.

Thanks to sessionStorage, the platform effortlessly retained his payment and shipping details, ensuring a smooth and uninterrupted checkout experience as he adjusted the product colour on the single product page.


// Code to store transaction details in sessionStorage
const transactionDetails = {
  productId: '12345',
  productName: 'Sports Shoes',
  quantity: 1,
  totalAmount: '$75.00',
  // ... other transaction details
};

const sessionStorageData = new lionxStorage("sessionStorage");
sessionStorageData.set("transactionDetails", transactionDetails);

const retrieveData = sessionStorageData.get("transactionDetails");

console.log( retrieveData );

Enter fullscreen mode Exit fullscreen mode

Note: The data stored in sessionStorage is automatically cleared when the session ends, such as when the user closes the browser or tab. This automatic cleanup ensures that sensitive transaction details are not retained unnecessarily.

As Alex discovered the perfect pair of sports shoes on the e-commerce platform, he wanted to share his find with a friend while preserving the specific details he had in mind, including the price range, colour, and size.

Leveraging URL parameters, Alex effortlessly encoded these selections into a personalised URL. Now, when his friend opens the link, the product page loads with the exact specifications, creating a seamless and personalised experience for anyone accessing the shared URL.


// Code to generate a URL with parameters
const productDetails = {
  productId: '12345',
  priceRange: '$50 - $100',
  colour: 'Black',
  size: 'M',
  // ... other product details
};

// Convert product details to URL parameters
const urlParams = new URLSearchParams(productDetails);

// Generate the product URL with encoded parameters
const productURL = `https://example.com/product?${urlParams.toString()}`;

// Alex can now share this URL with his friend
console.log(productURL);

Enter fullscreen mode Exit fullscreen mode

With these implementations, we guarantee Alex a personalised and convenient shopping experience.

 

Conclusion:

By implementing these storage mechanisms tailored to specific use cases, the e-commerce platform creates user-centric environments for individuals like Alex. The ability to seamlessly pick up where Alex left off, whether it's revisiting favourite product categories, maintaining personalised filters, or adhering to a preferred visual theme, not only streamlines the user experience but also cultivates continued engagement and loyalty. Alex feels acknowledged and valued, fostering a positive relationship between the user and the digital platform. In essence, remembering user selections transforms a casual visitor into a satisfied and returning user, illustrating the tangible benefits of thoughtful data storage strategies.

User persistent state is not just a technical aspect; it's a commitment to delivering a user-centric experience that adapts to individual preferences. From websites to incorporating persistent state functionality significantly contributes to user satisfaction, loyalty, and a sense of being truly understood. As developers continue to prioritise this aspect, we can expect digital interactions to become increasingly seamless and tailored, fostering a positive and lasting connection between users and the platforms they engage with.

Top comments (1)

Collapse
 
sagarcs profile image
sagarCS

very well expalined....worth reading!