Skip to content

API Reference

GravitumLabs edited this page Aug 8, 2016 · 1 revision

API Reference

List of Methods

  • SetUserId
  • SetUserName
  • SetFacebookId
  • SetDevicePushToken
  • SetUserBirthday
  • SetUserGender
  • Init
  • SendEvent
  • SendPurchaseEvent
  • SessionStart
  • SessionEnd

SetUserId

SetUserId is optional method. You may provide your own user id in certain cases (e.g. you want to use Google Play Services/Game Center player id as the unique user id for Gravitum service or you have your own web server with the custom player authentication), otherwise, it will be generated automatically. Just make sure, that the Id you provide will be unique for each user.

Parameters

String userId - unique user Id depending on your implementation.

Example:

Analytics.SetUserId(user_id);
Analytics.Init(this, APP_TOKEN, APP_SECRET, SENDER_ID);

SetUserName

To provide the user name use SetUserName method with the string name. Unlike the used Id, user name may not be unique. What name to provide is up to you without any restrictions.

Parameters

String userName - user Name depending on your implementation.

Example:

Analytics.SetUserName(user_name);
Analytics.Init(this, APP_TOKEN, APP_SECRET, SENDER_ID);

SetUserFacebook

Set user Facebook Id via SetFacebookId method call. The common approach if to get the user Facebook Id from Facebook SDK itself and provide to Gravitum Analytics.

Parameters

String facebookId - the user Id from Facebook SDK.

Example:

Analytics.SetFacebookId(facebookId);
Analytics.Init(this, APP_TOKEN, APP_SECRET, SENDER_ID);

SetDevicePushToken

If you have your own push notifications service implementation, you may use SetDevicePushToken method to provide the unique Id for each user device. If you don't pass any particular token, the Gravitum will generate push token by itself according to the Google Cloud Messaging SenderId you provided with the Init method.

Parameters

String pushToken - the push token for current user device provided from your push notification service.

Example:

Analytics.SetDevicePushToken(device_push_token);
Analytics.Init(this, APP_TOKEN, APP_SECRET, SENDER_ID);

SetUserBirthday

The name of this method speaks for itself. Provide the user birthday via java.util.Date object.

Parameters

java.util.Date date - date of birth for current user.

Example

Calendar birth = Calendar.getInstance();
birth.set(1989, 5, 24);

Analytics.SetUserBirthday(new Date(birth.getTimeInMillis()));
Analytics.Init(this, APP_TOKEN, APP_SECRET, SENDER_ID);

SetUserGender

The name of this method speaks for itself. Provide the user gender via Analytics.Gender enum constant.

Parameters

Analytics.Gender gender - the gender of the current user.

Example

Analytics.SetUserGender(Analytics.Gender.MALE);
Analytics.Init(this, APP_TOKEN, APP_SECRET, SENDER_ID);

Init

The only required method you need to call to set up Gravitum Analytics. To properly initialize Gravitum Android SDK add the following code to the onCreate method on your Activity class.

Parameters

Activity mainActivity - the main (or in some cases launcher) activity of your game project. String appToken - the App Token from your Gravitum Developer Dashboard. String appSecret - the App Secret from your Gravitum Developer Dashboard. String senderId - Sender ID you can find in your Google Play Developer Console (more information here).

Example

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Analytics.Init(this, APP_TOKEN, APP_SECRET, SENDER_ID);
}

SendEvent

The simplest way to send events. Use this method if you don't need to send the data with your event. When just the event Id will be enough for you.

Parameters

String eventId - unique event Id depending on your implementation.

Example

Analytics.SendEvent("first_start");

SendEvent (with event data)

Send an event with provided Id and event data. You will track this event in your Autopush Developer Dashboard.

Parameters String eventId - unique event Id depending on your implementation. HashMap<String, Object> eventData - you can provide any event data you want as a HashMap. What data to send with analytics event depends on your game project.

Example

HashMap<String, Object> data = new HashMap<>();
data.put("str_data", "hello_data");
data.put("float_data", 3.14f);
data.put("int_data", 10101);
Analytics.SendEvent("simple_event", data);

SendPurchaseEvent

One more specific Analytics event type is Purchase event. The common approach is to track the In-App Purchases with such kind of events. So, send this event every success In-App Purchase. Provide the product Id, price and the currency code of the real In-App Purchase. All these events you will find in one place in Gravitum Dashboard.

Parameters

String eventId - unique In-App product Id. float price - In-App product price. String currency - user locale currency code.

Example

Analytics.SendPurchaseEvent("coins_pack", 0.99f, "USD");

SessionStart

To setup session tracking you have to add two method calls in the right places of your Activity class. The first one is Analytics.SessionStart. Add this method to onResume method

Example

@Override
public void onResume() {
    super.onResume();

    Analytics.SessionStart();
}

SessionEnd

This method used for sending the request to the server about game session stop. Analytics.SessionEnd method should be called from onPause method of your main activity.

Example

@Override
public void onPause() {
    super.onPause();

    Analytics.SessionEnd();
}

Clone this wiki locally