Modify the content to display from CMS based on user preference/local storage

I am trying to capture a user preference e.g. Country or State (likely using local storage/cookie) and then modify the content I get from CMS based that before displaying to the user. How can I achieve this? Any tutorial or hints to achieve this would be helpful. I am ok if some level of coding is involved.