Skip to content

API Reference

Gravitum edited this page Dec 26, 2016 · 7 revisions

List Of Methods

  • SetUserId
  • SetUserName
  • SetFacebookId
  • SetDevicePushToken
  • SetBirthday
  • SetGender
  • SetCustomProperties
  • Init
  • SendEvent
  • SendMonetaryEvent

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

Gravitum.Analytics.SetUserId(user_id);
Gravitum.Analytics.Init ();

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

Gravitum.Analytics.SetUserName(user_name);
Gravitum.Analytics.Init ();

SetFacebookId

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

Parameters

string facebookId - the user Id from Facebook SDK.

Example

Gravitum.Analytics.SetFacebookId(facebookId);
Gravitum.Analytics.Init ();

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

Gravitum.Analytics.SetDevicePushToken(gcmId);
Gravitum.Analytics.Init ();

SetBirthday

The name of this method speaks for itself. Provide the user birthday via System.DateTime object.

Parameters

System.DateTime date - date of birth for current user.

Example

Gravitum.Analytics.SetBirthday(new System.DateTime(1985, 5, 16, 0, 0, 0, 0, System.DateTimeKind.Utc));
Gravitum.Analytics.Init ();

SetGender

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

Parameters

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

Example

Gravitum.Analytics.SetGender(Gravitum.Analytics.Gender.Male);
Gravitum.Analytics.Init ();

SetCustomProperties

You can set custom unique fields for each user.

Parameters

Dictionary<string, object> properties - this property will be used for filtering the segments from the audience of your application. Important: You can set up to 15 custom fields for each user.

Example

Dictionary<string, object> properties = new Dictionary<string, object> ();
properties.Add ("playerProperty1", "Ginger");
properties.Add ("playerProperty2", 36);

Gravitum.Analytics.SetCustomProperties (properties);
Gravitum.Analytics.Init ();

Init

The only required method you need to call to set up Gravitum Analytics. Call this in the first scene that is loaded.

Example

void Start () {
    Gravitum.Analytics.SetUserId(user_id);
    Gravitum.Analytics.SetUserName(user_name);
    Gravitum.Analytics.SetFacebookId(facebookId);
    Gravitum.Analytics.SetDevicePushToken(gcmId);
    Gravitum.Analytics.SetGender(Gravitum.Analytics.Gender.Male);
    Gravitum.Analytics.SetBirthday(new System.DateTime(1985, 5, 16, 0, 0, 0, 0, System.DateTimeKind.Utc));
    Gravitum.Analytics.Init ();
}

SendEvent

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

Parameters

string eventId - unique event Id depending on your implementation.

Dictionary<string, object> eventData - You can provide any event data you want as a Dictionary. What data to send with analytics event depends on your game project.

Example

Dictionary<string, object> eventData = new Dictionary<string, object> ();
eventData.Add ("custom_string_data", "string_data");
eventData.Add ("custom_int_data", 10101);

Gravitum.Analytics.SendEvent ("EventName", eventData);

SendMonetaryEvent

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

Gravitum.Analytics.SendMonetaryEvent("coins", 0.99f, "USD");

Clone this wiki locally