interstitial auto-close timing incorrect

206 views
Skip to first unread message

Cecile H

unread,
Oct 19, 2016, 12:23:27 PM10/19/16
to Google Mobile Ads SDK Developers, cecile....@dat.com
Hi,

I'm running into an issue with auto-closing an interstitial ad.

Our DFP interstitial ad is configured to auto-close after a 6 second wait.  The timing of the auto close is not behaving as expected.  Sometimes the ad closes a couple seconds after displaying and sometimes it doesn't close at all.

I think the problem is the auto-close count down starts too soon. 

My observations via timing statements in Swift code lead me to believe that the auto-close count down starts when the ad finishes loading.
I put timing statements in GADInterstitialDelegate interstitialDidReceiveAd, interstitialWillPresentScreen, and interstitialWillDismissScreen
I expected the the auto-close count down to start when I presented the ad. (i.e. called presentFromRootViewController)
Is this expectation correct? 

Implementation details are included below. 
Any thoughts on what I should change to get the interstitial ad to auto-close 6 seconds after it is presented?

Please let me know if my question is unclear or if you need additional information.  Any help you can provide would be much appreciated!  
Thanks, Cecile



Implementation details:
  • iOS Mobile Ads SDK version: 7.12.1
  • model and OS version of the device: iPhone 6, iOS 10.0.2
The creative for the ad was created using the 'Mobile Interstitial with Auto-close' template. (see java script pasted at the bottom of this post)

In the iOS app
DFPInterstitial is created and loadRequest is called on app startup in AppDelegate didFinishLaunchingWithOptions.
    interstitial = DFPInterstitial(adUnitID: adId)
    interstitial
!.loadRequest(DFPRequest())  

presentFromRootViewController is called when the main view controller appears in viewDidAppear.
    if interstitial.isReady && !interstitial.hasBeenUsed {
        interstitial
.presentFromRootViewController(self)
   
}



JavaScript in the creative
<script type="text/javascript" src="//googleads.g.doubleclick.net/mads/static/mad/sdk/native/api/v1/google_mobile_app_ads.js"></script>
<script>
<!--
var _admDisplayTime='[%DisplayTime%]';

function _admScreenFitting(){
   
var _admPImage=document.getElementById('_admPortraitImage');
   
var _admLImage=document.getElementById('_admLandscapeImage');
   
var screenWidth=window.innerWidth;
   
var screenHeight=window.innerHeight;
   
var imageRatio=480/320;
   
if(screenWidth>screenHeight){
     
//landscape mode
     
var newWidth=screenWidth;
     
var newHeight=screenWidth/imageRatio;
     
if(newHeight>screenHeight){
         
var newWidth=screenHeight*imageRatio;
     
var newHeight=screenHeight;
     
}
   
}
   
else{
     
//portrait mode
     
var newWidth=screenHeight/imageRatio;
     
var newHeight=screenHeight;
     
if(newWidth>screenWidth){
         
var newHeight=screenWidth*imageRatio;
         
var newWidth=screenWidth;
     
}
   
}
   displayDensity
=window.devicePixelRatio?window.devicePixelRatio:1;
   
if(displayDensity!=1){
      _admPImage
.src=('[%PortraitImageHD%]'!='')?'[%PortraitImageHD%]':_admPImage.src;
      _admLImage
.src=('[%LandscapeImageHD%]'!='')?'[%LandscapeImageHD%]':_admLImage.src;
   
}
   
if('[%AllowScaling%]'=='yes'){
      _admLImage
.width=newWidth;
      _admLImage
.height=newHeight;
      _admPImage
.width=newWidth;
      _admPImage
.height=newHeight;
   
}
   _admStartCountDown
();
}

function _admPreCheckForThirdParty(){
   
// Check for third party impression tracker
   
if('[%ThirdPartyImpressionTracker%]'!=''){
     
var thirdImp=document.createElement('IMG');
      thirdImp
.src='[%ThirdPartyImpressionTracker%]';
     
with(thirdImp.style){width='1px';height='1px';position='absolute';top='-100%'};
      document
.body.appendChild(thirdImp);
   
}
   _admScreenFitting
();
}

