S
S
Senseich2018-08-21 17:45:18
JavaScript
Senseich, 2018-08-21 17:45:18

How does the Google Adsense advertising code work?

Hello! I have a question, probably more technical. For Google Adsense, each ad unit looks something like this:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
         style="display:block"
         data-ad-format="autorelaxed"
         data-ad-client="ca-pub-1271381194193378"
         data-ad-slot="3961443235">
</ins>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({});
</script>

I have such blocks, for example, on the page three. I decided to move the repeating code down before the closing tag </body>. Those. this part:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({});
</script>

But bad luck, only the first advertisement began to load.
After experimenting, I realized that the point is in this line (adsbygoogle = window.adsbygoogle || []).push({});, there should be as many of them as ad units. From here the question is whether it is possible to write like this, is it correct:
<script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    (adsbygoogle = window.adsbygoogle || []).push({});
    (adsbygoogle = window.adsbygoogle || []).push({});
</script>

If we take a more global approach to the issue, then I want to somehow optimize the loading of blocks so that the pages load faster. Perhaps you can make the blocks load after loading the page content itself?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question