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:

Before:

<script type="text/javascript">
    google_ad_client = "ca-pub-xxxxxxxxxxxxxxxx";
    google_ad_slot = "1234567890";
    google_ad_width = 728;
    google_ad_height = 90;
</script>
<!-- leaderboard -->
<script type="text/javascript"
src="//pagead2.googlesyndication.com/
pagead/show_ads.js">
</script>

After:

 
<script async src="//pagead2.googlesyndication.com/
pagead/js/adsbygoogle.js"></script>
<!-- leaderboard -->
<ins class="adsbygoogle"
    style="display:inline-block;width:728px;height:90px"
    data-ad-client="ca-pub-xxxxxxxxxxxxxxxx"
    data-ad-slot="1234567890"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

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

For Google Analytic :

Change to:

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

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

Nice !!

Reference:
1. Adsense Support
2. Google Analytic