function _admStartCountDown() {
    setTimeout
('admob.opener.close()',parseInt(_admDisplayTime)*1000)
}

function _admOnload() {
     
if (admob.opener.isOverlayShowing()) {
         _admStartCountDown
()
     
} else {  
          admob
.events.addEventListener('onshow', _admStartCountDown)
     
}
}

if (window.addEventListener) {  
    window
.addEventListener("load", _admPreCheckForThirdParty, false);
    window
.addEventListener("resize", _admScreenFitting, false)  
} else {  
    window
.attachEvent("onload", _admPreCheckForThirdParty)
}
//-->
</script>


Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Oct 19, 2016, 4:32:03 PM10/19/16
to Google Mobile Ads SDK Developers, cecile....@dat.com
Hi Cecile,

Can you send us an Ad Unit ID that would serve this creative? We will have a look again from there. Also, from looking at your creative, I did not find anything conspicuous but have you first tried with our sample apps to reproduce the issue?

Thanks,
Arjun Busani
Mobile Ads SDK Team

Cecile H

unread,
Oct 19, 2016, 6:19:54 PM10/19/16
to Google Mobile Ads SDK Developers, cecile....@dat.com
Hi Arjun,

Thank you for your help.

I am able to reproduce the issue using my creative and the Swift/doubleclick/DFPInterstitial sample app.

I did the following
1) in the DFPInterstitialExample app, in ViewController.swift, change gameLength to 2, which is much shorter than the 6 second wait used by the creative
   
 static let gameLength = 2

2) build and run 
3) when the game is over immediately click Ok.
My interstitial ad displays for a few seconds and then automatically closes

4) change gameLength to 8, which is longer than the 6 second wait used by the creative
    
static let gameLength = 8

5) build and run
6) when the game is over immediately click Ok.
My interstitial ad displays and remains open

I sent you my Ad Unit ID via email.

Thanks, Cecile

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Oct 20, 2016, 10:53:51 AM10/20/16
to Google Mobile Ads SDK Developers, cecile....@dat.com
Hi Cecile,

Thank you for your Ad Unit ID. I was able to reproduce the issue and it was due to your implementation. Let's look at your template's code snippet here -

    function _admStartCountDown() {
        setTimeout('admob.opener.close()', parseInt(_admDisplayTime) * 1000)

    }

    function _admOnload() {
        if (admob.opener.isOverlayShowing()) {
            _admStartCountDown()
        } else {
            admob.events.addEventListener('onshow', _admStartCountDown)
        }
    }
    if (window.addEventListener) {
        window.addEventListener("load", _admPreCheckForThirdParty, false);
        window.addEventListener("resize", _admScreenFitting, false)
    } else {
        window.attachEvent("onload", _admPreCheckForThirdParty)
   }
When you are adding an event listener for "load" and "onload", you must link that to _admOnload(). Instead, you are having your _admPreCheckForThirdParty() function and in that, you are never calling _admOnload().

One quick fix is to simply add _admOnload() into your _admPreCheckForThirdParty() function like this - 

function _admPreCheckForThirdParty(){
   // Check for third party impression tracker

   if(''!=''){
      var thirdImp=document.createElement('IMG');
      thirdImp.src='';

      with(thirdImp.style){width='1px';height='1px';position='absolute';top='-100%'};
      document.body.appendChild(thirdImp);
   }
   _admScreenFitting();

   _admOnload();
}

Let us know if you need anything else.

Thanks,
Arjun Busani
Mobile Ads SDK Team

Cecile H

unread,
Oct 21, 2016, 10:38:42 AM10/21/16
to Google Mobile Ads SDK Developers, cecile....@dat.com
Hi Arjun,

Thank you!   

We added a new creative, using a custom template.  Our custom template is a copy of the system template "Mobile Interstitial with Auto-close (app)" with the change you recommended.

Our interstitial ad is now auto closing as expected.

Thanks again!  -Cecile
Reply all
Reply to author
Forward
0 new messages