Unity SDK 1.x
v1.x is in maintenance mode: no new features. Only critical bug fixes, security patches, and carefully reviewed non-breaking stability/performance fixes are allowed. All new feature work goes into v2.x.
Overview
The Metica Unity SDK offers a straightforward interface for interacting with the Metica backend API from your Unity game directly. The SDK provides simplified methods to fetch offers and SmartConfigs (abbreviated as configs), and to log user actions within your app or game as events. The Metica Unity SDK takes care of networking nuance, caching and much more so you don't have to.

Terminology
Application Your application or game that uses the Metica services.
User A user or player of the application. Player and user are used interchangeably.
Event An
eventrefers to a user's action within the context of the application. For example, clicking a button, logging in, clicking an ad, etc. The properties (or attributes) associated with these events vary based on the type of the event; e.g., the propertytotalAmountmust be set when logging an in-app offerpurchaseevent.User Properties Sometimes (and formerly) called User Attributes, user properties consist of general information about the user that best characterises them in your application. For example you could define your user properties to include game progression, demographics, user preferences, player's level, etc.
What you need
To use the Metica Unity SDK you need:
An
API key, obtainable in the Metica platformAn
appId, obtainable in the Metica platform.
Installation
In Unity, open the Package Manager (Window > Package Manager) and click on the '+' button in the top left corner. Select "Add package from git URL..." and enter the following:
https://github.com/meticalabs/metica-unity-sdk.git
How to use the Metica SDK
Access to the SDK functionalities is obtained through an IMeticaSdk interface, an instance of which (its implementation) can be easily obtained with:
You can now use the _sdk to access all method calls, keeping in mind that most of them are asynchronous. Example:
Setup
In Unity's Hierarchy View, right click (on an empty area) and select
Metica > Add SDK. This will add a prefab with the MeticaUnitySdk component attached (if not already in scene). Alternatively you can manually drag and drop the prefab fromPackages/Metica Unity Sdk/Runtime/Unity/Prefabs/.Select the prefab and click the
Create Configurationbutton to create and save it in the folder you select.*Select the configuration file and fill the fields (see SDK Configuration)
If needed, add the file to the MeticaSdk prefab. When you use the Create Configuration button the configuration should be automatically linked.
*: Alternatively, create a configuration asset by right-clicking a folder in the Project View and selecting Create > Metica > SDK > New SDK Configuration. This can also be found in the main menu under Assets > Create > Metica but it will create the asset in the Assets' root.
SDK Configuration
The SDK configuration exposes the following parameters:
apiKey
Your API key
appId
The application identifier accessible from Metica's dashboard.
initialUserId
A string that identifies a user. This can change during the lifetime of your app/game so, for example and depending on your needs, this could be a temporary id like "guest" that later becomes a specific userId, or it can be the current user's id if it's already identified.
Log Level
The level of the SDK's logs. Do not confuse this with the meaning Log in the context of event logging. The valid values are provided by the enumeration Metica.SDK.LogLevel and determine the verbosity of the logs with Info being the most verbose and Debug being the least verbose. Offsuppresses all logging.
SmartConfigs
The GetConfig method can be used to retrieve the SmartConfigs.
Because the result is specific to each application, the SDK represents it in a generic manner, through an Dictionary<string, object> instance.
Each entry in the dictionary represents a configuration key and its value. The latter is expected to be valid json.
The operation can be passed a dictionary of user properties and the device details, as a DeviceInfo instance (see Device Info), in order to personalise the returned configuration. The personalisation happens on the server side, based on the configured variations and experimentation setup.
Signature
Example
If the configKeys argument is null or empty, then all the configured keys will be returned.
Note that the server side response for this call is going to be cached according to the cache control directives returned by the server.
Device Info
The DeviceInfo stores information regarding the host device, and it can differ across different devices of the same user.
Note that leaving this variable to null is perfectly fine as it will trigger a device detector that is internal to the SDK
An overview of the role of each DeviceInfo property:
store
string
Identifies the app store related to the in-game offers. Possible values:
- GooglePlayStore, the Google store
- AppStore, the Apple store
GooglePlayStore
locale
string
Locale expressed as a combination of language (ISO 639) and country (ISO 3166) JDK 8 standard reference.
en-US
Events Ingestion
This section explains how to ingest events from the game into Metica. Here is a list of methods that deliver these events to Metica, and following their signatures should be sufficient for an SDK developer. Additional details about them can also be found here.
Offer Lifecycle Events
Logs offer related events like offer display, offer purchase, and offer interaction.
All these events have two signatures: one with and one without productId. If the offer linked to the event was generated by Metica, the method without ProductId should be used. Conversely, if the offer is a game offer created internally within the game, the method with ProductId must be used, passing the relevant productId (any internal string representing it) in the method.
Examples:
Full State Update
LogFullStateUpdate sends a complete snapshot of the user's state to the server, replacing any previously stored data.
Please note that this method fully resets the user's state on the server and expects all relevant state information to be included in the request.
Any user attributes that are currently stored in the server with the given userId but are not sent with this update, will be erased.
Partial State Update
LogPartialStateUpdate sends a partial update of the user's state to the server,
modifying or adding only the provided fields while preserving those that are currently stored on the server.
This method cannot erase existing fields (like LogFullStateUpdate does); it can only overwrite values or introduce new ones.
Custom Event Logging
LogCustomEvent logs custom application events. The only required field in this dictionary is eventType , which Metica uses to classify the different types of events your application sends.
Custom Payloads
All events, except fullStateUpdate, partialStateUpdate and CustomEvent, support a custom payload that can include any information.
It's passed as a Dictionary<string, object> to the logging methods. To avoid confusion with other fields, it is recommended to pass the parameter by name, i.g. LogInstall(customPayload: playerExtraParams) rather than just LogInstall(playerExtraParams).
Example
Event Dispatch (Flushing)
When you log an event (both with static calling or using async), it isn't guaranteed to be sent immediately as events are sent in bulks.
If you need to make sure events are immediately sent to the ingestion endpoint, you can use the RequestDispatchEvents call but don't overuse it as the default behaviour helps aggregating events for lower network load.
Ads Integration
This section explains how to integrate Metica's interstitial ads into your Unity project. Metica's streamlined API simplifies ad integration by automatically handling ad unit IDs and optimizing ad selection.
This guide assumes that the AppLovin SDK has already been configured. Otherwise please follow this guide. MeticaAds requires AppLovin SDK version ≥ 13.

