phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

Trouble using Google new asynchronous Adsense code? Fix here


 
Search this topic... | Search phpBB2 Discussion... | Search Box
Register or Login to Post    Index » phpBB2 Discussion  Previous TopicPrint TopicNext Topic
Author Message
JLA
Board Member



Joined: 30 Apr 2009

Posts: 451
Location: U.S.A


flag
PostPosted: Wed Feb 26, 2014 12:39 pm 
Post subject: Trouble using Google new asynchronous Adsense code? Fix here

Just giving back a little here.... As we've posted here http://www.jlaforums.com/viewtopic.php?t=252089240

Noticed recently that Google Adsense changed the default for their ad units to put out the new asynchronous code which is supposed to improve page load times.

Typically (the easiest way) when a PHPBB board wants to use adsense, the ad unit code is inserted in the appropriate template file for the page where you wish to display the ad unit. Using the old synchronous code - it was straight forward and works without issue

Example:

You want to display the ad at the top of your viewtopic page just below the header:

Open /templates/yourtemplate/viewtopicbody.tpl and insert the synchronous ad unit code into the appropriate spot where you want to display the ad unit.

With the new asynchronous ad unit code there is a problem and it is not so easy. To start you have to take a look at a key line in the new asynchronous ad unit code

Code:

<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>


The key item to see here is the "({})" The asynchronous tags need to push into an empty array to work. When you place the asynchronous ad unit code into your phpbb template file as described above, the "{}" characters will be stripped out and look like this

Code:
<script>
(adsbygoogle = window.adsbygoogle || []).push();
</script>


which will cause the ad unit to not display.

There is one fix for this if you want the asynchronous ad unit code to work with your phpbb.


Example - you want to display an adsense asynchronous ad unit code on the view topic page.

In your /viewtopic.php file find "$template->assign_vars(array(" and just BEFORE put something like

Code:
$adsenseadunit1 = 'your adsense asynchronous ad unit code';


then after "$template->assign_vars(array(" put something like

Code:
'ADSENSEADUNIT1'             => $adsenseadunit1,


then in your /templates/yourtemplate/viewtopicbody.tpl put something like

Code:
{ADSENSEADUNIT1}


where you want the asynchronous ad unit code to be displayed. Doing it this way will keep the "{}" characters from being stripped out of the ad unit code.

Hope this helps anyone who might encounter or has encountered the issue.

_________________
http://www.jlaforums.com
Back to top
Display posts from previous:   
Register or Login to Post    Index » phpBB2 Discussion  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT - 4 Hours
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0615 seconds using 17 queries. (SQL 0.0217 Parse 0.0004 Other 0.0394)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo