Hello,

As a practice for better performance, ads should be loaded only when everything else is rendered. This patch move GA_googleFillSlot() to just before closing tag. Performance is improve, because banners are loaded after other elements.

Two problems, still:
- No admin option yet, but there is a define('GAM_LAZY', true); at the beginning so that you can easily turn it on/off.
- Move other Javascript to the bottom. I don't have time to do it now, but just the fillslot that already makes a big performance gain (particularly when Google CDN is far from you).

CommentFileSizeAuthor
#8 gam-765802.patch3.03 KBjcisio
#2 gam-765802-3.patch2.96 KBjcisio
gam-lazy.patch2.21 KBjcisio

Comments

toemaz’s picture

Status: Needs review » Needs work

Thanks for the patch. Just a note regarding: $(document).ready(function() ... It has been deprecated. Instead we should use Drupal.behaviors.

If you can update the patch, I will be glad to commit it.

jcisio’s picture

Status: Needs work » Needs review
StatusFileSize
new2.96 KB

OK new patch to use Drupal.behaviors. I moved all scripts to the bottom, too.

Still, a few shortcomings:

- When DOM not ready, ads display at the bottom for a very short moment. I don't use a wrapper with display:none or move out of viewport because it seems that iframe will reload when it is turned on/attached to another element. My actual solution is move a displayed banner from the bottom to the correct position.

- Normally, drupal_add_js doesn't work on hook_footer. I don't know why it works here. Maybe move it to hook_init to be sure.

- Last but not least, with this patch, the default behavior is changed: script is inserted at the bottom by default. If it is good or not, I leave it for the maintainer to decide ;)

jcisio’s picture

Just a notice, there is incoherent usage of ga_ and gam_ prefixes in the patch. I prefer gam_ because that what Google is using, and ga_ is for "Google Adsense".

iamer’s picture

When I tried this patch, all the ads were clumped up together at the top of the page.

jcisio’s picture

Status: Needs review » Active

I'm not sure, but it works well here http://www.thongtincongnghe.com/
I don't have time to test now, but maybe it's a css position problem in theme.

iamer’s picture

You're probably right, I'll look at it and report back.

jcisio’s picture

It seems that I've found the problem. If the ad divs is positionned by CSS, and the CSS has not completed loaded on domready, those positions are wrong and cause the problem.

Solution could be fix the position again after onload event.

jcisio’s picture

StatusFileSize
new3.03 KB

New patch. Attach on onload event, too. Fixed problem with admin_menu, and may fix #4. Please test ;)

kmonty’s picture

Why have the return ' '; line? Why not just do a return;?

jcisio’s picture

If a block is empty, Drupal won't render it and we won't have the placeholder that we want.

Funkymoses’s picture

subscribing; apologies for not having anything useful to say.

jcisio’s picture

Status: Active » Needs review

At least there is a patch to test. Changing the status.

Exploratus’s picture

subscribe.... This is very important for page loadtime. ill test.

jcisio’s picture

Yes please test and report. As I'm not sure if it works for most websites.

Exploratus’s picture

Doesnt seem to work. Dont know why. it moves the ads all around...

jcisio’s picture

Provide more info with any detail. If not I can't get it done.

Exploratus’s picture

The ads appeared in the bottom left corner of my screen, the css settings I had setup for Google Ad Manager where no longer working when I used the patch.

jcisio’s picture

That behavior means that there is some conflict with the other Javascript in the webpage. Did you see any error?

About the css, that's because you set some rule on code generated by GAM. I advise you set stylesheet only on the block container (the <div class="block">...</div>), because its content is expected to have no stylesheet at all, with the size that is exactly the same as banner size.

jcisio’s picture

Status: Needs review » Fixed

Tested in two sites with different themes without problem. Committed a modified patch for broader testing. This feature is disabled by default.

Reopen if have any problem.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.