Unity SDK

C#

Full-featured Appflow integration for Unity games on iOS and Android.

The Unity SDK provides a C# API for all Appflow v2 features, purpose-built for game developers. It uses Unity's native APIs (UnityWebRequest, PlayerPrefs, MonoBehaviour lifecycle) and integrates with Unity IAP for in-app purchases. Distributed as a Unity Package Manager (UPM) package for easy installation via git URL.

Installation

Add via Unity Package Manager using the git URL:

Unity → Window → Package Manager → + → Add package from git URL
https://github.com/appflow-ai/appflow-unity-sdk.git

Or add directly to your manifest.json:

Packages/manifest.json
{
  "dependencies": {
    "ai.appflow.sdk": "https://github.com/appflow-ai/appflow-unity-sdk.git"
  }
}

Quick Start

GameManager.cs
using AppflowSDK;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    void Start()
    {
        // Initialize Appflow (creates DontDestroyOnLoad singleton)
        Appflow.Configure("your_api_key", new AppflowOptions
        {
            EnableAutoTracking = true,
            LogLevel = LogLevel.Info,
        });

        // Identify users
        Appflow.Instance.SetUserId("player_123");

        // Track events
        Appflow.Instance.Track("level_completed", new Dictionary<string, object>
        {
            { "level", 5 },
            { "score", 12500 },
            { "time_seconds", 45.2f },
        });
    }
}

In-App Purchases

StoreManager.cs
using AppflowSDK;
using UnityEngine;

public class StoreManager : MonoBehaviour
{
    public async void PurchasePremium()
    {
        // Track purchase intent
        Appflow.Instance.Track("purchase_start", new Dictionary<string, object>
        {
            { "product_id", "premium_monthly" },
        });

        // Use Unity IAP or platform-specific APIs for actual purchase
        // Then report the result to Appflow
        Appflow.Instance.Track("purchase_complete", new Dictionary<string, object>
        {
            { "product_id", "premium_monthly" },
            { "revenue", 9.99 },
            { "currency", "USD" },
        });
    }
}

Remote Config

GameConfig.cs
using AppflowSDK;

public class GameConfig
{
    // Get typed config values with defaults
    public static int MaxLives => (int)Appflow.Instance.GetNumber("max_lives", 3f);
    public static bool AdsEnabled => Appflow.Instance.GetBool("ads_enabled", true);
    public static string MotdMessage => Appflow.Instance.GetString("motd", "Welcome!");

    // Use in game logic
    public static bool ShouldShowInterstitial(int level)
    {
        int adFrequency = (int)Appflow.Instance.GetNumber("ad_frequency", 3f);
        return AdsEnabled && level % adFrequency == 0;
    }
}

Scene Tracking

auto-tracking
// Auto-tracked events (when enableAutoTracking = true):
// - app_open         → Application start
// - app_background   → OnApplicationPause(true)
// - app_foreground   → OnApplicationPause(false)
// - session_start    → New session after 30min gap
// - session_end      → App quit or long background
// - scene_loaded     → SceneManager.sceneLoaded

// All events include device info:
// platform, os_version, device_model, app_version, locale, timezone

Key Features

Zero Dependencies
Uses only Unity built-in APIs (UnityWebRequest, PlayerPrefs)
Offline Buffering
Events persisted to disk, synced when connection available
Auto-Tracking
Lifecycle, sessions, and scene loads tracked automatically
Remote Config
Server-driven feature flags with typed getters
UPM Distribution
Install via Unity Package Manager git URL
iOS + Android
Full support for both mobile platforms from Unity

Requirements

Unity 2021.3+, iOS 16+ (build target), Android API 24+ (build target). Optional: Unity IAP package for in-app purchase integration.

Related Guides