Following the deprecation of the
[Google Sign-In](https://android-developers.googleblog.com/2024/09/streamlining-android-authentication-credential-manager-replaces-legacy-apis.html)
API, we are removing the games v1 SDK in 2026. After February 2025, you will be unable to publish
titles that are newly integrated with games v1 SDK, on Google Play. We recommend that you use the
games v2 SDK instead.  

While existing titles with the previous games v1 integrations continue to function for a
couple of years, you are encouraged to
[migrate to v2](https://developer.android.com/games/pgs/android/migrate-to-v2)
starting June 2025.  

This guide is for using the Play Games Services v1 SDK. For information
on the latest SDK version, see the
[v2 documentation](https://developer.android.com/games/pgs/android/events).

This guide shows you how to collect player gameplay data for game analytics using the events APIs
provided by Google Play Games Services. The APIs can be found in the
[`com.google.android.gms.games.event`](https://developers.google.com/android/reference/com/google/android/gms/games/event/package-summary)
and [`com.google.android.gms.games`](https://developers.google.com/android/reference/com/google/android/gms/games/package-summary).

## Before you begin

If you haven't already done so, you might find it helpful to review the
[events game concepts](https://developer.android.com/games/pgs/events).

Before you start to code using the events APIs:

- Define the events for your game in the [Google Play Console](https://play.google.com/apps/publish/).
- Follow the [sign-in checklist recommendations](https://developer.android.com/games/pgs/v1/quality#sign-in).

## Get the events client

To start using the events APIs, your game must first obtain an
[`EventsClient`](https://developers.google.com/android/reference/com/google/android/gms/games/EventsClient) object. You can do this by calling the
[`Games.getEventsClient()`](https://developers.google.com/android/reference/com/google/android/gms/games/Games.html#getEventsClient(android.app.Activity,%20com.google.android.gms.auth.api.signin.GoogleSignInAccount)) method and passing in the
activity and the [`GoogleSignInAccount`](https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInAccount) for the current player. To learn how to
retrieve the player account information, see
[Sign-in in Android Games](https://developer.android.com/games/pgs/v1/android/signin).
| **Note:** The [`EventsClient`](https://developers.google.com/android/reference/com/google/android/gms/games/EventsClient) class makes use of the Google Play services [`Task`](https://developers.google.com/android/reference/com/google/android/gms/tasks/Task) class to return results asynchronously. To learn more about using tasks to manage threaded work, see the [Tasks API developer guide](https://developers.google.com/android/guides/tasks).

## Submit events

You can add code in your game to notify Google Play Games Services whenever an
event of interest to your game occurs.

To send an event update, call [`EventsClient.increment()`](https://developers.google.com/android/reference/com/google/android/gms/games/EventsClient.html#increment(java.lang.String,%20int)) with the `eventId` value and an
integer `incrementAmount` that is equal to or greater than 0.

- The `eventId` is generated by Google Play Games Services when you first define the event in the Google Play Console and is used to uniquely identify this event in your game.
- You can use the `incrementAmount` input to specify the player's quantitative progress towards completing some game-specific goal. For example, if the event your game wants to track is *'Defeat 500 bug-eyed monsters'* , the `incrementAmount` value can be the number of monsters that the player killed in a single battle.

Here's an example of how to submit an event with an increment amount of 1:  

```text
public void submitEvent(String eventId) {
  Games.getEventsClient(this, GoogleSignIn.getLastSignedInAccount(this))
      .increment(eventId, 1);
}
```

## Retrieve events

You can retrieve all events data stored in Google's servers for your game, by
calling [`EventsClient.load()`](https://developers.google.com/android/reference/com/google/android/gms/games/EventsClient.html#load(boolean)). In the
method call, pass in a boolean value to indicate if Google Play Games Services should clear the locally
cached data on the user's device.

To retrieve data for specific events that you defined in the Google Play Console, call
[`EventsClient.loadByIds()`](https://developers.google.com/android/reference/com/google/android/gms/games/EventsClient.html#loadByIds(boolean,%20java.lang.String...)) and pass in an array of event IDs in the input parameters.

The following snippet shows how you can query Google Play Games Services for the
list of all events for your game:  

```gdscript
public void loadEvents() {
  Games.getEventsClient(this, GoogleSignIn.getLastSignedInAccount(this))
      .load(true)
      .addOnCompleteListener(new OnCompleteListener<AnnotatedData<EventBuffer>>() {
        @Override
        public void onComplete(@NonNull Task<AnnotatedData<EventBuffer>> task) {
          if (task.isSuccessful()) {
            // Process all the events.
            for (Event event : task.getResult().get()) {
              Log.d(TAG, "loaded event " + event.getName());
            }
          } else {
            // Handle Error
            Exception exception = task.getException();
            int statusCode = CommonStatusCodes.DEVELOPER_ERROR;
            if (exception instanceof ApiException) {
              ApiException apiException = (ApiException) exception;
              statusCode = apiException.getStatusCode();
            }
            showError(statusCode);
          }
        }
      });
}
```