I am able to get a previous page name but in the same hit that variable value get changed to the current page name. Can you please suggest on this?
I have also encountered the same issue with my previous experience. It was due to different actions happening in between 2 pages. The action could be below:
1. Reload of page.
2. Form submit can be happen.
3. redirection to same page.
You can check for other actions which are happening on your current page. If you are sure non of the above action is happening, you can contact Adobe support.
Also, It should not happen accross the website. If it's happenning across the website, something is wrong with the configuration.
This sounds like the getPreviousValue plugin is being called multiple times in the same page load.
One thing to check is that you are only calling getPreviousValue when a page view occurs (e.g. not on link tracking calls or other events).
For instance, if you've put the getPreviousValue function call in doPlugins it's easy to accidently cause this to run multiple times as doPlugins runs all the time for various reasons (not just on page view).