How to retroactively reward UserPoints to new users after they register for stuff they did when they were anonymous
This tutorial will show you how to reward anonymous users for interacting with your site, similar to khanacademy.org and queryblitz.com. An example is displaying a message like "You have collected 6 Awards! Log in or Register to claim your prizes."
This tutorial used Flags 2.0, Session API, UserPoints, Token, Custom Tokens, and Rules to give UserPoints to users after they have registered for flags they flagged before they registered.
To give UserPoints to anonymous users for flagging content, first set up a flag. We will call this flag "Awesome". Make sure both anonymous and authenticated users have access to this flag.
Next, create a new token with the Custom Tokens module, set the Type as User and in the PHP text area place the following, exactly as it shows here:
$uid = $account->uid;
$flag = flag_get_flag('awesome') or die('no "awesome" flag');
$count = $flag->get_user_count($uid);