XF 1.5 Non-responsive ads in Template

mypbaph

Member
sorry for the noob question, i want to place a non-responsive ad code in the 'ad_above_content' template. if user is viewing the forum thru desktop, a 728x90 ad unit will show up, if thru mobile a 300x250 ad will appear instead.

what conditional code should i use? thanks!
 

island

Active member
Curious what solution you chose mypbaph -- did you solve this?

Certain ad networks such as Amazon CPM ads don't provide responsive ad units yet, only standard sizes.

The ideal thing would be to have a way for xenforo to detect screen resolution at the template level and serve the 728 x 90 ad code for example to screens above x-pixels and show mobile banner code to screens below that resolution with an if / else statement. However, I don't think this is possible -- as I believe it was stated that xenforo / php doesn't receive the screen resolution before the page is rendered. Is that correct?

It's against the TOS I believe to hide any ad unit, so css can't be used to do an if / else to show a 728 x 90 or a mobile banner depending on screen resolution.

The amazon CPM code is javascript code. I wonder if the ideal solution would be to wrap another javascript around the code which checks screen resolution and then either does or does not call the amazon javascript cpm ad code?
 

island

Active member
Adding the code in blue seems to work in very limited testing, but I'm not clear if this would be against the TOS.

I wish there were a way to wrap the whole <script> ad code </script> in a container javascript if statement instead of having to insert the if statement so that if a scanner checked it, it would see that it's 100% unchanged. But I don't think there's a way to do that. If someone has done it, would be very interested.

<!DOCTYPE html>
<html>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
(jquery already loaded by xenforo -- only for test here)

<script type="text/javascript" language="javascript" src="//c.amazon-adsystem.com/aax2/getads.js"></script>
<script type="text/javascript" language="javascript">
if ( $(window).width() > 740 ) {
//<![CDATA[
aax_getad_mpb({
"slot_uuid":"1234567890"
});
//]]>
}
</script>
</body>
</html>

(or an else { } statement could be added, so desktop would have desktop ad
slot_uuid and mobile size screen would have mobile slot_uuid.)
 
Last edited:
Top