View Full Version : Adsense in Sencha Touch

26 Oct 2011, 1:45 AM
Okay, I've (http://www.sencha.com/forum/showthread.php?128915-sencha-touch-and-google-adsense) seen (http://www.sencha.com/forum/showthread.php?123230-Adsense) multiple (http://www.sencha.com/forum/showthread.php?131135-Adsense) threads on this subject, though none have claimed a solution. Some have tossed ideas around, some have not had any response at all, but none have actually claimed anything worked. I've tried to roll my own using a more direct approach to the problem (http://www.sencha.com/forum/showthread.php?31983-autoLoad-and-external-javascript), but no dice there either.

Bottom line, I'm looking to bottom dock a Panel and put adsense in it. Adsense's code is basically just HTML, but it's specifically an inline <script> and a <script src='foo'>, and neither seem to play nice the old-fashioned way.

The only other possibility I'm seeing is to iframe it, which is specifically against Google's terms of use.

At this point, I'm bypassing Adsense altogether. I'm just trying to get an external JS file that only calls alert() to fire. I understand that Sencha Touch provides a means to call script logic so an alert() is better done elsewhere. Given the nature of what I'm really trying to do, it's going to have to be script tags to be a viable option... Ideas?

28 Oct 2011, 8:24 AM
The only other possibility I'm seeing is to iframe it, which is specifically against Google's terms of use.

I've seen mention that Google allows exceptions to this policy with specific authorization from Google. So, I requested that authorization. Just heard back. Denied.

We received your request to iframe ads on your website. We carefully reviewed your request and are unable to approve your request. Please know that placing ad code directly into the source of your page improves ad targeting. You may notice over time that your ad performance will improve leading to an increase in revenue. If you have further questions, please let us know.

Insert surprise here.

22 Nov 2011, 4:32 PM
Hey I found an easy way to do it - you put the two script elements given by Adsense inside a couple of divs, then you create docked component that makes the inner div (ie. the Ad container) it's own content using contentEl property.
Outer div is there just to initially hide the ad.

In index.html you put this inside the body element:

<div id="hidden" style="display:none">
<div id="adsense">
<script type="text/javascript">
window.googleAfmcRequest = {
client: 'XX-XX-XXXXXXXXX',
format: '320x50_mb',
output: 'html',
slotname: '1232435435',
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_afmc_ads.js"></script>

Then in your sencha code you define you docked component

dockedItems : [
xtype: 'component',
contentEl : 'adsense',
dock : 'bottom',
height: 50

26 May 2012, 12:13 PM
Just perfect solution, great!

30 Apr 2013, 12:38 AM
I also solved this problem by using contentEl, but it works only for few ads. How can I have more than 4 ads in Sencha touch app?