Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put Google Adsense in GWT

Tags:

java

adsense

gwt

Do anyone know how to put Google adsense ads inside a GWT web application?

like image 281
Thiago Diniz Avatar asked Feb 11 '09 20:02

Thiago Diniz


2 Answers

You can put the javascript-code from Adsense in the single HTML page that GWT starts with. This way the advertising will not be displayed in the same area as GTW but above/below the GWT code. For advertising that could be ok.

This example places a baner above the application:

  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>www.javaoracleblog.com</title>
    <script type="text/javascript" language="javascript" src="com.javaoracleblog.aggregator.nocache.js"></script>
  </head>
  <body>
<script type="text/javascript"..
ADsense code here 
</script>
    <!-- OPTIONAL: include this if you want history support -->
    <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
  </body>
</html>

In order to indicate to Google WT that the site of Google adsense can be trusted you need to add a regex matching URL to the -whitelist command line argument.

Note that this will probably not solve the problems desribed in the above "Why I dumped GWT" article.

like image 187
Edwin Avatar answered Sep 17 '22 15:09

Edwin


According to this thread on AdSense:

Short version, you can't use Adsense via Ajax without breaking the programme policies/t&c's

Long version...

Ad code passed through an xmlhttp call is not rendered, it's just treated as text (hence, responseText). The only way to execute js code is to use "responseXML" coupled with the "exec()" command.

For instance...

If your xml contains something along the lines of:

This is the content from the external file javascript code goes here

You would assign a variable (called page_data for instance) using ajax_obj.responseXML, run the XML through a parser and run

exec(js variable or line from XML here);

Not really helpful from an Adsense standpoint, but that's how it's done.

It's also worth mentioning Why I dumped GWT:

Another problem were my adsense banners. Since I didn’t have a lot of content on the page, the banners were sometimes off topic. An even bigger problem was that the banners stayed the same when people searched for different keywords (since the ajax refresh didn’t trigger an adsense refresh). I solved this by doing the search with a page refresh instead of an ajax call. The ajax part of the site was limited to sorting, faceting, i18n and displaying tips.

like image 20
cletus Avatar answered Sep 19 '22 15:09

cletus