To add Adsense ads to this template, you don't need to edit the HTML code of your template because the 'Layout' menu has provided slots for placing ad units, some of which are billboard ads on the home page, sidebar ads, middle / top / bottom article ads, matched content ads and several other ad slots.
Activate the default Google Adsense script template
For those of you who already have an adsense account or who have just registered and want to display ad units in this template, the first step that needs to be done is to simply activate the adsense script <script src = '... adsbygoogle.js' /> which is already installed in the template this.
In the HTML template box, please scroll to the bottom, you will find an adsense script that is closed with a comment tag as below:
<!-- <script>/*<![CDATA[*/ (function() { var ad = document.createElement('script'); ad.async = true; ad.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'; var sc = document.getElementsByTagName('head')[0]; sc.parentNode.insertBefore(ad, sc); })(); /*]]>*/</script> -->
Ubah atau hilangkan tag comment pada kode diatas hingga menjadi seperti dibawah ini
<script>/*<![CDATA[*/ (function() { var ad = document.createElement('script'); ad.async = true; ad.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'; var sc = document.getElementsByTagName('head')[0]; sc.parentNode.insertBefore(ad, sc); })(); /*]]>*/</script>The script above is useful for giving async commands to the browser, meaning the adsense ad script will be loaded after the html page has finished loading perfectly.
What if I want to add autoads?
You can add the auto ads code by modifying the script above a little, please replace the script above with the script code below. Don't forget to add your adsense ID to the marked section:
<script>/*<![CDATA[*/ (function() { var add = document.createElement('script'); var att = document.createAttribute('data-ad-client'); att.value = 'ca-pub-0000000000000000'; add.setAttributeNode(att); add.async = true; add.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'; var sc = document.getElementsByTagName('head')[0]; sc.parentNode.insertBefore(add, sc); })(); /*]]>*/</script>What if I want to use lazy adsense?
previously we informed that this method is not recommended because it can reduce the pageview and CPC of your adsense ads. Unlike the async command , the lazy way adssense works is by loading the ad script when the user scrolls the blog page, so the first time when the page is finished loading the adsense ad will not appear. For those of you who still want to try it, you can change the adsense script at the first point to be like this:
<script>/*<![CDATA[*/ var lazyadsense = false; window.addEventListener("scroll", function(){ if ((document.documentElement.scrollTop != 0 && lazyadsense === false) || (document.body.scrollTop != 0 && lazyadsense === false)) { (function() { var ad = document.createElement('script'); ad.async = true; ad.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'; var sc = document.getElementsByTagName('head')[0]; sc.parentNode.insertBefore(ad, sc); })(); lazyadsense = true; } }, true) /*]]>*/</script>Writing recommended adsense ad units
One of the causes of slow loading blogs is due to repeated writing of the adsense script ( adsbygoogle.js ). Correct writing is enough for one adsbygoogle.js script that is placed in the <head> section , so every additional ad unit you don't need to rewrite the adsense script like the example below:
<ins class='adsbygoogle' data-ad-client='ca-pub-xxxxxxxxxxxxxxxx' data-ad-format='link' data-ad-slot='xxxxxxxxxx' data-full-width-responsive='false'/>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>Change ad unit to 'Horizontal'
Maybe many don't know that we can determine the shape or size of the adsense ad unit through the data-ad-format = '...' attribute , the Horizontal that is meant in the title is to change / display the shape of the ad unit into a rectangle and will not displays ad units in other forms such as square boxes. Maybe the desktop version will not see the difference, but it will be very visible in the mobile version.
To try the implementation, please change the data-ad-format = '...' attribute in the <ins> tag in your ad unit, for example as below:
<ins class='adsbygoogle' data-ad-client='ca-pub-xxxxxxxxxxxxxxxx' data-ad-format='horizontal' data-ad-slot='xxxxxxxxxx' data-full-width-responsive='false'/>You can see the full explanation in this article: How to use responsive ad tag parameters
Enable the Google Analytics script
Like the adsense code, the google analtytics code is also available on this template, it's just not yet active or still closed with a comment tag. Please find the code and delete the comment tag as shown below:
<!--<b:include name='post-analytics'/>-->
Hapus tag comment sehingga menjadi seperti dibawah ini:
<b:include name='post-analytics'/>don't forget to add Google Analytics ID in your blogger settings

0 Comments