Unity 4.+ migration guide

Upgrading version

Increase the dependency version in your Packages/manifest.json file to upgrade your Qonversion SDK to the latest

"com.qonversion.unity": "https://github.com/qonversion/unity-sdk.git#4.0.0"

Initialization

Qonversion Unity SDK 4 contains significant changes in how the library is initialized. We are moving from a static class approach to an instance-based one. Before, you initialized Qonversion using the Launch call:

Qonversion.Launch("projectKey", true);

Now, instead, you should create a QonversionConfig object using QonversionConfigBuilder and provide it to the initialization method as follows:

QonversionConfig config = new QonversionConfigBuilder(
        "projectKey",
        LaunchMode.SubscriptionManagement
    ).Build();
Qonversion.Initialize(config);

Note that instead of providing the observeMode flag to the Launch call, you now should provide a concrete value from the LaunchMode enum depending on which mode you use Qonversion. Also, we've renamed our modes to make them more transparent for users:

  • "Observe" mode becomes "Analytics" mode,
  • "Infrastructure" mode becomes "Subscription Management" mode.

After the initialization, you can access the Qonversion instance whenever you want as follows:

Qonversion.GetSharedInstance();

So you should replace all your Qonversion calls with the construction above.

Also, if you were using Qonversion.SetDebugMode() for testing purposes, you should now call the SetEnvironment(Environment.Sandbox) method of the QonversionConfigBuilder.

Entitlements

We are on the way to renaming permissions to entitlements as this naming suits more what it is used for. So, the following objects and methods were renamed in this release:

Version <4Version 4+
PermissionEntitlement
QProductRenewStateQEntitlementRenewState
QPermissionSourceQEntitlementSource
PermissionsCacheLifetimeEntitlementsCacheLifetime
CheckPermissionsCheckEntitlements
OnPermissionsReceivedOnEntitlementsReceived
OnUpdatedPurchasesReceivedOnUpdatedEntitlementsReceived
UpdatedPurchasesReceivedUpdatedEntitlementsReceived

The Entitlement class contains the same information as the Permission with a renaming of the PermissionID field - now it's named simply Id.

There is no SetPermissionsCacheLifetime method in Qonversion. You should provide EntitlementsCacheLifetime to QonversionConfigBuilder during the initialization using the SetEntitlementsCacheLifetime method.

QonversionConfig config = new QonversionConfigBuilder(
        "projectKey",
        LaunchMode.SubscriptionManagement
    )
    .SetEntitlementsCacheLifetime(EntitlementsCacheLifetime.Year)
    .Build();
Qonversion.Initialize(config);

Automation changes

We've also changed the way the Automations is used. As in Qonversion, you should use Automations via the shared instance. On the first access, it will be initialized and returned. Then the initialized instance will be used.

📘

You should access the shared instance of Automations strictly after you initialize Qonversion, else an exception will be thrown.

QonversionConfig config = new QonversionConfigBuilder(
        "projectKey",
        LaunchMode.SubscriptionManagement
    ).Build();
Qonversion.Initialize(config);
Automations.GetSharedInstance().SetDelegate(...);

Also, the methods for working with push notifications were moved from Qonversion to Automations, so if you were using the following methods:

  • SetNotificationsToken,
  • HandleNotification,
  • GetNotificationCustomPayload,
    make sure to make calls from the Automations instance instead of the Qonversion one.

Rest of the changes

Along with the changes described above, there are several technical improvements and other changes in the new major release:

  • all the internal classes were moved to the Internal package, and DTO classes were moved to the Dto package to make the library file structure more readable;
  • the deprecated methods SetUserID and Purchase methods with OnPermissionsReceived callbacks were removed. SetUserID should be replaced with the setProperty call with the UserProperty.CustomUserId parameter.
  • added the new method UserInfo, which returns the information about the current Qonversion user. Now it contains internal Qonversion and identity identifiers. The user info may be extended in future releases;
  • added new enum values - QOfferingTag.Unknown and QTrialDuration.Unknown, which are used when parsing fails;
  • the EntitlementsCacheLifetime enum values were rewritten in UpperCamelCase to meet the rest enums style;
  • added new values AppleSearchAds and AppleAdServices to the AttributionProvider enum,
  • the following methods, classes, and values renamings took place:
Old nameNew name
AddAttributionDataAttribution
CheckTrialIntroEligibilityForProductIdsCheckTrialIntroEligibility
SetAdvertisingIDCollectAdvertisingId
SetAppleSearchAdsAttributionEnabledCollectAppleSearchAdsAttribution
AttributionSourceAttributionProvider