3
\$\begingroup\$

Is it possible to see how many of your users have unlocked certain achievements on the Google Play Developer console? This information would be very useful. I guess that one could achieve this through integration with Google Analytics but I was wondering if there was a simpler way to get this data.

\$\endgroup\$
2
\$\begingroup\$

The Google Play Games service actually provides an API for doing just that. I have provided an example for querying the state of all achievements in this answer on SO - but I will provide that information here as well.

The following method will retrieve and iterate all achievements, and should be run asynchronously (using AsyncTask or in a separate thread):

public void loadAchievements()  {
   GameHelper mHelper;        // GameHelper should be accessible for this to work

   boolean fullLoad = false;  // set to 'true' to reload all achievements (ignoring cache)
   float waitTime = 60.0f;    // seconds to wait for achievements to load before timing out

   // load achievements
   PendingResult p = Games.Achievements.load( mHelper.getApiClient(), fullLoad );
   Achievements.LoadAchievementsResult r = (Achievements.LoadAchievementsResult)p.await( waitTime, TimeUnit.SECONDS );
   int status = r.getStatus().getStatusCode();
   if ( status != GamesStatusCodes.STATUS_OK )  {
      r.release();
      return;           // Error Occurred
   }

   // process the loaded achievements
   AchievementBuffer buf = r.getAchievements();
   int bufSize = buf.getCount();
   for ( int i = 0; i < bufSize; i++ )  {
      Achievement ach = buf.get( i );

      // here you now have access to the achievement's data
      String id = ach.getAchievementId();  // the achievement ID string
      boolean unlocked = ach.getState == Achievement.STATE_UNLOCKED;  // is unlocked
      boolean incremental = ach.getType() == Achievement.TYPE_INCREMENTAL;  // is incremental
      if ( incremental )
         int steps = ach.getCurrentSteps();  // current incremental steps
   }
   buf.close();
   r.release();
}

This assumes you are using BaseGameUtils (and mHelper is already connected). The API documentation should provide any further information you need. You can also do this with callbacks if you don't want to manually run it asynchronously.

You should of course change the internals of the loop which are processing the results to do something more useful, since the example only illustrates how to access the information. For your question you may only need to check for unlocked achievements and count them.

\$\endgroup\$
  • \$\begingroup\$ thanks, I am using BaseGameUtils so your solution should work for me. I was actually hoping for something a bit different though. Almost like an "admin" view of all unlocked achievements, I don't actually want to do this programmatically in my game because I am the only one who should be able to view this data. If there is no such view then I will probably build an "admin" view in the game that I will disable before releasing (or a separate app that only I use) so then I would accept your answer. Although Google Analytics may actually then be an easier option for what I want. \$\endgroup\$ – brent777 Jun 14 '14 at 13:18
  • \$\begingroup\$ btw do you know if you can view exactly who actually has unlocked which achievements? Or is this against some ToS? I know that you are not allowed to do this using Google Analytics. \$\endgroup\$ – brent777 Jun 14 '14 at 13:19
  • 1
    \$\begingroup\$ Oh I see, I think I misread your original question..my bad. To answer the question (properly), in the Developer Console go to the Game services tab, under Achievements there is a column for Unlocked % / Total # / Time which displays exactly what you are looking for :D \$\endgroup\$ – free3dom Jun 14 '14 at 16:08
  • \$\begingroup\$ thanks. For some reason this column just shows a "-" for me. I had a look at the other stats pages (e.g. Players) and they just say "More user data needed to display analytics". However, under "Engagement" it does actually show me correct data and I can see that a bunch of achievements have been unlocked. I have only released the game to about 20 people for testing to date (but it is in a production state), any idea how much data needs to be present before these stats are actually shown? \$\endgroup\$ – brent777 Jun 14 '14 at 22:49
  • \$\begingroup\$ btw I accepted your answer since it is useful and I may use it in the long-term and it would achieve what I wanted as well - although your comment was more useful to me in the short term. \$\endgroup\$ – brent777 Jun 14 '14 at 22:51
2
\$\begingroup\$

Callback approach

Apart from some small errors in the accepted answer I prefer the callback approach to get the results so we don't have to perform all of this in the background.

To simplify comparison I used the same GameHelper. This GameHelper object is a singleton containing a reference to the GoogleApiClient object.

Updated example code:

    GameHelper mHelper;        // GameHelper should be accessible for this to work
    boolean fullLoad = false;  // set to 'true' to reload all achievements (ignoring cache)

    // load achievements
    Games.Achievements.load( mHelper.getGoogleApiClient(), fullLoad ).setResultCallback(new ResultCallback<Achievements.LoadAchievementsResult>() {
        @Override
        public void onResult(Achievements.LoadAchievementsResult loadAchievementsResult) {
            for( Achievement achievement : loadAchievementsResult.getAchievements() ){

                // here you can work with the achievement objects
                // ...
                boolean unlocked = (achievement.getState() == Achievement.STATE_UNLOCKED);
            }
        }
    });
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.