Home » Web Tutorials » Make Money » What is Ad Unit Code in Google AdSense?

What is Ad Unit Code in Google AdSense?

AdSense ad unit is a piece of script to be embedded in your webpage in order to display ads from Google. The script will be triggered when the page is loaded which will send an ad request to the nearest Google server located. Server will return appropriate ad based on ad auction and the script will then display the ads in the webpage. Each and every ad unit in a webpage sends an ad request which is recorded in your AdSense account as ad request count.

AdSense Ad Unit Code Example

AdSense offers responsive and fixed width ads. Responsive format will automatically adjust as per the viewport (browser’s width) and has the following script:

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7499xxxxxxxxxxxx"
     crossorigin="anonymous"></script>
<!-- Responsive Ad Unit Code -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-7499xxxxxxxxxxxx"
     data-ad-slot="7321xxxxxx"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

Fixed width ad unit will have a defined width and height dimensions instead of responsive parameters.

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7499xxxxxxxxxxxx"
     crossorigin="anonymous"></script>
<!-- Fixed Ad Unit Code -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-7499xxxxxxxxxxxx"
     data-ad-slot="7321xxxxxx"
     data-ad-width="300"
     data-ad-width="600"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

It is not recommended to use fixed ad dimensions as the ad will not automatically adjust its size. There are also possibilities not getting full impressions for fixed units due to insufficient inventory. You can generate responsive or fixed AdSense ad unit code from your AdSense account and embed it in your webpage to display ads. Learn more creating Ad units.

Various Terms Used in AdSense Ad Unit Code

Following is the explanation of the terms used in an AdSense ad script code.

  • Script – AdSense ad code is a server side JavaScript code embedded in any webpage. This script calls the nearest Google ad server through API in the background and retrieve the relevant ad to be displayed on the page.
  • Ad Client – This is the publisher’s AdSense id used to identify the corresponding AdSense account. In order to avoid misuse of the publisher code, Google introduced site approval concept where publishers need to get approval for each individual site where the account’s ad units are used.
  • Ad Slot – This is a slot number assigned automatically by Google in order to track any particular ad.
  • Width and Height – Determines the size of the ad to be displayed in a webpage. As mentioned, it will be auto for responsive ad unit.

Auto and Manual Ads

When you create multiple ad units in your account, you can notice that the first script line is same in all units. This pagead2.googlesyndication.com script was earlier called as page level ads which was subsequently renamed as auto ads. As the name indicated, you can simply insert this single script in header section of your webpage to show advertisements without using remaining part of the ad unit code. In that case, you need to enable auto ads in your AdSense account so that Google will automatically analyze your page layout and show relevant ads.

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7499xxxxxxxxxxxx"
     crossorigin="anonymous"></script>

When you want to manually insert multiple ad units on the same page, make sure to insert the header script between <head>……</head> section and then insert the remaining part of ad unit in a position where you want to to show the ad. You should insert the header script only once in a webpage to avoid duplication error.

You can combine auto ads and manual ads to maximize the earnings from your content.

Leave a Comment

Your email address will not be published. Required fields are marked *