Forum Moderators: martinibuster

Message Too Old, No Replies

How to Lazy Load Adsense?

Checking for possible ways to lazyload adsense?

         

Niresh12495

7:54 pm on Jan 12, 2021 (gmt 0)

10+ Year Member Top Contributors Of The Month



Is there any possible ways to lazyload adsense?
Is there any consequence by lazyloading adsense?

This doesn’t work properly, it loads ads in wrong order.
[css-tricks.com...]

[edited by: martinibuster at 6:43 pm (utc) on Feb 8, 2021]

JorgeV

10:24 am on Feb 8, 2021 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



Hello,

There is no real lazy loading of Adsense ads. However, there may be a trick, check about using adsense and infinite scroll page, you might be able to adapt it for your page.

Adsense ads are already loading asynchronously, isn't it enough ?

Nothing happens , until you page calls the adsbygoogle.js script.call, so you can work around this. Like for example, calling the script only at the end of your page, or once your most important resources are loaded. etc...

NickMNS

2:34 pm on Feb 8, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is there any possible ways to lazyload adsense?

Yes

Is there any consequence by lazyloading adsense?

Possibly

This doesn’t work properly, it loads ads in wrong order

I wouldn't use that script, it appears too complex for its purpose, and it appears to reload ads when the user switches between landscape and portrait. I would be very concerned that this would cause invalid impressions and potentially get your account banned.

This not lazyloading, This is defer loading.

Using defer is similar to async. Adsense ads are already using async. The difference is that with async the script will not block the main thread as the js ad-code is downloaded, so your page elements will continue to be rendered. But, once the ad-code is fully loaded, script execution will be added to the queue and the ad will be rendered next. In the case of defer, it will be similar in terms of downloading, it wont block the thread, but the downloaded script will only be executed once all the other scripts have completed.

How big a difference this will make will depends on how big your page and how long the download is. For a short download and big page the difference can be sizable.

The problem is that delaying the script execution of an above the fold ad can be problematic, as the ad code will be executed but due to the delayed loading the ad may never be seen as the user will scroll past it.

Using lazy loading or defer may be effective at speeding up page load time metrics but it will come at the very big cost of reducing visible impressions which will lead to fewer clicks and less money per click. If page speed is the only reason for doing this I would recommend against it.

However, lazy loading is beneficial in the case when you have a very long page and when users will not always scroll down to the end of the page. In that case loading ads that will never be seen is bad, it negatively impacts AVV (active view viewable). So lazy loading after some scroll point makes sense, it is not likely to make you get more clicks, but you should earn more per click/impression due to a higher AVV.

No5needinput

3:39 pm on Feb 8, 2021 (gmt 0)

10+ Year Member Top Contributors Of The Month



This idea from one of my previous posts may help...

When I had to DELAY ad loading due to Adsense not reading responsive div size until page had loaded (Error: No slot size for availableWidth=0)

On each ad unit I changed:

(adsbygoogle = window.adsbygoogle || []).push({});


To

setTimeout(function(){(adsbygoogle = window.adsbygoogle || []).push({})}, 1000);


*Set 1000 to whatever delay

From topic at: [webmasterworld.com ]

NickMNS

3:54 pm on Feb 8, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@No5needinput
The solution for this error:
(Error: No slot size for availableWidth=0)

Is to set a width on the parent div of the ad-code, something like width:300 or 320px. Then the attribute:
data-full-width-responsive="true"

will force the add to expand to full width. The attribute is defaults to true when not present. This will eliminate the need for the 1 second delay and may improve ad performance.

martinibuster

6:45 pm on Feb 8, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



On each ad unit I changed:


Changing the code in the Google AdSense ad unit is against Google's terms, as I understand it.

Nick's solution is better because it does not fiddle with the ad unit code.

levo

7:25 pm on Feb 8, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I haven't tried it, but you can use Ad Manager's Lazy Loading with Adsense fallback.

[developers.google.com...]

Niresh12495

4:17 pm on Feb 28, 2021 (gmt 0)

10+ Year Member Top Contributors Of The Month



I know about GPT Tags, but i want to load adsense, No one has listed any working lazy load solution above, all are defer load.

guarriman3

12:29 pm on Mar 2, 2021 (gmt 0)

10+ Year Member Top Contributors Of The Month



On the mobile pages, I started to use a code similar to this one


This is, on the mobile pages the 'adsbygoogle.js' is inserted (parentNode.insertBefore) just when the users start to scroll down.

And, instead of pushing the ads in the regular way proposed by Google, I use the the SetTimeout proposed by @No5needinput, in order to break down the JavaScript long tasks. I use also 1000 miliseconds.

@NickMNS
The problem is that delaying the script execution of an above the fold ad can be problematic, as the ad code will be executed but due to the delayed loading the ad may never be seen as the user will scroll past it.

