• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.2 Ad Serving Help

MrDeranged

Well-known member
#1
Hey All,

Not even sure if what I'm trying to do is possible. I'd just like to know if it is and if I'm on the right track to do so.

I use openx to serve my ads. I've created 3 zones, 728x90, 468x60 and 320x50.

There are invocation codes for each zone. I'm hoping that I'll be able to call the invocation code based on client width. below is the code that I have in the ad template. Not sure if this is even possible.....

<xen:hook name="ad_below_top_breadcrumb" />

<script type="text/javascript">
width = document.documentElement.clientWidth;
if (width > 744) {

<script type='text/javascript'><!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://****/****/****/****/ajs.php':'http://****/****/****/****/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=12");
document.write ('&amp;cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
document.write ("&amp;loc=" + escape(window.location));
if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>--></script><noscript><a href='http://****/****/****/****/ck.php?n=aef55404&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://****/****/****/****/avw.php?zoneid=12&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=aef55404' border='0' alt='' /></a></noscript>
}

if (width > 484) {

<script type='text/javascript'><!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://****/****/****/****/ajs.php':'http://****/****/****/****/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=13");
document.write ('&amp;cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
document.write ("&amp;loc=" + escape(window.location));
if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>--></script><noscript><a href='http://****/****/****/****/ck.php?n=ac818485&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://****/****/****/****/avw.php?zoneid=13&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=ac818485' border='0' alt='' /></a></noscript>
}

if (width < 484) {

<script type='text/javascript'><!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://****/****/****/****/ajs.php':'http://****/****/****/****/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=14");
document.write ('&amp;cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
document.write ("&amp;loc=" + escape(window.location));
if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>--></script><noscript><a href='http://****/****/****/****/ck.php?n=a0d43933&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://****/****/****/****/avw.php?zoneid=14&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=a0d43933' border='0' alt='' /></a></noscript>
}

</script>


What I'm getting is this:

upload_2013-12-15_22-38-30.png


Any help greatly appreciated!!!

Thanks
 

Jeremy

Well-known member
#2
Remove all instances of:
Code:
<script type='text/javascript'>
and
Code:
</script>
After you do that, place the opening script tag (that I told you to take out) right after the opening <xen:hook>. And place the closing script tag right before the closing </xen:hook>
 

MrDeranged

Well-known member
#3
Thank you very much Jeremy!!!

Did what you said. Now instead of the 468 and the 320, I'm getting the 728 and the 468. So there's definitely progress :)

The whole problem is that I just want one banner to show up. I'm guessing both are showing up because both meet the requirements.

Any idea on how to just have one show up at a time?

I'm guessing it's some kind of if/then thing, but my coding knowledge could probably maybe fill a very very small thimble.... ;)
 

Jeremy

Well-known member
#4
Well, the first two conditions are both true if you are above 744. You'd want to change the second one to be:

Code:
if (width < 744 && width > 484)
 

MrDeranged

Well-known member
#5
That fixed that :)

Sorry for all the questions. Hopefully this will be the last one though :)

The 728 banner doesn't seem to be taking the sidebar into account. Is it possible to get that taken into consideration?

Thank you again for all the help :)

Also, to help try and increase my coding knowledge, is there a reason for the double &?
 

MrDeranged

Well-known member
#7
if I resize my window so that it would step down to the 468 banner, it's not taking the sidebar into account. meaning the sidebar is covering the 768 banner

upload_2013-12-16_0-0-37.png
 

Jeremy

Well-known member
#8
The code you have posted above doesn't take into account resizing of your browser. Is it permissible under the TOS of whatever ad server you are using to reload ads on the same page?
 

MrDeranged

Well-known member
#9
I'm not actually trying to get it to do it on the fly. I'm just trying to simulate different resolutions so that it will be "responsive" on page load so to speak. I hope that makes sense
 

Jeremy

Well-known member
#10
Change your width:
Code:
width = document.documentElement.clientWidth - 10 - INSERT SIDEBAR WIDTH;
Replace INSERT SIDEBAR WIDTH with the width of your sidebar.
 

MrDeranged

Well-known member
#11
by change my width, do you mean this line?

width = document.documentElement.clientWidth;

How do I find out my sidebar width?

Will that take into account whether or not the sidebar is currently showing or will it always assume that the sidebar is showing?
 

Jeremy

Well-known member
#14
Change your width line to this:
Code:
var $sidebar = $('.sidebar')
  , offset = 0;

if ($sidebar.length) {
  offset = $sidebar.width() + 10;
}

width = document.documentElement.clientWidth - offset;
 

MrDeranged

Well-known member
#15
hmmm...

not sure if I did this right. Top of template now looks like this:

<xen:hook name="ad_below_top_breadcrumb" />
<script type="text/javascript">

var $sidebar = $('.sidebar')
, offset = 0;

if ($sidebar.length) {
offset = $sidebar.width() + 10;
}

width = document.documentElement.clientWidth - offset;
if (width > 744) {

Sidebar still covers up the 728 ad as opposed to sizing down to the 468
 

Jeremy

Well-known member
#16
The width may still be above 744. You will most likely want to change your width to be the width of the content container.
 

MrDeranged

Well-known member
#17
Could you kindly point me to where I can find out how to do so? I really only have very very limited coding experience as you might have figured out by now ;)

Thank you again for all your help :)