1. 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

Discussion in 'Styling and Customization Questions' started by MrDeranged, Dec 16, 2013.

  1. MrDeranged

    MrDeranged Well-Known Member

    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
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    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>
     
  3. MrDeranged

    MrDeranged Well-Known Member

    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.... ;)
     
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    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)
    
     
  5. MrDeranged

    MrDeranged Well-Known Member

    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 &?
     
  6. Jeremy

    Jeremy XenForo Moderator Staff Member

    I'm not sure what you mean by taking the sidebar into effect.
     
  7. MrDeranged

    MrDeranged Well-Known Member

    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
     
  8. Jeremy

    Jeremy XenForo Moderator Staff Member

    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?
     
  9. MrDeranged

    MrDeranged Well-Known Member

    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
     
  10. Jeremy

    Jeremy XenForo Moderator Staff Member

    Change your width:
    Code:
    width = document.documentElement.clientWidth - 10 - INSERT SIDEBAR WIDTH;
    
    Replace INSERT SIDEBAR WIDTH with the width of your sidebar.
     
  11. MrDeranged

    MrDeranged Well-Known Member

    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?
     
  12. Jeremy

    Jeremy XenForo Moderator Staff Member

    It will always assume. Is this displayed on every page?
     
  13. MrDeranged

    MrDeranged Well-Known Member

    Yes, I'm using the "ad_below_top_breadcrumb" template
     
  14. Jeremy

    Jeremy XenForo Moderator Staff Member

    Change your width line to this:
    Code:
    var $sidebar = $('.sidebar')
      , offset = 0;
    
    if ($sidebar.length) {
      offset = $sidebar.width() + 10;
    }
    
    width = document.documentElement.clientWidth - offset;
     
  15. MrDeranged

    MrDeranged Well-Known Member

    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
     
  16. Jeremy

    Jeremy XenForo Moderator Staff Member

    The width may still be above 744. You will most likely want to change your width to be the width of the content container.
     
  17. MrDeranged

    MrDeranged Well-Known Member

    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 :)
     

Share This Page