Unity Integration
Here you will find the guide to implement and use the Attrackt Unity Adapter
Before You Beginβ
Make sure you meet the following requirements
Requirementsβ
- The integration requires Attrackt account, so create account if you havenβt already done so, and create a new iOS app in your account. Refer to the Add Your Apps and Placements section of our Using the Publisher Dashboard article to learn how to set up placements in the Attrackt dashboard.
- Make sure your application is an iOS 12 and higher. We do not recommend integrating the SDK for iOS versions lower than 12.0.
info
Attrackt currently only support iOS applications so Android apps exported from unity wont have Attrackt inside them.
Step 1. Download the Attrackt Unity Pluginβ
Attrackt Unity v1.0.0β
Step 2. Attrackt Native Framework Implementationβ
Attrackt Unity plugin is already includes a dependency to the iOS native Framework and requires CocoaPods. After a successful export of your iOS project from Unity it sohuld result in the Pod statement within your project's Podfile.
You can validate it by opening the Podfile and make sure you see there the line:
pod 'Attrackt'
For further example of how the pod implementation works you can visit our docs here
Mediationβ
In order for the advertisers mediation to work make sure you implement the desired advertisers in your Podfile. Refer to our mediation docs here
Step 3. Activating the plugin in Unityβ
After downloading the AttracktUnity.unitypackage file, in order to add it to your project you can:
- Double click it
- In your Unity editor go to Assets->Import Package->Custom Package. Navigate to the AttracktUnity.unitypackage file location and select it.
after doing one of the steps above correctly you should see this window:

Step 4. Add the game Objectβ
On your Initial scene in the project, the first one that shows after loading, Select it and right click to see the options.
You should have under GameObject >
a new Row called Attrackt

Click on the Attrackt
option and a new GameObject should be added to your scene.
danger
After adding it successfuly it sohuld look like that, with a new object and the object inspector open

Step 5. Setting Attrackt upβ
Attrackt GameObject accept few parameters.
- debug: Boolean True, False - Will print debug info on screen and in log.
- apiKey: String The APIKey of the application you are running and retrieved from the dashboard
- placements: [String] Accepts array of placements to initialise, Attrackt placements from the dashboard.
info
After setting all data properly, that's it. Attrackt will initialise automatically and there is no need to further init or call it manually from the iOS or Unity code.
Step 6. Presenting Advertisementβ
After a successful setup, You should go to your Unity app code and there will be a Singleton class available called
AttracktManager
The class exposes function that will allow you to present an ad from the requested placment
public static void ShowAd(string placement, UnityAction<AttracktInterstitialFinishedState> interstitialClosed = null)
The function ShowAd
accepts 2 parameters:
- placementId: String The name of the placement from the dashboared that you want to present and has demand connected
- interstitialClosed: [Callback] (optional) Accepts a callback function that calls when the advertisement is closed/dissappear.
e.g
AttracktManager.ShowAd("when_char_dead", state =>
{
AttracktScreenWriter.Write("ad has completed with state " + state);
});
The callback returns a variable named state
which indicates on the status of the ad view and has values of:
public enum AttracktInterstitialFinishedState {
Error = 1,
Skipped = 2,
Completed = 3,
}
This will help you to know what the user has done and even allow you to reward him accordingly
In App Purchase Adsβ
Attrackt Ads allow the user to purchase In App products from within the ad. In order to make it work with the native layer one of two things has to be done.
- Connect manully to the purchase event and call from Unity to the in app purchase layer of the native device.
- Attrackt by default will look for the default implementation of IAP Listeners from the official Unity IAP package,
IStoreListener
. so if it has already implemented, nothing else has to be done. the purchase should work out of the box and will call to the already predefiend success purchase callback and will reward the user with his goods.
Purchasing Manuallyβ
Attrackt Unity plugin allow you to connect to the purchasing events which are methods of the static class
AtracktEvents
The available callbacks are:
AttracktEvents.onIapPurchaseFinishedWithSuccessEvent += (sku) =>
{
AttracktScreenWriter.Write("onIapPurchaseFinishedWithSuccessEvent: " + sku);
};
AttracktEvents.onIapPurchaseFinishedWithFailureEvent += (sku, error) =>
{
AttracktScreenWriter.Write("onIapPurchaseFinishedWithFailureEvent: " + sku);
};
AttracktEvents.onIapAlreadyPurchasedEvent += (sku) =>
{
AttracktScreenWriter.Write("onIapAlreadyPurchasedEvent: " + sku);
};
Use this callbacks to be notified on user in app action related to attrackt and react accordingly.