Skip to content

Superfine SDK Unity

Introduction

The Superfine SDK for Unity provides a comprehensive solution for integrating revenue tracking and reporting into your Unity applications. This guide will walk you through the setup and configuration process.

Download

Setup

  1. Import Unity Package
    Download the SuperfineSDK zip file, unzip it, and copy the extracted files into your Packages folder.

    ⚠️ Important: The SDK requires the External Dependency Manager to function properly. You can remove or modify these dependencies to match your application's version requirements. Download the External Dependency Manager from here.

  2. Get App Information
    Go to the project section on the Superfine.org dashboard, select your project, and copy the Project ID and Project Secret.

  3. Update Superfine Settings
    From the menu, select Superfine/Edit Settings to update your Project ID and Project Secret.

  4. Initialize SDK
    Add the following code to initialize the SDK (this can be placed in the Awake function of a new component).

void Awake()
{
    SuperfineSDKSettings settings = SuperfineSDKSettings.LoadFromResources().Clone();
    settings.autoStart = false;

    // Initialize SuperfineSDK.
    SuperfineSDK.Initialize(settings, OnInitialized);

    // Note: Call SuperfineSDK.Start(); after MMP and Mediation SDK initialization.
    SuperfineSDK.Start();
}

// Callback after Superfine initialization is complete
void OnInitialized()
{
}
If autoStart is set to false, you can manually start the SDK as follows:

settings.autoStart = false;
SuperfineSDK.Initialize(settings, OnInitialized);

// Start SuperfineSDK when needed.
SuperfineSDK.Start();
To stop the SDK, call:

SuperfineSDK.Stop();

⚠️ Important: You should call Unity.SuperfineSDK.Initialize(); after MMP and Mediation SDK initialization.

We support MMPs such as Appsflyer, Adjust, Singular, and Tenjin. Here is how to do it:

1. Send Linking Event

Setting the link event using Customer User ID: Make sure you call this function only once after the Superfine SDK is successfully initialized, and MMP is successfully initialized.

Example:

void OnInitialized()
{
    string sfid = Superfine.Unity.SuperfineSDK.GetUserId();
    int sendLinkEventCount = PlayerPrefs.GetInt("LinkEventWithMMP", 0);

    if (!string.IsNullOrEmpty(sfid) && sendLinkEventCount == 0)
    {
        // For Appsflyer
        Dictionary<string, string> appsflyerData = new Dictionary<string, string>();
        appsflyerData.Add("sf_link_uid", sfid);
        AppsFlyerSDK.AppsFlyer.setCustomerUserId(sfid);
        AppsFlyerSDK.AppsFlyer.sendEvent("sf_link_uid", appsflyerData);

        // For Singular
        Dictionary<string, object> singularData = new Dictionary<string, object>
        {
            { "sf_link_uid", sfid }
        };
        SingularSDK.SetCustomUserId(sfid);
        SingularSDK.Event(singularData, "sf_link_uid");

        // For Tenjin
        BaseTenjin instance = Tenjin.getInstance(TENJINKEY);
        instance.SetCustomerUserId(sfid);
        instance.SendEvent("sf_link_uid");

        // For Adjust, set the sf_link_uid in the Adjust server and get the token
        Adjust.addSessionCallbackParameter("userId", sfid);
        AdjustEvent adjustEvent = new AdjustEvent(SF_LINK_UID_TOKEN);
        Adjust.trackEvent(adjustEvent);

        // Ensure this is sent only once
        PlayerPrefs.SetInt("LinkEventWithMMP", 1);
    }
}

2. Set Callback Events

Appsflyer

Set callback event
Go to Appsflyer > Active Partner > Pick the app
Map the sf_link_uid event for All media sources, including Values & Revenue.
Appsflyer Callback Event

Adjust

Set sf_link_uid event
Go to App View > All Apps > Pick your app > Event > Add Event
Add the sf_link_uid event.
Adjust Linking Event

Then, copy the Token.
Adjust Linking Event

Use this Token in the code:

Example:

Adjust.addSessionCallbackParameter("userId", sfid);
AdjustEvent adjustEvent = new AdjustEvent(Token);
Adjust.trackEvent(adjustEvent);

Singular

No extra steps needed

Tenjin

Set callback event
Go to Tenjin > Configure > Apps > Callbacks, and search for Superfine in the Channels and Partners section.

Search for Superfine Channel

Add the event sf_link_uid to the callback, ensuring the user filter is configured for All Users.

Superfine Callbacks

Ad Revenue Auto-Tracking

These events are used to track ad revenue from your app. We support automatic ad revenue tracking.
Our SDK provides ad revenue reporting support through add-on classes. You can receive detailed reports by implementing the appropriate class based on your chosen mediation platform and registering for events.
Currently, we support the following mediation platforms:

  • MAX Mediation (AppLovin)
  • Appodeal (both UMP and Manual versions)
  • IronSource Mediation
  • Google AdMob Mediation

1. MAX Mediation (AppLovin)

  • Integration: Add the AppLovin Helper add-on to your project by navigating to Superfine > Add-ons > AppLovin.
  • Event Registration: Start logging revenue and impressions by calling SuperfineSDKApplovin.RegisterPaidEvent().
    To stop logging, call SuperfineSDKApplovin.UnregisterPaidEvent() or do so when your manager class is destroyed.