Yep, this is the main issue. I've seen how my pagespeed improved (100% in all the pages) but the AVV metrics and the incomes dropped. My users have no time to see the the mobile ads placed on the top of the mobile pages, because such ads take 1-2 seconds to be viewable.

[edited by: martinibuster at 11:19 am (utc) on Mar 14, 2021]
[edit reason] Pls don't make people read an entire web page. Just describe the code. Thx [/edit]

Niresh12495

4:41 am on Mar 3, 2021 (gmt 0)

10+ Year Member Top Contributors Of The Month



Yes, Defer loading is not a solution. I have two solutions, I'll be posting Git Project here, When I'm done with Git.
Keep following.

guarriman3

8:22 am on Mar 3, 2021 (gmt 0)

10+ Year Member Top Contributors Of The Month



I'll be posting Git Project here, When I'm done with Git.

I would be very grateful if you could do it, please. I also did some tests with 'IntersectionObserver', pushing the AdSense unit 300px before the user sees the div including such unit.

However, I'm not sure that my users are fully capable of seeing the units, and I suspect that the push+load of the AdSense units take longer than the time the users scroll over the reserved space.

Niresh12495

9:39 am on Mar 3, 2021 (gmt 0)

10+ Year Member Top Contributors Of The Month



Push+load doesn’t take much time. But you might need to increase the threshold.
Are you able to push adunits in order?

Here adunits does not load in order.

If you don’t mind could you share the java script that you try or use.

[edited by: martinibuster at 11:21 am (utc) on Mar 14, 2021]
[edit reason] Link isn't necessary to this discussion. [/edit]

usaidr

6:04 pm on Mar 2, 2021 (gmt 0)




System: The following 3 messages were spliced on to this thread from: https://www.webmasterworld.com/google_adsense/5028834.htm [webmasterworld.com] by martinibuster - 8:26 am on Mar 3, 2021 (utc -5)


So I want to lazy load ads to improve my site performance. I tried but ads are not appearing. I must be doing some mistake.

<div id="div-2" class="ad-slot" style="height: 90px; width: 728px;">
<script> googletag.cmd.push(function() { googletag.display('div-2'); }); </script> </div>.


Kindly Guide Me. Would Really Help Me. THANKS!

[edited by: martinibuster at 8:17 am (utc) on Mar 3, 2021]
[edit reason] Removed AS code. [/edit]

martinibuster

8:26 am on Mar 3, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Lazy loading the ads might violate the terms and conditions where it's against the rules to change how the ads are delivered. The ads are delivered asynchronously. Lazy loading the div element that contains the ad may change how those ads are loading, imo.

usaidr

1:11 pm on Mar 3, 2021 (gmt 0)



@martinibuster Well I am using Google's own given method [developers.google.com...]

Niresh12495

5:26 am on Mar 4, 2021 (gmt 0)

10+ Year Member Top Contributors Of The Month



This solution is for GPT, but most people still ends with adsense alone.

```
googletag.pubads().enableLazyLoad({
fetchMarginPercent: 500,
renderMarginPercent: 200,
mobileScaling: 2.0
});
```

guarriman3

3:15 pm on Mar 4, 2021 (gmt 0)

10+ Year Member Top Contributors Of The Month




Lazy loading the ads might violate the terms and conditions where it's against the rules to change how the ads are delivered. The ads are delivered asynchronously. Lazy loading the div element that contains the ad may change how those ads are loading, imo.


Yes, I had such fears, but after reading some blogs, forums, etc., I consider that Google does not mind that your separate the three parts of the code (the load of the JS library hosted in Google's servers, the 'ins' element with the parameters, and the push function).

We do not modify the original code, but we wrap it with extra code trying to optimize the user experience, by speeding up the load of the pages. In fact, we do reduce the AdSense incomes so that users can see faster the information of our pages.

Having said that, I miss information from Google trying to help us, small publishers, with this issue. I receive tons of mails from Google, and none of them explaining explicitly how to fix it. We are forced to show fast pages for SEO, and 100% of my PageSpeed issues (CLS included) are due to the load of Adsense ads.

These days I've read in this wonderful forum that Google Ad Manager may be the solution for the lazy load for my Adsense units.

I've just checked my inbox and since 2003 (yes, I use AdSense from the very first day) and I haven't received any email saying "hey, why are you not using Google Ad Manager?"

I am a real Google fan. I manage personally a very old website and I'm focused just on generating useful information for users, without cheating Google. I insert only ads from Adsense, and I receive dozens of emails inviting me to test other networks.

If I'm told to improve my PageSpeed score, I stop to generate useful information for users and I waste hours learning to break down javaScript long tasks. Whatever for my loving Google.

But, please Google, provide us some further help/tools to small publishers who can not spend too much time testing code.

allhearts

11:55 am on Sep 12, 2021 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



it would be nice to get some clarification from google but good luck.

I don’t know what to do as well, my pages have a horrible rating as well.


Thank you.