RationalSpace

Archive for the ‘Google’ Category

Remove Duplicate link of Amazon Cloud Services

leave a comment »

Duplicate link remove of Amazon Cloud Services

You just migrated your website to Amazon Cloud and found that a whole set of URLs with AWS IP are getting crawled by Google ? Here is a guide to resolve this issue. This issue can be quite harmful for your site’s SEO as it will lead to duplicate content being indexed by Google!

Advertisements

Written by rationalspace

May 5, 2014 at 12:45 pm

Handling Google Adsense in responsive design

leave a comment »

We were on the verge of launching a responsive design for our website when it suddenly occurred to me – What about ads? How would Google ads show up in mobile ?

Unfortunately, Google does not offer a way to handle this. Ideally their code should automatically detect the size of the device and render ads appropriately.

The way you would implement a responsive design is by hiding the parts of the website/content that you don’t want to show in mobile.  i.e display:none.We could do this but this is obviously not a good approach as the call to the ads would still be made! So this will mean that we are not only making extra un-necessary calls to google but also violating Google Adsense policies. Even if the div containing the ad unit is hidden, the Javascript is still executed and the ad is still rendered – counting as an impression for the advertiser.

We resolved this issue by dynamically calculating window size and rendering the code to write javascript.
Here is a code sample:

  <script type="text/javascript">      
        adWidth = window.innerWidth;
        if(adWidth>=728){
                document.write('<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px;" data-ad-client="ca-pub-xxxxx" data-ad-slot="yyyyyyyy"></ins>');
        }
        
</script>
<script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>

(adsbygoogle = window.adsbygoogle || []).push({});

This code will not show the ads if the width is less than 728px. You can modify this to show smaller ads in smaller widths also 🙂

Written by rationalspace

October 7, 2013 at 2:54 pm

Posted in Google

Google Adsense Asynchronous Ads

leave a comment »

Javascripts are render-blocking elements of the html.
This means that whenever you put a code to fetch a javascript file: something like

<script type='text/javascript' src='http://myhome.com/myjs.js'></script>

the browser waits to load the javascript file and then executes the rest of the code below this.

Now this can be quite a bad experience if you are loading google ads at multiple places in your website.
Most of the times,we have the google ad placed in the header itself. So before the user can see your website content, the ad renders. Wouldn’t it be great if one can load the ads asynchronously after the rest of the html has loaded?

Fortunately, yes we can do that now.

Google has given an option to fetch ads asynchronously, though they say that their code is in Beta version:)

<!-- box-home page -->
<ins class="adsbygoogle" style="display:inline-block;width:300px;height:250px;" data-ad-client="ca-pub-xxxxxxxx" data-ad-slot="xxxxxxxx"></ins>
<script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

This works perfectly. By this method, your entire page gets loaded first and then ads get called. Helps performance and good for a user too!

Written by rationalspace

October 7, 2013 at 9:59 am

Posted in Google, Performance

%d bloggers like this: