My website got loaded with google analytic and google ads javascript library hosted elsewhere in google server.
It will attempt to download and re-write some part of the content with the relevant ads. (yes, I got paid for that traffic . )

Recently with some optimisation done on the theme, it found out only the above javascript got WARNING, and it tried to perform document.write while the javascript file been deferred until all content being downloaded.

I was wondering how to make it work again.
Then I found this page at google support which provide guideline how to change it to async call instead of blocking call in previous version.

Here is how to do it.

For Google Ads:


<script type="text/javascript">
    google_ad_client = "ca-pub-xxxxxxxxxxxxxxxx";
    google_ad_slot = "1234567890";
    google_ad_width = 728;
    google_ad_height = 90;
<!-- leaderboard -->
<script type="text/javascript"


<script async src="//
<!-- leaderboard -->
<ins class="adsbygoogle"
(adsbygoogle = window.adsbygoogle || []).push({});

note : please edit the client-ad and slot id with yours.

For Google Analytic :

Change to:

<!-- Google Analytics -->
<script>||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
<script async src=''></script>
<!-- End Google Analytics -->

and that’s it, it is now being deferred and making async call while loading the ads content.

Nice !!

1. Adsense Support
2. Google Analytic