Initialization
The IsMeticaAdsEnabled flag is a boolean variable that determines whether a specific user will receive ads optimized by Metica's AI or will be part of a holdout group receiving ads directly through the standard AppLovin MAX SDK. This flag is set during the SDK initialization and is used to A/B test the revenue performance of Metica's ad optimization against the baseline performance of the MAX SDK.
Important: MeticaAds.InitializeAsync() must be called BEFORE initializing the AppLovin MAX SDK to ensure proper integration.
Holdout tracking
When making use of user holdout functionality it is important to implement following callbacks so comparison and analytics are possible. See the sample implementations further below for interstitial and rewarded ads.
Important: Only log ad events for types of interstitial/rewarded, others (banners) are not supported by Metica.
Interstitial ads
Interstitial ads are full-screen or full-page ads that temporarily cover an app’s interface. They’re typically shown at natural pauses or transition points, such as after completing a level in a game or when navigating between major views.
The following sections show you how to load and then show an interstitial ad.
Loading an Interstitial Ad
The following code shows you how to attach listeners and load the first interstitial ad.
Showing an Interstitial Ad
To show an interstitial ad, call ShowInterstitial():
Rewarded Ads
Rewarded ads are video ads that users can choose to watch in exchange for in-app rewards.
Loading a Rewarded Ad
The InitializeRewardedAds method attaches listeners for both Metica and MAX SDK rewarded ad callbacks and then loads the first rewarded ad.
Showing a Rewarded Ad
To show an interstitial ad, call ShowRewarded():
Metica SDK vs AppLovin Interstitial API
API Calls
Metica's API in contrast to AppLovin does not require an adUnitId to be passed. The reason is that Metica's AI technology automatically selects and manages the optimal ad unit IDs behind the scenes, eliminating the need for developers to manually specify these IDs in each function call and simplifying integration.
Metica Ads API
Max SDK API
Callbacks
Metica Ad Callbacks
Max Ad Callback
Code Samples
The Metica Unity SDK package includes examples that can be easily imported into your Assets by selecting the package in the Package Manager and clicking the Import button next to one of the examples.
Currently available examples:
MeticaExample01 shows how to use the SDK via
MeticaAPI(deprecated). This uses the static calls code style.MeticaExample02 shows how to use the SDK by retrieving the instance and using asynchronous code style.
Privacy Manifest
For iOS, iPadOS, tvOS and watchOS apps, we provide a privacy manifest at Assets/Plugins/PrivacyInfo.xcprivacy that describes the data collected by the Metica SDK.
Last updated
Was this helpful?

