SaltyFatGuy
SaltyFatGuy

Reputation: 3

Unity uploading ingame stats to a website

I want to make a Unity game that sends ingame stats to a website, Like how many times a player has shot, how many kills the play has. ect.

my question is is this even possible using Unity? if yes what tools do I need?

Upvotes: 0

Views: 95

Answers (1)

Tiny Brain
Tiny Brain

Reputation: 640

  1. If you already have a backend for your game analytics, then you can just call their API endpoints using UnityWebRequest.
using UnityEngine.Networking;
...
IEnumerator LogEvent(kills, shots) {
    WWWForm form = new WWWForm();
    form.AddField("kills", kills);
    form.AddField("shots", shots);

    using (UnityWebRequest www = UnityWebRequest.Post("http://www.my-server.com/myform", form))
    {
        yield return www.SendWebRequest();
        if (www.isNetworkError || www.isHttpError) {
            Debug.Log(www.error);
        } else {
            Debug.Log("Form upload complete!");
        }
    }
}
...
public void GameOver() {
    ...
    StartCoroutine(LogEvent(10, 100));
}
  1. You can use some Analytics SDKs for that such as Firebase Analytics, Google Analytics, AppsFlyer, and so on.

https://firebase.google.com/docs/analytics/unity/start https://developers.google.com/analytics/devguides/collection/unity/v4/devguide

In my experience, Firebase is the best one as it supports other tools like Storage, Authentication, ...

Upvotes: 1

Related Questions