How do I transfer anonymous data the user when he registers? I have a system for storing data (e.g. accessibility settings like colour contrast) for anonymous and authenticated users. Authenticated users have the data in a dedicated table.

For anonymous users I'm using CTools object cache so if the person keeps the session he won't lose his accessibility settings. (I might use this for storing searches as well.)

I could use Session API but there is a potential issue with European cookie law - yes, this is about site usability which theoretically trumps that law but it's a very public site so the client doesn't want any trouble, valid or not.

Okay, so here's the point: If a person registers I need to go from CTools to my custom storage. The actual process of doing that is simple enough but when a person registers, their session ID changes, so once they are logged in (e.g. when hook_user_register() gets called) the old session ID is dead and gone.

Any ideas how I can keep the old session ID, or transfer the data from not-logged-in to logged-in? (Putting the data in form_state in the user_register_form goes some of the distance, but not all of it.)
In fact it turned out to be simple (after spending a long time trying to be clever). 

In hook_form_user_register_form_alter() add a value field to the form... 

$form['mydata'] = array( 
  '#type' =&gt; 'value', 
  '#value' =&gt; $mydata, 
  // in any form you like 
); 


Then in hook_user_insert() that data is in the $edit array, and already added to the $account object. Make sure you unset it from the $edit array otherwise it'll get put into the 'data' field. Anyway by this point the $account has a uid so it's possible to save the data.