Unity

SDK Version: 3.10.1

This document describes the basic procedure for integrating StartApp In-App Ads into your Unity applications for iOS. 
After this simple integration process, StartApp In-App Ads enables you to reap the benefits of StartApp's In-App monetization products, which maximize the revenue generated by your application. All this profit-making is achieved with minimal effort and minimal interference with your users’ experience.

NOTES:
  • To build your app with StartApp SDK you must have XCode 4.4.1+
  • The code samples in this document can be copy/pasted into your source code
  • When submitting your application to the App Store,do not forget to update your "IDFA Settings"
  • If you have any questions, contact us via support@startapp.com

Getting Started

Step 1, Adding the SDK package to your Unity project

In order to add StartApp SDK to your application please follow the following steps:

1. Unzip the SDK files to a temporary folder
2. Import StartAppiOSUnitySDK-x.x.x.unitypackage as a Custom Package (or drag and drop it to your "Assets" folder under the "Project" Window)

3. Import all the package's items by pressing "All" and then "Import" 

Step 2, Updating your StartApp data file

Update the StartAppDataiOS.txt_ (in the Assets/Resources folders) as follows:

1. Add your StartApp Account ID after developerId=
For example: developerId=103343523

2. Add your StartApp Application ID after applicationId=
For example: applicationId=204346543

You can find your Account and Application IDs in the developers’ portal.
After logging in, your account ID will be displayed at the top right-hand corner of the page: 

To find your application ID, click on the "Apps and Sites" tab on the left pane and choose the relevant ID from your app list:

Step 3, Provide Your App's Orientation

Call the unityOrientation() method in the Start() method of your script, and pass your app's orientation:

void Start () {
        #if UNITY_IOS
        StartAppWrapperiOS.unityOrientation(StartAppWrapperiOS.STAUnityOrientation.STAAutoRotation);
        #endif    
    }

Where unityOrientation() can get one of the following values:
 STAUnityOrientation.STAPortrait (portrait only app)
 STAUnityOrientation.STALandscape (landscape only app)
 STAUnityOrientation.STAAutoRotation (app supports auto-rotation)

Step 4, User Consent (GDPR)

StartApp requires you to pass user consent flag via the API as detailed herein below. The user consent flag indicates whether a user based in the EU has provided consent for ads personalization, collection and use of personal data. Based on this consent flag, StartApp will be able to use the data to target the most relevant ads to your users. If a user has not consented, we will not show personalized ads to this user.

IMPORTANT NOTES:
  • Collection of consent is only required in countries covered by GDPR (EU member states). Consent is not required for users that are based outside those countries.
  • We recommend you to pass the consent flag to StartApp right after initializing the SDK.
  • In case of any consent change during the lifetime of the user activity, you are required to re-submit the relevant consent flag to StartApp.
  • Older SDK versions (before 3.8.0): We'll continue to support them with showing ads. It’s important to know that in case you cannot update the SDK version and the user consent is false for GDPR users, do not initialize StartApp SDK for such users.

Use this method in case the user has consented:

StartAppWrapperiOS.setUserConsent(true, 
                                  "pas", 
                                  (long)(DateTime.UtcNow.Subtract(new DateTime (1970, 1, 1))).TotalMilliseconds);
}

Use this method in case the user has not consented:

StartAppWrapperiOS.setUserConsent(false, 
                                  "pas", 
                                  (long)(DateTime.UtcNow.Subtract(new DateTime (1970, 1, 1))).TotalMilliseconds);
}

NOTE: timestamp parameter should represent the specific time a consent was given by the user.

Interstitial Ads

You can choose to show an interstitial ad in several locations within your application. This could be upon entering (onCreate), between stages, while waiting for an action and more.

Add the following code to the appropriate place or places in which you would like to show the ad:

1. Load the ad

void Start () {
        #if UNITY_IOS
        StartAppWrapperiOS.loadAd();
        #endif    
    }

2. Show the ad

StartAppWrapperiOS.showAd();

You can show a specific type of interstitial ad, as well as getting callbacks events. For detailed instructions please refer to the Advanced Usage.

Splash Ad

A Splash Ad is a full-page ad that is displayed immediately after the application is launched. A Splash Ad first displays a full page splash screen that you define (as described below) followed by a full page ad.

