I have 2 custom variables in Google Analytics with scope set to 2(Session). One variable tracks user role and other tracks user Program. Our site works in a way that there would be a single role for different programs. So a user can login with different roles. If different users login in the same browser the custom variables values are overwritten. For example the user logs in where role is 'Admin' and Program is 'ABC'. The Google Analytics would show report 'Admin' 'ABC'
If the user logs off and logs in without closing the browser with role as 'Admin' program 'DEF' , the Analytics would now show report as 'Admin' 'DEF'. Thus 'ABC' gets replaced.
This does not happen if the user closes the browser and logs in again. If user closes the browser and logs in again, I get report like
Is there a way to prevent overwriting even if the user does not close the browser?
The code is like:
_gaq.push(['_setCustomVar', 1, 'User Role', applicationRoleName, 2]); <br>
_gaq.push(['_setCustomVar', 3, 'Program Name', applicationProgramCode, 2]);
This is expected behavior. If the user logs out of your application and logs in again he is still in the same google analytics session. If he closes the browser he starts a new session, so you get two data sets with different values, one for each session.
So in effect you are asking "can I programmatically start a new tracking session in Google Analytics" to which to my best knowledge the anwser is no (at least not with methods provided by Google, of course you could change the Google cookie manually).
You might try to set setSessionCookieTimeout() to 100 milliseconds (or another ridiculously small value) specifically on your logout page so that sessions expire on logout immediately (and set it back to 0 - which means "session ends on browser close - on the following pages). However this is untested, not approved by Google, will change the way your data is collected and I would not recommend it.
Also my comment on the forced migration to universal analytics still applies.