Disabling AdSense based on cookies

Hello there,

So I have quite a tough question about AdSense.

I'm in a partnership with one advertising company and I need, when visitors come throught this company, I need to show their ads for the whole time. When they leave, they still should after 2 minutes see this companies ads, but after 2min 1sec no more. And I have difficulty hiding AdSense - it still show (not in the sidebar but) in footer and I don't know why...

So I have one situation - Normal where AdSense shows (without referral)

This is where all AdSense positions are showing for example this one:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Trendy Bydlení - Sidebar  -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="----"
     data-ad-slot="----"
     data-ad-format="auto"></ins>
<script>
if ( ads == 1 ) {
(adsbygoogle = window.adsbygoogle || []).push({});
}
</script>

And the second situation - Referral where my ads partner shows (with referral)

For this, I have in header.php

<script src="//i.imedia.cz/js/im3light.js"></script>
<script> var pozice = [{id:"leaderboard", zoneId: "external.test.leaderboard"},{id:"skystraper", zoneId: "external.test.skyscraper"}, {id:"square", zoneId: "external.test.smr"}];</script>
<script>
im.conf.server = "iimedia.sbeta.cz"; 

function getQueryVariable(variable)
{
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++)
  {
    var pair = vars[i].split("=");
    if (pair[0] == variable)
    {
      return pair[1];
    }
  }
  return -1; //not found
}

if ( getQueryVariable('utm_source') == 'www.seznam.cz' )
{
   im.getAds(pozice);
   var ads = 1;
} else
{
    var ads = 0;
}
</script>

And than I show the ad simply like this:
<div id="skystraper"></div>

When accessing site without referral, everything is fine but with the second situation AdSense are still showing and weirdly displaying in footer. Was anybody solving similar problem?

First situation - fine
http://imgur.com/a/wDvWB

Second situation - wrong
http://imgur.com/a/pbt18