PlaySuper LogoPlaySuper
Unity SDK

Complete Example & Reference

Full integration script, offline support, user properties, troubleshooting, and links to related guides

Complete Example & Reference

This page brings together everything from the previous guides into a single integration script, plus additional features like offline support, user properties, and troubleshooting.

Full integration script

This MonoBehaviour shows the complete lifecycle — initialize, create player, login, distribute coins, and open the store:

using UnityEngine;
using PlaySuperUnity;
using System.Collections.Generic;
using System.Threading.Tasks;

public class PlaySuperManager : MonoBehaviour
{
    private string playerUuid = "unique-player-id-123";

    void Awake()
    {
        PlaySuperUnitySDK.Initialize("YOUR_API_KEY");
    }

    async void Start()
    {
        await CreatePlayer();
        await LoginPlayer();
    }

    async Task CreatePlayer()
    {
        var response = await PlaySuperUnitySDK.Instance.CreatePlayerWithUuid(playerUuid);
        if (response?.data != null)
        {
            Debug.Log($"Player created: {response.data.playerId}");
        }
    }

    async Task LoginPlayer()
    {
        var response = await PlaySuperUnitySDK.Instance.LoginFederatedByStudio(playerUuid);
        if (response != null)
        {
            Debug.Log("Logged in successfully!");
        }
    }

    public void OnPlayerProfileLoaded(Player player)
    {
        PlaySuperUnitySDK.SetUserProperties(new Dictionary<string, object>
        {
            { "phone", player.phone },
            { "country", player.country }
        });
    }

    public async void OnPlayerEarnedCoins(int amount)
    {
        await PlaySuperUnitySDK.Instance.DistributeCoins("YOUR_COIN_ID", amount);
    }

    public void OnOpenStoreButtonClicked()
    {
        PlaySuperUnitySDK.Instance.OpenStore();
    }
}

Offline support

The SDK automatically queues coin distributions that fail due to network issues, missing auth tokens, or server errors. Queued transactions sync as soon as the player logs in and connectivity is restored — no additional code is needed.

If you want to show the player an offline indicator:

private bool IsOnline()
{
    return Application.internetReachability != NetworkReachability.NotReachable;
}

public async void DistributeCoinsWithFeedback(string coinId, int amount)
{
    if (!IsOnline())
    {
        Debug.Log("You're offline. Coins will sync when connected.");
    }

    await PlaySuperUnitySDK.Instance.DistributeCoins(coinId, amount);
}

User properties

User properties are persistent key-value pairs that the SDK attaches to every analytics event. They are useful for segmentation, A/B testing, and cohort analysis.

Setting properties

Properties are merged with any existing values — you do not need to pass the full set each time:

PlaySuperUnitySDK.SetUserProperties(new Dictionary<string, object>
{
    { "phone", "1234567890" },
    { "country", "IN" },
    { "ab_test_group", "variant_b" }
});

Supported types: string, int, long, float, double, bool.

Properties persist in Unity's PlayerPrefs across app restarts. Only call SetUserProperties when values change.

Reading and clearing properties

// Read current properties
var props = PlaySuperUnitySDK.GetUserProperties();

// Clear all properties (e.g. on logout)
PlaySuperUnitySDK.ClearUserProperties();

How properties appear in events

Every property is automatically prefixed with user_ in event payloads:

{
  "event_name": "ps_sdk.store_opened",
  "properties": {
    "$device_id": "abc-123-def-456",
    "$user_id": "player-uuid",
    "user_phone": "1234567890",
    "user_country": "IN"
  }
}

Best practices

  1. Set early — call SetUserProperties as soon as player data is available (after login or profile load)
  2. Update incrementally — only pass changed values; existing ones are preserved
  3. Use snake_case names — e.g. phone_number, ab_test_group
  4. Keep values primitive — avoid nested objects or arrays

Troubleshooting

ProblemSolution
API key mismatchMake sure the key in your code matches the one in the console
Wrong environmentPass isDev: true when initializing the SDK for the dev environment
Android build failsVerify that gradle templates are configured as described in Installation
Coins not syncingCheck network connectivity; the SDK syncs automatically when back online
GPM WebView missingConfirm GPM WebView is installed via Tools > GPM > Manager
GuideDescription
Console SetupSet up your account, game, coins, and API key
API ReferenceREST API documentation for direct API usage
Touchpoints APIFull REST API reference for touchpoints
WebhooksServer-side notifications for coin transactions
Gift Card APIPurchase and distribute gift card vouchers