Search code examples
coldfusionlucee

How do websites show "help" blocks until the user clicks X to not to see them again


On some web sites you visit, they'll provide instructions or help or count how many times you've dismissed a help/insight. Are they typically done with a cookie, updating a database record for the user's profile or what?

The web app I'm working on has a bulleted list of steps to perform. The client is asking for that to be dismissable rather than collapsible as it is now (the user has to minimize it every time they hit the page). Normally I'd just update the user's profile where a column might be showHelpText with a bit value.

Since this is a per page setting, I'm thinking of creating a mapping table that I can query searching for cgi.script_name (Adobe CGI Server Variables) and the userID. If a record exists, don't show the help. If no records found, show the help text. Is there a more efficient way to accomplish this. Cookies are out since the user could be using different devices/pc/tablets/etc. Showing the help again is not a part of this request.


Solution

  • I think that in this situation i'd would do use the local storage api and add a field to the user record in the db called 'ui_preferences' which would be a copy of local storage value, on load if the value doesn't exist you could fetch it, allowing the values to propagate between devices.

    Psuedo Js;

    someCustomObject.savePreferences(uiPreferences);
    /* somewhere in the method call: */
      var uiPreferences = {'helpDialog':{'pageNameHere': true}};
      localStorage.setItem('uiPreferences', JSON.stringify(uiPreferences));
    

    So the when the page loads you could go;

    var uiPreference = someCustomObject.getPreference('somepreference');
    

    Which could check local storage for the preference, and if it doesn't exists ping the server for it. You custom js object could deal with default values, meaning you don't need a fixed schema for the preferences. Seeing as local storage is effectively just a key value store you would only ever need one column in the db to store a large-ish text field.