2. Appodeal Mediation

  • Integration: Add the Appodeal Helper add-on to your project by navigating to:
  • Superfine > Add-ons > Appodeal (UMP) (for the UMP version).
  • Superfine > Add-ons > Appodeal (Manual) (for the Manual version).
  • Event Registration: Start logging revenue and impressions by calling SuperfineSDKAppodeal.RegisterPaidEvent().
    To stop logging, call SuperfineSDKAppodeal.UnregisterPaidEvent() or do so when your manager class is destroyed.

3. IronSource Mediation

  • Integration: Add the IronSource Helper add-on to your project by navigating to Superfine > Add-ons > IronSource.
  • Event Registration: Start logging revenue and impressions by calling SuperfineSDKIronSource.RegisterPaidEvent().
    To stop logging, call SuperfineSDKIronSource.UnregisterPaidEvent() when done or when your manager class is removed.

4. Google AdMob Mediation

  • Integration: Add the AdMob Helper add-on to your project by navigating to Superfine > Add-ons > AdMob.
  • Event Registration: You must register events for all ad placements:

  • Banner Ads:

    SuperfineSDKAdMob.RegisterBannerViewPaidEvent(bannerView, adUnitId);
    SuperfineSDKAdMob.UnregisterBannerViewPaidEvent(bannerView, adUnitId);
    

  • Interstitial Ads:

    SuperfineSDKAdMob.RegisterInterstitialAdPaidEvent(interstitialAd, adUnitId);
    SuperfineSDKAdMob.UnregisterInterstitialAdPaidEvent(interstitialAd, adUnitId);
    

  • Rewarded Video Ads:

    SuperfineSDKAdMob.RegisterRewardedAdPaidEvent(rewardedAd, adUnitId);
    SuperfineSDKAdMob.UnregisterRewardedAdPaidEvent(rewardedAd, adUnitId);
    

  • Rewarded Interstitial Ads:

    SuperfineSDKAdMob.RegisterRewardedInterstitialAdPaidEvent(rewardedInterstitialAd, adUnitId);
    SuperfineSDKAdMob.UnregisterRewardedInterstitialAdPaidEvent(rewardedInterstitialAd, adUnitId);
    

  • App Open Ads:

    SuperfineSDKAdMob.RegisterAppOpenAdPaidEvent(appOpenAd, adUnitId);
    SuperfineSDKAdMob.UnregisterAppOpenAdPaidEvent(appOpenAd, adUnitId);
    

  • Ad Revenue Tracking:

    SuperfineSDK.LogAdRevenue();
    

IAP Revenue Recognition

The SuperfineSDKUnityIAP class simplifies the process of sending In-App Purchase (IAP) receipt events.
Ensure you are using the Unity IAP package for this functionality.

  • Integration: Add the Unity IAP Helper add-ons to your project by navigating to Superfine > Add-ons > UnityIAP.
  • Sending Events: Call Superfine.Unity.SuperfineSDKUnityIAP.LogIAPReceipt(Product p) when a purchase is successfully completed using the Unity IAP plugin.

Example:

// Callback function for successful purchase
private void ProcessProductFinal(Product p, string receipt = null)
    {
        // Implement your logic here

        // Log the first purchase event
        Superfine.Unity.SuperfineSDK.LogIAPResult(p.definition.id, (double)(p.metadata.localizedPrice), 1, p.metadata.isoCurrencyCode, true);

        // Use Unity IAP helper to send the receipt event for LTV calculation of renewing purchases
        Superfine.Unity.SuperfineSDKUnityIAP.LogIAPReceipt(p);
    }

Wallet Events - For On-Chain Revenue Recognition

  1. LogWalletLink

    void LogWalletLink(const String wallet, const String type = "ethereum");

Description: Call this method when you want to link the user's wallet address.

Parameters
wallet String: Cannot be null. The wallet address you want to log the linking event for
type String: Default is "ethereum". The chain of the wallet address

Example:

//Link wallet address "ronin:50460c4cd74094cd591455cad457e99c4ab8be0" in the "ronin" chain
SuperfineSDK.LogWalletLink("ronin:50460c4cd74094cd591455cad457e99c4ab8be0", "ronin");
2. LogWalletUnlink

void LogWalletUnlink(const String wallet, const String type = "ethereum");

Description: Call this method when you want to unlink the user's wallet address.

Parameters
wallet String: Can't be null. The wallet address you want to log the unlinking event for.
type String: Default is "ethereum". The chain of the wallet address.

Example:

//Unlink wallet address "ronin:50460c4cd74094cd591455cad457e99c4ab8be0" in "ronin" chain
SuperfineSDK.LogWalletUnlink("ronin:50460c4cd74094cd591455cad457e99c4ab8be0", "ronin");

Additional Revenue Sources

You can log addional revenue by using

void LogIAPResult(string pack, float price, int amount, string currency, bool isSuccess);

Description: Call this method when the user attempts to buy an IAP item.

Parameters
pack String: Can't be null. The unique identifier of the purchased item or pack.
price Float: Can't be null. The price of the item or pack.
amount Integer: Can't be null. The quantity of the purchased item or pack.
currency String: The currency code (e.g., "USD", "EUR") corresponding to the revenue.
isSuccess Boolean: Can't be null. True if the purchase was successful. False if the purchase failed.

Example:

//Log when the user completed to purchase a package with ID "test_pack" for 0.99 USD, getting 150 units.
SuperfineSDK.LogIAPResult("test_pack", 0.99, 150, "USD", true);