Search Unity

10-Step Integration Guide for Unity Ads in Unity

Discussion in 'Unity Ads' started by unity-nikkolai, Jan 29, 2015.

  1. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,773
    You code it yourself and show them when you want to like after game over or when 5 minutes has passed since game was launched.
     
    Sylvir likes this.
  2. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    okay cool thanks, i probably knew that I just was busy with a lot of things and had to run out the door so I thought I would ask thank you!. So the 2 codes that you put in there are just kind of the skeleton and set up so that adds will play. You just set up your own code to call those when and where you want? Also can you do an add banner with unity ads or are those not supported? Wasnt sure if they supported add banners too or just video adds. thanks!
     
  3. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,773
    Only video ads are supported but you can implement some other system for images.
     
  4. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    Excellent question, and a very good point. The ideal situation is to design your game with the knowledge that you'll be monetizing with ads, and provide purpose within your game for ads. The most effective ads tend to be rewarded ads. With rewarded ads, you provide your users with the option to watch an ad for some in-game reward.

    Some examples of rewards that we've seen:
    • Earn X number of coins, gems, or other in-game currency
    • Double your earnings for the last completed level of gameplay
    • Gain a bonus round of gameplay, or bonus health to continue gameplay
    • Chance to earn a consumable item, in-game currency, or an upgrade/cosmetic item
    There is an example of how to implement rewarded ads in the Unity Ads SpaceAds demo project. In the StartMenu scene, there is a GameObject called GetCoinsButton with a Unity UI Button component and the GetCoinsButton script, which uses the UnityAdsHelper script.

    The Button component is configured to call the ShowAd() method in the GetCoinsButton script. The Button becomes intractable when Unity Ads are available and ready, when the cooldown time has passed since the last ad was shown, and when the GetCoinsButtton is set intractable (allowing more control when using animation components).

    The GetCoinsButton has a few variables exposed to the inspector:
    • Zone ID – specify a zone ID to use, or leave blank to use the "default" zone
    • Rewarded Cooldown – length of delay in seconds before the button is available again
    • Reward Coin Amount – the number of coins to add to the existing inventory of coins
    • Interactable – used with animations to give more control over when the button is enabled
     

    Attached Files:

  5. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    thank you for taking the time to respond! I will give this some more thought and begin implementing them in the near future!
     
  6. Victor-M

    Victor-M

    Joined:
    Jul 4, 2015
    Posts:
    5
    Please, I need help. The Ads only work in editor..on android device nothing happens. :(
     
  7. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    thank you! does unity adds support an ad banner style as well or just the video adds?
     
  8. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    did you test it on your device as an actual built apk or just through the unity remote?
     
  9. anomaly_a

    anomaly_a

    Joined:
    May 10, 2012
    Posts:
    5
    I downloaded the scripts and Unity is warning me that several lines are obsolete. Do you have an updated version of them? I figured I could just adjust the scripts to cut out the obsolete portions but there are some significant changes.

    Edit: They are actually really easy to edit out now that I actually tried it.
     
  10. pardisproud

    pardisproud

    Joined:
    Jul 8, 2015
    Posts:
    1
    Im getting a Can't add script component when i try to add ShowAdsOnLoad to the empty GameObject
     
    Last edited: Jul 10, 2015
  11. Victor-M

    Victor-M

    Joined:
    Jul 4, 2015
    Posts:
    5
  12. Victor-M

    Victor-M

    Joined:
    Jul 4, 2015
    Posts:
    5
    I'm with other problem. I had 5 videos started and finished on unity Ads console. Today is the fist day. I was here making the last update before marketing. And all day long looking "Videos completed". So after a test opening that image ad in editor to see if the reward appear. But I see the "Videos completed", and back to "0". o_O

    I'm very scared about this. Somebody can explain me what happened? :(
     
  13. whitespeed

    whitespeed

    Joined:
    Jan 9, 2014
    Posts:
    1
    I'm so confused, it seems everything is OK but just don't show ads. I don't know why! The editor mode is iPhone, iPod and GameID is right. Here is the log and script:
    Debug:
    Debug: onFetchCompleted
    UnityEngine.Advertisements.<getAdPlan>c__Iterator0:MoveNext()

    Script:
    void Start ()
    {
    Advertisement.Initialize("55620",true);
    StartCoroutine(ShowAdWhenReady());
    }

    IEnumerator ShowAdWhenReady()
    {
    if(!Advertisement.IsReady())
    yield return null;
    Advertisement.Show();
    }
     
  14. The GUS

    The GUS

    Joined:
    Jan 24, 2015
    Posts:
    2
    If initialize on the scene "A" could I show in the scene "B", or I should initialize too in "B"?
     
  15. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,461
    Just wanted to say good job in providing simulated ads in the editor - this really helps development. I've ended up making my own editor simulation for other ad plugins so this has really saved me some work.
     
    unity-nikkolai likes this.
  16. Mr.Stein

    Mr.Stein

    Joined:
    Dec 4, 2013
    Posts:
    169
    unity-nikkolai likes this.
  17. KuaStore

    KuaStore

    Joined:
    Feb 3, 2015
    Posts:
    10
    Hey! I used your scripts and I am new to unity. Can you please tell me how can I add a timer? The ads displays every time I restart the scene and since my game is a simple game the ads display too often. Is there anyway I could make that the ads display 20 seconds after the scene is played? Thanks!
     
  18. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    Check out the Unity Ads Helper project. I've updated the helper with the new API changes, and improved upon it a bit. There is now a unitypackage available and a README that details the functionality and how to use it. There walks you through how to use the helper with examples in both C# and JavaScript, as well as reusable example assets that you can drag and drop into your project for your convenience.

    Will be updating this 10-step guide to use the new helper package, and update the SpaceAds demo as well. Will also be putting together a video walkthrough showing how to use the helper.
     
  19. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
  20. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    The new unity-ads-helper project includes a ButtonExample script with a timer that you can use. The project README goes into detail on how it works under the section titled Rewarding Users for Watching Ads.

    There's a slight difference between the example outlined in the README and the ButtonExample script provided with the example assets in the unitypackage, though. The example assets version takes it a step further and use PlayerPrefs to keep track of the timer between game sessions.
     
  21. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    You should only initialize Unity Ads once. If you're using the new Unity Ads Helper, you can drag and drop the helper script into scene "A" to initialize Unity Ads. It'll persist between scenes. This would allow Unity Ads enough time to initialize Unity Ads and cache video ads before you intend to show them.

    With Unity Ads initialize, you can then call UnityAdsHelper.ShowAd() from scene "B" whenever you want to show.

    Keep in mind, the new Unity Ads Helper has a settings file, which you can configure by selecting Edit > Unity Ads Settings from the Unity Editor menu. Set your iOS and Android game IDs there.
     
  22. simonini_thomas

    simonini_thomas

    Joined:
    Apr 30, 2015
    Posts:
    21
    Thanks for this tutorial. However I have two problem :

    - First, my ad must be load on the first scene (menu) but sometimes the ad starts on the second (game) so it's frustrating for a player.
    - Second my game is landscape however video ads are shown portrait.

    Moreover I have a question what is Zone id.

    Thanks a lot for your help and your tutorial. QUESTIONS.png
     
  23. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    236
    Hello @simonini_thomas ,

    1-Problem: I assume that, "menu" is your first scene when you run your application. Its not a good practice to show your game menu ,If you want to show an Ad at first run. Because it tooks 3-5 seconds(according to your connection) to your application is ready to serve a Video Ad. Since Unity Ads Helper has a DontDestroyOnLoad(gameObject) method , your ShowOnLoad scripts also couldnt destroy it self when you press play button. So as soon as your game is ready to show a Video Ad , it simply shows an Ad. When you press Play button and load your "game" scene "ShowOnLoad" script still tries to show an ad as soon as its ready.
    Possible Fix 1: Try split UnityAdsHelper and ShowOnLoad into different gameobjects.
    Possible Fix 2: Dont show your menu before Ad shows if it is a must.

    2- It is a known issue. If patching couldnt solve your problem , let us know for further check.

    3-

    Hope it helps,

    Regards,
     

    Attached Files:

    unity-nikkolai likes this.
  24. simonini_thomas

    simonini_thomas

    Joined:
    Apr 30, 2015
    Posts:
    21
    Thank you very much !
     
  25. waqasmajeed

    waqasmajeed

    Joined:
    Jan 2, 2014
    Posts:
    2
    Hi,

    Thanks @unity-nikkolai for sharing this. I am using these steps to integrate Unity ads into my android projects. Which is working perfectly.
    Is there any of your blog which can help to integrate Unity Ads into an Ios project?
     
  26. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    When integrating in Unity for iOS, setting up your project with the Unity Ads Helper is pretty much the same for Android. The only difference is, you need an iOS specific game ID. Be sure to update Unity Ads Settings with your game IDs for both iOS and Android (Edit > Unity Ads Settings).

    One other thing, if you created any custom zone IDs in your Android game profile, you would need to create the same zone IDs in you iOS game profile. You'll need to make sure the zone settings are the same for both game profiles for them to function the same for each platform.

    When building your Xcode project, it's recommended to use the Replace option instead of Append if you run into any issues after rebuilding the project. Other than that, you should be good to go.
     
    waqasmajeed likes this.
  27. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    277
    hi
    How to merge it in manifest unity3d ads ??
    I have now in my game chartboost and applovin all work fine but when i want to merge unity3d ads dont work :(

    Her the errors

    CommandInvokationFailure: Unable to merge android manifests. See the Console for more details.
    C:/Program Files/Java/jdk1.8.0_25\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="C:/android programm/adt-bundle-windows-x86_64-20140702/adt-bundle-windows-x86_64-20140702/sdk\tools" -Dfile.encoding=UTF8 -jar "C:/Program Files (x86)/unity5/Editor/Data/BuildTargetTools/AndroidPlayer\sdktools.jar" -

    stderr[
    Error: [Temp\StagingArea\AndroidManifest-main.xml:48, H:\projekte game\unity5games\test2\Temp\StagingArea\android-libraries\unityads\AndroidManifest.xml:10] Trying to merge incompatible /manifest/uses-permission[@name=android.permission.WRITE_EXTERNAL_STORAGE] element:
    <uses-permission
    -- @android:name="android.permission.WRITE_EXTERNAL_STORAGE">
    --</uses-permission>
    --(end reached)
    <uses-permission
    ++ @android:maxSdkVersion="18"
    ++ @android:name="android.permission.WRITE_EXTERNAL_STORAGE">
    ++</uses-permission>
    ]
    stdout[
    [Temp\StagingArea\AndroidManifest-main.xml:13, H:\projekte game\unity5games\test2\Temp\StagingArea\android-libraries\unityads\AndroidManifest.xml:4] Skipping identical /manifest/application/activity[@name=com.unity3d.ads.android.view.UnityAdsFullscreenActivity] element.
    ]
    UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    UnityEditor.Android.AndroidSDKTools.RunCommandInternal (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 memoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    UnityEditor.Android.AndroidSDKTools.RunCommandSafe (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 memoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    UnityEditor.HostView:OnGUI()




    Error building Player: CommandInvokationFailure: Unable to merge android manifests. See the Console for more details.
    C:/Program Files/Java/jdk1.8.0_25\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="C:/android programm/adt-bundle-windows-x86_64-20140702/adt-bundle-windows-x86_64-20140702/sdk\tools" -Dfile.encoding=UTF8 -jar "C:/Program Files (x86)/unity5/Editor/Data/BuildTargetTools/AndroidPlayer\sdktools.jar" -

    stderr[
    Error: [Temp\StagingArea\AndroidManifest-main.xml:48, H:\projekte game\unity5games\test2\Temp\StagingArea\android-libraries\unityads\AndroidManifest.xml:10] Trying to merge incompatible /manifest/uses-permission[@name=android.permission.WRITE_EXTERNAL_STORAGE] element:
    <uses-permission
    -- @android:name="android.permission.WRITE_EXTERNAL_STORAGE">
    --</uses-permission>
    --(end reached)
    <uses-permission
    ++ @android:maxSdkVersion="18"
    ++ @android:name="android.permission.WRITE_EXTERNAL_STORAGE">
    ++</uses-permission>
    ]
    stdout[
    [Temp\StagingArea\AndroidManifest-main.xml:13, H:\projekte game\unity5games\test2\Temp\StagingArea\android-libraries\unityads\AndroidManifest.xml:4] Skipping identical /manifest/application/activity[@name=com.unity3d.ads.android.view.UnityAdsFullscreenActivity] element.
    ]
     
    Last edited: Aug 11, 2015
  28. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    There's a note included with the Unity Ads AndroidManifest.xml file:
    Code (xml):
    1. <!-- Note: If android:maxSdkVersion attribute leads to problems when merging manifests, you can
    2.      remove maxSdkVersion attribute. Unity Ads on Android 4.4 or later won't need this permission so
    3.      maxSdkVersion means it is only requested for older Androids. -->
    4. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
    To fix the issue, you can remove the android:maxSdkVersion="18" attribute:
    Code (xml):
    1. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     
  29. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    277
    cant off the test mode every time when i off in unity3dads or in the project it will show unity3d ad s intersial???
     
  30. PabloHells

    PabloHells

    Joined:
    Jun 16, 2015
    Posts:
    16
    My game does not load the ads of Unity , he always carries testing ads , even I push off on selecting Monetization setting.

    What might be causing this problem?
     
  31. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    277
    the same problem looks like the method on the first side dont work
     
  32. PabloHells

    PabloHells

    Joined:
    Jun 16, 2015
    Posts:
    16
    Well ... The problem with testing ads I decided, but now I emerged a new doubts.

    Every time the ship of my game explodes and the player must restart the stage, so the stage starts a new video is presented to my player and this whenever it has to restart the level.
    I wonder if this can cause me any problems with the terms of the Unity ADS?
     
  33. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    If you are just starting out with the Unity Ads Helper, remember that you need to set your own game IDs under Edit > Unity Ads Settings. The example game IDs provided there by default will only show test ads.

    Screen Shot 2015-08-13 at 12.53.16 PM.png

    If you have the Unity Ads Helper configured with your own game IDs, and the Enable Test Mode option is disabled in Unity Ads Settings, double check your Ad Test Mode settings in the Unity Ads Admin. Ad Test Mode settings are found under the Monetization Settings tab of each game profile.

    By default, the Ad Test Mode is set to use Client Settings (so, whether you Enable Test Mode enabled or not in Unity Ads Settings). You can override the Client Settings by selecting any of the other options. If you want to disable test mode for all users, select the Force Off option. Conversely, if you want to enable test mode for all users, select the Force All option. There is also an option to show test ads only on specific test devices, identified by their advertising ID.
     
  34. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    277
    ok found another solution your tut on the first side dont work by i use the normal method from unity3d ads doc .
     
  35. Sarhanbh

    Sarhanbh

    Joined:
    Apr 15, 2015
    Posts:
    32
    hay
    Is it problem when I changed gameID but when open another scene the game id overwritte to defult ID :/ !!

    and what is diffrent between Reward and non-Reward ?(sorry my english poor)
     
    Last edited: Aug 15, 2015
  36. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    It shouldn't. I haven't been able to reproduce this issue. What version of Unity are you using? If this issue is happening for you, try selecting File > Save Project after changing the IDs. Then open the new scene. If you're still getting the issue, try it again in a new project (just to make sure it's not isolated to the existing project).

    Rewarded ads are non-skippable, while non-rewarded ads allow the option to be skipped.
     
  37. biscito

    biscito

    Joined:
    Apr 3, 2013
    Posts:
    83
    hey , )

    there a problem in xcode & app Transport Security
    basically the ads don't show,
     
  38. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    @biscito: App Transport Security in iOS 9 requires that all web requests be sent by HTTPS. Unity Ads SDK v1.4.5 (Asset Store package v1.2.1) and later supports iOS 9, however we have not yet flipped the switch on the servers to use exclusively HTTPS. We will do so after August 31st.
     
    biscito likes this.
  39. waqasmajeed

    waqasmajeed

    Joined:
    Jan 2, 2014
    Posts:
    2
    Hi @unity-nikkolai . Yes, that worked on ios too. Thanks for your help.
     
  40. firativerson

    firativerson

    Joined:
    Jan 22, 2015
    Posts:
    28
    I put my app on the market and successfully added my package name in unity ads website. However I am still getting just unity video and no actual ads. Anybody knows why? I am currently on a vacation in Turkey, is it because I am not in US?
     
  41. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    @firativerson: Sounds like you still have test mode enabled for your game. You can override test mode from the Unity Ads Admin.
    1. Select your game profile from the Games page.
    2. Select the Monetization Settings tab and click Show Advanced Settings.
    3. Scroll down to the Ad Test Mode section and select Change.
    4. Select the Force Off option and select Save.
     
    firativerson likes this.
  42. firativerson

    firativerson

    Joined:
    Jan 22, 2015
    Posts:
    28
    @unity-nikkolai thank you, that solved my problem. I assumed pointing the app in market would automatically change from test mode to active! Thanks again!
     
  43. Dynamikeyz

    Dynamikeyz

    Joined:
    Aug 21, 2015
    Posts:
    29
    So I've implemented UnityAds using the script you've kindly attached. However, I've set development mode on, deselected "enable test mode" and yet I'm still seeing the default Unity video and ad at the beginning of the screen. I want to be able to see if a live ad work? Should I change "run in Xcode as debug" to release?

    I also tried the above when you
    "
    1. Select your game profile from the Games page.
    2. Select the Monetization Settings tab and click Show Advanced Settings.
    3. Scroll down to the Ad Test Mode section and select Change.
    4. Select the Force Off option and select Save."
    Still doesn't work? Should I change that back to the old setting?

    I'm in the UK if that helps.

    Also, [edit] just tried it again. Seems to have worked first time, showing an "download get game (Angry Bots?!)" after the default unity ads video. Then it stopped working again... Is the unity ads video supposed to play? I thought it was supposed to be a video ad?


    Thanks
     
    Last edited: Aug 27, 2015
  44. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    @Dynamikeyz: You might still have Unity Ads configured with the default game IDs. Those are set to only show test ads (which can be set from the Unity Ads admin). Go to Edit > Unity Ads Settings, and enter your own game IDs in the fields provided.

    If you still only see test ads with your own game IDs entered in settings, send me a private message with your game IDs so I can double check your settings. Also send me a download link so I can test your game locally.
     
  45. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    @Dynamikeyz: If you had previously set your game IDs in Unity Ads Settings, it's possible the changes didn't save. I just updated the Unity Ads Helper so that it actively saves after any changes are made.
     
  46. Dynamikeyz

    Dynamikeyz

    Joined:
    Aug 21, 2015
    Posts:
    29
    I would love to but my USB with the files are broken :( All I have is the Xcode build files... :') lol is there a way to have the original unity file again? I'll pm you
     
  47. feranonono

    feranonono

    Joined:
    Dec 2, 2014
    Posts:
    1
    in unityAdsSetting should i unCheck the enable test mode when i publish the game? thanks!
     
  48. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    In this helper implementation, you don't need to since it relies on Development Mode being enabled as well.

    If you need to, you can always override these test mode settings from the Unity Ads Admin:
    1. Select your game profile from the Games page.
    2. Select the Monetization Settings tab and click Show Advanced Settings.
    3. Scroll down to the Ad Test Mode section and click Change.
    4. Select any of the options and click Save.
    By default, Ad Test Mode is set to use Client Setting. If you want to turn Test Mode off for all devices, select the Force Off option and click save. You can also setup Ad Test Mode to only show ads on your personal test devices by selecting the Test Devices Only option and adding the Advertising IDs for each device.
     
  49. jpv1234

    jpv1234

    Joined:
    Dec 5, 2014
    Posts:
    87
    Any idea how to setup the new integration with Unity ads on 5.2? There is no guide about it and Unity helper is causing this error

    Assets/Scripts/Game Scripts/UnityAdsHelper.cs(157,47): error CS0433: The imported type `UnityEngine.Advertisements.ShowResult' is defined multiple times

    I know that this is caused because the service is already integrated in 5.2. It's just that I can't get it working now
     
  50. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    @jpv1234: That error actually indicates a conflict between the Unity Ads asset package and the Unity Ads API that's included with Unity 5.2. If you remove the Unity Ads assets from your project and enable Unity Ads through the new Services window, this error should resolve itself.

    If you prefer to continue using the Unity Ads asset package, simply reimport it from the Asset Store and leave Unity Ads disabled in the Services window. If you choose to continue using the version of Unity Ads available through the Asset Store, you'll need to add UNITY_ADS_SDK to Scripting Define Symbols in Player Settings for both iOS and Android.

    I'll be updating the docs with this info shortly. Thanks!

    Screen Shot 2015-09-08 at 4.09.50 PM.png Screen Shot 2015-09-08 at 4.14.03 PM.png