Search Unity

Unity ads shows only at first launch of the game

Discussion in 'Unity Ads & User Acquisition' started by jjoker8, May 16, 2019.

  1. jjoker8

    jjoker8

    Joined:
    Apr 17, 2019
    Posts:
    4
    Android game show ads only first time after instalation, or first time after reset the phone (turn off and on). When I play next time ads are not loading. I suspect it has something common with this pop-up window about cookie policy, if it doesn't show, ads doesn't show either. Problem occurs also on new empty project, tested on galaxy s4 and galaxy s8. I tried in test mode and with real ads, all the same, it's loading only at first launch of the application, when it asks about cookie permission. I'm quite sure it's nothing wrong with my code, as it comes from documentation Game is not integrated with Google Play.

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.Monetization;
    6. using UnityEngine.UI;
    7.  
    8. public class AdController : MonoBehaviour
    9. {
    10.     string log;
    11.     public GameObject Log;
    12.  
    13.     public static AdController Instance { get; private set; }
    14.  
    15.     public bool isInTestMode = false;
    16.  
    17.     private string GooglePlayID = "*******";
    18.  
    19.     private string videoAd = "video";
    20.     private string rewardedVideoAd = "rewardedVideo";
    21.  
    22.     private void Awake()
    23.     {
    24.  
    25.         if (Instance == null)
    26.         {
    27.             Instance = this;
    28.             DontDestroyOnLoad(gameObject);
    29.         }
    30.         else
    31.         {
    32.             Destroy(gameObject);
    33.         }
    34.  
    35.     }
    36.     // Start is called before the first frame update
    37.     void Start()
    38.     {
    39.         if (!Monetization.isInitialized)
    40.         {
    41.             Monetization.Initialize(GooglePlayID, isInTestMode);
    42.  
    43.         }
    44.  
    45.         if(Monetization.isInitialized)
    46.         {
    47.             PrintLog("Monetization is initialized");
    48.         }
    49.         else
    50.         {
    51.             PrintLog("Monetization is not initialized");
    52.         }
    53.     }
    54.  
    55.     public void ShowAd()
    56.     {
    57.  
    58.         if (!Monetization.isInitialized)
    59.         {
    60.             Monetization.Initialize(GooglePlayID, isInTestMode);
    61.         }
    62.         if (Monetization.isInitialized)
    63.         {
    64.             PrintLog("Monetization is initialized");
    65.         }
    66.         else
    67.         {
    68.             PrintLog("Monetization is not initialized");
    69.         }
    70.         StartCoroutine(WaitForAd(false));
    71.     }
    72.  
    73.     public void ShowRewardedAd()
    74.     {
    75.         if (!Monetization.isInitialized)
    76.         {
    77.             Monetization.Initialize(GooglePlayID, isInTestMode);
    78.         }
    79.         if (Monetization.isInitialized)
    80.         {
    81.             PrintLog("Monetization is initialized");
    82.         }
    83.         else
    84.         {
    85.             PrintLog("Monetization is not initialized");
    86.         }
    87.         StartCoroutine(WaitForAd(true));
    88.     }
    89.     IEnumerator WaitForAd(bool rewarded = false)
    90.     {
    91.         PrintLog("Waiting for ad");
    92.         string placementId = rewarded ? rewardedVideoAd : videoAd;
    93.  
    94.         while (!Monetization.IsReady(placementId))
    95.         {
    96.             yield return null;
    97.         }
    98.  
    99.         ShowAdPlacementContent ad = null;
    100.         ad = Monetization.GetPlacementContent(placementId) as ShowAdPlacementContent;
    101.  
    102.         if (ad!=null)
    103.         {
    104.             PrintLog("Ad is loaded");
    105.         }
    106.         else
    107.         {
    108.             PrintLog("Ad is not loaded");
    109.         }
    110.  
    111.         if (ad != null)
    112.         {
    113.             if (rewarded)
    114.                 ad.Show(AdFinished);
    115.             else
    116.                 ad.Show();
    117.         }
    118.     }
    119.     void AdFinished(ShowResult result)
    120.     {
    121.         if (result == ShowResult.Finished)
    122.         {
    123.             //Reward player
    124.             PrintLog("Result: " + result.ToString());
    125.         }
    126.     }
    127.  
    128.     void PrintLog(string txt)
    129.     {
    130.         log = log + txt + "     ";
    131.         Log.GetComponent<Text>().text = log;
    132.  
    133.     }
    134. }
     
    Last edited: May 16, 2019
  2. mikaisomaa

    mikaisomaa

    Unity Technologies

    Joined:
    Sep 14, 2015
    Posts:
    365
    Can you provide device logs?
     
  3. jjoker8

    jjoker8

    Joined:
    Apr 17, 2019
    Posts:
    4
    Ok I had to learn how to use adb, but Finally I have the log :)

    Code (CSharp):
    1. --------- beginning of system
    2. --------- beginning of main
    3. I/Unity   (27860): onResume
    4. D/Unity   (27860): SetWindow 0 0x92743608
    5. D/Unity   (27860): SetWindow 0 0x92743608
    6. I/Unity   (27860): windowFocusChanged: true
    7. D/Unity   (27860): Unity systrace disabled: failed to load native tracing API
    8. D/Unity   (27860): [VFS] Mount /mnt/asec/com.MyCompany.AdsTest-1/base.apk
    9. I/Unity   (27860): SystemInfo CPU = ARMv7 VFPv3 NEON, Cores = 4, Memory = 1819mb
    10. I/Unity   (27860): SystemInfo ARM big.LITTLE configuration: 4 big (mask: 0xf), 0 little (mask: 0x0)
    11. I/Unity   (27860): ApplicationInfo com.MyCompany.AdsTest version 0.1 build a512174b-4ec7-4103-bcd1-031045065179
    12. I/Unity   (27860): Built from '2019.1/staging' branch, Version '2019.1.1f1 (fef62e97e63b)', Build type 'Development', Scripting Backend 'il2cpp', CPU 'armeabi-v7a', Stripping 'Enabled'
    13. D/Unity   (27860): PlayerConnection initialized from /mnt/asec/com.MyCompany.AdsTest-1/base.apk/assets/bin/Data (debug = 0)
    14. E/Unity   (27860): Socket: set reusable port failed, error: Protocol not available(92)
    15. E/Unity   (27860):
    16. E/Unity   (27860): (Filename: ./Runtime/Network/Sockets.cpp Line: 415)
    17. E/Unity   (27860):
    18. E/Unity   (27860): Socket: set reusable port failed, error: Protocol not available(92)
    19. E/Unity   (27860):
    20. E/Unity   (27860): (Filename: ./Runtime/Network/Sockets.cpp Line: 415)
    21. E/Unity   (27860):
    22. E/Unity   (27860): Socket: set reusable port failed, error: Protocol not available(92)
    23. E/Unity   (27860):
    24. E/Unity   (27860): (Filename: ./Runtime/Network/Sockets.cpp Line: 415)
    25. E/Unity   (27860):
    26. E/Unity   (27860): Socket: set reusable port failed, error: Protocol not available(92)
    27. E/Unity   (27860):
    28. E/Unity   (27860): (Filename: ./Runtime/Network/Sockets.cpp Line: 415)
    29. E/Unity   (27860):
    30. D/Unity   (27860): PlayerConnection initialized network socket : 0.0.0.0 55397
    31. D/Unity   (27860): PlayerConnection initialized unix socket : Unity-com.MyCompany.AdsTest
    32. D/Unity   (27860): Multi-casting "[IP] 192.168.1.34 [Port] 55397 [Flags] 3 [Guid] 2738031774 [EditorId] 1721574797 [Version] 1048832 [Id] AndroidPlayer(samsung_GT-I9505@192.168.1.34) [Debug] 1 [PackageName] AndroidPlayer" to [225.0.0.222:54997]...
    33. D/Unity   (27860): Waiting for connection from host on [0.0.0.0:55397]...
    34. D/Unity   (27860): PlayerConnection accepted from [192.168.1.33] handle:0x2c
    35. D/Unity   (27860): Started listening to [0.0.0.0:55397]
    36. D/Unity   (27860): [EGL] Attaching window :0x92743608
    37. D/Unity   (27860): InitializeScriptEngine OK (0xa08e5fe0)
    38. D/Unity   (27860): PlayerConnection already initialized - listening to [0.0.0.0:55397]
    39. D/Unity   (27860): PlayerInitEngineNoGraphics OK
    40. D/Unity   (27860): AndroidGraphics::Startup window =  0x92743608
    41. D/Unity   (27860): [EGL] Attaching window :0x92743608
    42. D/Unity   (27860): Vulkan detection: 0
    43. D/Unity   (27860): [EGL] Request: ES 3.1+AEP RGB0 000 0/0
    44. D/Unity   (27860): [EGL] Checking ES 3.1 support...
    45. D/Unity   (27860): [EGL] ES3.1 not supported
    46. D/Unity   (27860): [EGL] Request: ES 3.1 RGB0 000 0/0
    47. D/Unity   (27860): [EGL] Request: ES 3.0 RGB0 000 0/0
    48. D/Unity   (27860): [EGL] Found: ID[1] ES 3.0 RGB16 565 0/0
    49. D/Unity   (27860): GfxDevice: creating device client; threaded=1
    50. D/Unity   (27860): [EGL] Request: ES 3.1+AEP RGB0 000 0/0
    51. D/Unity   (27860): [EGL] Request: ES 3.1 RGB0 000 0/0
    52. D/Unity   (27860): [EGL] Request: ES 3.0 RGB0 000 0/0
    53. D/Unity   (27860): [EGL] Found: ID[1] ES 3.0 RGB16 565 0/0
    54. D/Unity   (27860): [EGL] Request: ES 3.0 RGBA32 8888 0/0
    55. D/Unity   (27860): [EGL] Found: ID[5] ES 3.0 RGBA32 8888 0/0
    56. D/Unity   (27860): extension is supported with value 0
    57. D/Unity   (27860): ANativeWindow: (1080/1920) RequestedResolution: (0/0) RenderingResolution: (0/0) EGLSurface: (1080/1920)
    58. D/Unity   (27860): Renderer: Adreno (TM) 320
    59. D/Unity   (27860): Vendor:   Qualcomm
    60. D/Unity   (27860): Version:  OpenGL ES 3.0 V@84.0 AU@  (CL@)
    61. D/Unity   (27860): GLES:     3
    62. D/Unity   (27860):  GL_EXT_disjoint_timer_query
    63. D/Unity   (27860): OPENGL LOG: Creating OpenGL ES 3.0 graphics device ; Context level  <OpenGL ES 3.0> ; Context handle -1969934400
    64. D/Unity   (27860): [EGL] Attaching window :0x92743608
    65. D/Unity   (27860): Requested framebuffer: resolution[1080x1920], rgba[8/8/8/8], depth+stencil[on], samples[1]
    66. D/Unity   (27860): Created framebuffer: resolution[1080x1920], rgba[8/8/8/8], depth+stencil[24/8], samples[0]
    67. D/Unity   (27860): [EGL] Attaching window :0x92743608
    68. D/Unity   (27860): Initialize engine version: 2019.1.1f1 (fef62e97e63b)
    69. D/Unity   (27860): PlayerInitEngineGraphics OK
    70. D/Unity   (27860): Found 18 native sensors
    71. D/Unity   (27860): Sensor :        Accelerometer ( 1) ; 0.000599 / 0.01s ; K330 3-axis Accelerometer / STMicroelectronics
    72. D/Unity   (27860): Sensor :        Accelerometer ( 1) ; 0.000599 / 0.01s ; K330 3-axis Accelerometer / STMicroelectronics
    73. D/Unity   (27860): UnloadTime: 0.488281 ms
    74. D/Unity   (27860): UUID: aab26881f99a2a9f => 81faee63918747dccb54d006cbe036f5
    75. D/Unity   (27860): Sensor :        Accelerometer ( 1) ; 0.000599 / 0.01s ; K330 3-axis Accelerometer / STMicroelectronics
    76. D/Unity   (27860): Choreographer available: Enabling VSYNC timing
    77. I/Unity   (27860): windowFocusChanged: false
    78. I/Unity   (27860): onPause
    79. D/Unity   (27860): Setting up 1 worker threads for Enlighten.
    80. D/Unity   (27860):   Thread -> id: ffffffff99a58e00 -> priority: 1
    81. D/Unity   (27860): ASensorManager_destroyEventQueue returned 0
    82. I/Unity   (27860): ##utp:{"type":"MemoryLeaks","version":2,"phase":"Immediate","time":1558014611589,"processId":27860,"allocatedMemory":148672,"memoryLabels":[{"Default":56},{"NewDelete":13760},{"Thread":4294967248},{"Manager":192},{"GfxDevice":4628},{"Audio":88},{"Serialization":24},{"Terrain":60},{"String":2604},{"DynamicArray":123976},{"Utility":1680},{"PoolAlloc":4294967236},{"ScriptManager":1416},{"VR":20},{"SceneManager":224},{"EditorGui":52}]}
    83. I/Unity   (27860): onDestroy
    84. I/Unity   (27860): onResume
    85. D/Unity   (27860): SetWindow 0 0x92744408
    86. D/Unity   (27860): SetWindow 0 0x92744408
    87. I/Unity   (27860): windowFocusChanged: true
    88. D/Unity   (27860): Unity systrace disabled: failed to load native tracing API
    89. D/Unity   (27860): [VFS] Mount /mnt/asec/com.MyCompany.AdsTest-1/base.apk
    90. I/Unity   (27860): SystemInfo CPU = ARMv7 VFPv3 NEON, Cores = 4, Memory = 1819mb
    91. I/Unity   (27860): SystemInfo ARM big.LITTLE configuration: 4 big (mask: 0xf), 0 little (mask: 0x0)
    92. I/Unity   (27860): ApplicationInfo com.MyCompany.AdsTest version 0.1 build a512174b-4ec7-4103-bcd1-031045065179
    93. I/Unity   (27860): Built from '2019.1/staging' branch, Version '2019.1.1f1 (fef62e97e63b)', Build type 'Development', Scripting Backend 'il2cpp', CPU 'armeabi-v7a', Stripping 'Enabled'
    94. D/Unity   (27860): PlayerConnection initialized from /mnt/asec/com.MyCompany.AdsTest-1/base.apk/assets/bin/Data (debug = 0)
    95. E/Unity   (27860): Socket: set reusable port failed, error: Protocol not available(92)
    96. E/Unity   (27860):
    97. E/Unity   (27860): (Filename: ./Runtime/Network/Sockets.cpp Line: 415)
    98. E/Unity   (27860):
    99. E/Unity   (27860): Socket: set reusable port failed, error: Protocol not available(92)
    100. E/Unity   (27860):
    101. E/Unity   (27860): (Filename: ./Runtime/Network/Sockets.cpp Line: 415)
    102. E/Unity   (27860):
    103. E/Unity   (27860): Socket: set reusable port failed, error: Protocol not available(92)
    104. E/Unity   (27860):
    105. E/Unity   (27860): (Filename: ./Runtime/Network/Sockets.cpp Line: 415)
    106. E/Unity   (27860):
    107. E/Unity   (27860): Socket: set reusable port failed, error: Protocol not available(92)
    108. E/Unity   (27860):
    109. E/Unity   (27860): (Filename: ./Runtime/Network/Sockets.cpp Line: 415)
    110. E/Unity   (27860):
    111. D/Unity   (27860): PlayerConnection initialized network socket : 0.0.0.0 55029
    112. D/Unity   (27860): PlayerConnection initialized unix socket : Unity-com.MyCompany.AdsTest
    113. D/Unity   (27860): Multi-casting "[IP] 192.168.1.34 [Port] 55029 [Flags] 3 [Guid] 2351345499 [EditorId] 1721574797 [Version] 1048832 [Id] AndroidPlayer(samsung_GT-I9505@192.168.1.34) [Debug] 1 [PackageName] AndroidPlayer" to [225.0.0.222:54997]...
    114. D/Unity   (27860): Waiting for connection from host on [0.0.0.0:55029]...
    115. D/Unity   (27860): PlayerConnection accepted from [192.168.1.33] handle:0x2c
    116. D/Unity   (27860): Started listening to [0.0.0.0:55029]
    117. D/Unity   (27860): [EGL] Attaching window :0x92744408
    118. D/Unity   (27860): InitializeScriptEngine OK (0x9f75bfe0)
    119. D/Unity   (27860): PlayerConnection already initialized - listening to [0.0.0.0:55029]
    120. D/Unity   (27860): PlayerInitEngineNoGraphics OK
    121. D/Unity   (27860): AndroidGraphics::Startup window =  0x92744408
    122. D/Unity   (27860): [EGL] Attaching window :0x92744408
    123. D/Unity   (27860): Vulkan detection: 0
    124. D/Unity   (27860): [EGL] Request: ES 3.1+AEP RGB0 000 0/0
    125. D/Unity   (27860): [EGL] Checking ES 3.1 support...
    126. D/Unity   (27860): [EGL] ES3.1 not supported
    127. D/Unity   (27860): [EGL] Request: ES 3.1 RGB0 000 0/0
    128. D/Unity   (27860): [EGL] Request: ES 3.0 RGB0 000 0/0
    129. D/Unity   (27860): [EGL] Found: ID[1] ES 3.0 RGB16 565 0/0
    130. D/Unity   (27860): GfxDevice: creating device client; threaded=1
    131. D/Unity   (27860): [EGL] Request: ES 3.1+AEP RGB0 000 0/0
    132. D/Unity   (27860): [EGL] Request: ES 3.1 RGB0 000 0/0
    133. D/Unity   (27860): [EGL] Request: ES 3.0 RGB0 000 0/0
    134. D/Unity   (27860): [EGL] Found: ID[1] ES 3.0 RGB16 565 0/0
    135. D/Unity   (27860): [EGL] Request: ES 3.0 RGBA32 8888 0/0
    136. D/Unity   (27860): [EGL] Found: ID[5] ES 3.0 RGBA32 8888 0/0
    137. D/Unity   (27860): extension is supported with value 0
    138. D/Unity   (27860): ANativeWindow: (1080/1920) RequestedResolution: (0/0) RenderingResolution: (0/0) EGLSurface: (1080/1920)
    139. D/Unity   (27860): Renderer: Adreno (TM) 320
    140. D/Unity   (27860): Vendor:   Qualcomm
    141. D/Unity   (27860): Version:  OpenGL ES 3.0 V@84.0 AU@  (CL@)
    142. D/Unity   (27860): GLES:     3
    143. D/Unity   (27860):  GL_EXT_disjoint_timer_query
    144. D/Unity   (27860): OPENGL LOG: Creating OpenGL ES 3.0 graphics device ; Context level  <OpenGL ES 3.0> ; Context handle -1659027776
    145. D/Unity   (27860): [EGL] Attaching window :0x92744408
    146. D/Unity   (27860): Requested framebuffer: resolution[1080x1920], rgba[8/8/8/8], depth+stencil[on], samples[1]
    147. D/Unity   (27860): Created framebuffer: resolution[1080x1920], rgba[8/8/8/8], depth+stencil[24/8], samples[0]
    148. D/Unity   (27860): [EGL] Attaching window :0x92744408
    149. D/Unity   (27860): Initialize engine version: 2019.1.1f1 (fef62e97e63b)
    150. D/Unity   (27860): PlayerInitEngineGraphics OK
    151. D/Unity   (27860): Found 18 native sensors
    152. D/Unity   (27860): Sensor :        Accelerometer ( 1) ; 0.000599 / 0.01s ; K330 3-axis Accelerometer / STMicroelectronics
    153. D/Unity   (27860): Sensor :        Accelerometer ( 1) ; 0.000599 / 0.01s ; K330 3-axis Accelerometer / STMicroelectronics
    154. D/Unity   (27860): UnloadTime: 0.396729 ms
    155. D/Unity   (27860): UUID: aab26881f99a2a9f => 81faee63918747dccb54d006cbe036f5
    156. D/Unity   (27860): Sensor :        Accelerometer ( 1) ; 0.000599 / 0.01s ; K330 3-axis Accelerometer / STMicroelectronics
    157. D/Unity   (27860): Choreographer available: Enabling VSYNC timing
    158. I/Unity   (27860): windowFocusChanged: false
    159. I/Unity   (27860): onPause
    160. D/Unity   (27860): Setting up 1 worker threads for Enlighten.
    161. D/Unity   (27860):   Thread -> id: ffffffff997b5300 -> priority: 1
    162. D/Unity   (27860): ASensorManager_destroyEventQueue returned 0
    163. I/Unity   (27860): ##utp:{"type":"MemoryLeaks","version":2,"phase":"Immediate","time":1558014671523,"processId":27860,"allocatedMemory":149888,"memoryLabels":[{"Default":56},{"NewDelete":14976},{"Thread":4294967248},{"Manager":192},{"GfxDevice":4628},{"Audio":88},{"Serialization":24},{"Terrain":60},{"String":2604},{"DynamicArray":123976},{"Utility":1680},{"PoolAlloc":4294967236},{"ScriptManager":1416},{"VR":20},{"SceneManager":224},{"EditorGui":52}]}
    164. I/Unity   (27860): onDestroy
     
    Last edited: May 16, 2019