Last updated January 16, 2012. Created by queryblitz on December 11, 2011.
Log in to edit this page.

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);
print $count;

Then set up a trigger that occurs "When a user account has been created", and add the action "Grant points to a user" and for the User, select "registered user". For "Number of points", put the token you created with Custom Tokens, which will be something like [account:token_custom_awesome_nodes]. That gives the user 1 point per answer.

You can test it out by, going to queryblitz.com and clicking "Answer Queries". After you answer a few, set up an account and see how many QueryPoints you have! (Default is 20 QueryPoints, so add that in).

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.