StartApp SDK provides two modes for displaying Splash screens:

Adding the Splash Screen
Splash Screen Mode Description
User-Defined Mode (default) Using your application's default splash image, with a loading animation
Template Mode StartApp SDK provides a set of pre-defined templates in which you can place your own creatives, such as application name, logo and loading animation. for more details, please refer to the "Advanced Usage"


Simply call showSplashAd() in the Start() method of your script:

void Start () {
        #if UNITY_IOS
        StartAppWrapperiOS.showSplashAd();  // show splash ad
        #endif    
    }

Please note that you should attach the script to an object which is being allocated upon application's launch (for example, "Main Camera").

If you wish to customize or use a different splash screen, please refer to the Advanced Usage.

Return Ads

The Return Ad is a new ad unit which is displayed once the user returns to your application after a certain period of time. To minimize the intrusiveness, short time periods are ignored. For example, the Return Ad won't be displayed if the user leaves your application to take a short phone call before returning.

Return ads are enabled and activated by default. If you want to disable this feature, simply call disableReturnAd() in your Start() method:

void Start () {
        #if UNITY_IOS
        StartAppWrapperiOS.disableReturnAd();  // disable return ads
        #endif    
    }

Please note that you should attach the script to an object which is being allocated upon application's launch (for example, "Main Camera").

Banner Ads

To add a banner to your application add the following code to your Start() method:

void Start () {
        #if UNITY_IOS
        StartAppWrapperiOS.addBanner(StartAppWrapperiOS.BannerPosition.BOTTOM);
        #endif    
    }

Parameters

BannerPosition - position of the banner. Can receive one of the following: 
 StartAppWrapper.BannerPosition.BOTTOM 
 StartAppWrapper.BannerPosition.TOP

You can change the banner position and size, as well as getting callbacks events. For detailed instructions please refer to the Advanced Usage.

Rewarded Video Ads

Rewarded Ads are interstitial video ads that provide a reward to the user in exchange for watching an entire video ad. The reward might be in-app goods, virtual currency or any premium content provided by the application. Because users actually opt-in to watch a rewarded video and are granted with something valuable in return, Rewarded Ads are an effective and clean monetization solution for stronger user retention and keeping users engaged in your application for a longer amount of time.

In order to show rewarded video ad in your app, follow the following steps:

1. Pass the GameObject name to the loadRewardedVideoAd() method (for example, "Main Camera")

 void Start () {
           #if UNITY_IOS
           StartAppWrapperiOS.loadRewardedVideoAd("Main Camera");
           #endif  
     }

2. Call showAd() in the place you want the ad to be shown:

void didLoadAd () {
           StartAppWrapperiOS.showAd ();
     }

3. Then, you can implement the following method in order to get a callback when the user completes watching the video and is eligible for getting the reward:

void didCompleteVideo () {
           //give some reward to user
     }

Build Your Unity Project

The first time you build your unity project with StartApp SDK, make sure to use "Build and Run" (instead of "Build"). Once completed, Unity will create and load an XCode project. You will notice a few errors. That's ok. Please follow the following steps to include additional necessary frameworks, then re-build your project.

  1. Select your application project to bring up the project editor
  2. Select your application target to bring up the target editor
  3. Select the Build Phases tab and disclose the "Link Binary with Libraries" phase and click the plus button in that phase
  4. Add the following frameworks: 
     CoreTelephony.framework 
     StoreKit.framework 
     AdSupport.framework 
     WebKit.framework 
     libz.tbd

NOTE:

from now make sure to use the "Append" option (instead of "Replace") every time you "Build and Run" your project, so all the above changes will be kept.

Updating your IDFA Settings

When submitting your application to the App Store you need to update its "Advertising Identifier (IDFA)" settings in order to comply with Apple advertising policy.

On the "Advertising Identifier" section: 
1 Choose "Yes" on the right pane 
2 Opt-in the "Serve advertisements within the app" checkbox 
3 Opt-in the confirmation checkbox under "Limit Ad tracking setting in iOS" 

Advanced Usage

For advanced usage, please refer to the "Advanced Usage" section.

Was this article helpful?
0 out of 0 found this helpful