0

How can I force an advertisement to show on an ajax-loaded page? Because, as you may know, document.write(); used by AdSense is skipped in asynchronous requests.

I NEED to force that ad to be shown. I also searched on google help forum but with no luck. I found only this but that doesn't tell me anything (it's discontinued).

Note: I also found this topic but I'm not about to refresh these adverts, JUST to show them ! Tried if ($('#advert')){ eval($('#advert')); } before, does not work

Is that possible? Is there some workaround?

Community
  • 1
  • 1
genesis
  • 50,477
  • 20
  • 96
  • 125
  • i dont quite understand what you need. is the advert supposed injected into the page after page load? is it built-in the initial page load? – Rafael Herscovici Jun 18 '11 at 07:44
  • after ajax page load, yes. Problm is that browser does ignore document.write() in asynchronous request (look at firebug console and go to any ajax document.write() including page) – genesis Jun 18 '11 at 07:50
  • 1
    i didnt downvote this question, but i think its because of the "cheat", maybe a google employee visits SO :-/ – Rafael Herscovici Jun 25 '11 at 09:47

3 Answers3

10

Sorry, but I think that way of showing AdSense violates Google's TOS. So even if you manage to do that, expect your account to be suspended some time later.

Edit:

Reference: it is already in the other answers https://www.google.com/adsense/localized-terms

Moreover, some time ago I tried to use ajax loaded page to show adsense and indeed they stopped the account. I also tried Iframe and again the account was suspended. Google don't give a *** until you start gaining $$$. So each time it took a while to suspend them. But thrust me they check each site manually at regular basis. So everytime I had to write many letters to google support to restore my accounts and it took a month to restore it and not before I fix the ads. I hate to be dark prophet, but I am pretty sure you will end like me if you mess with google's TOS. My personal advise is to revise your strategy.

I actually may go further and tell you that adsense payment is not very strict, and when something is wrong it is never in your favor. Many colleagues complain about the same, like uncounted clicks, unprovoked account suspensions (usually with significant money to check out), I also have one account that was never able to verify the address, because they don't send me the postcard and I made several requests and waited 2 months each time (for postal delays) and of course I have $$$'s to check out. So mate, don't try to cheat google, because more likely they will cheat you.

This is only my personal view and may contain some strong words that I'm not going to prove, because I'm not trying to start a discussion or accuse anyone.

Edit 2: I also can tell you why google do not allow asynchronous display of ads. Because you can manipulate the context (e.g. put hidden texts) and display non-relevant ads to your page, you can make google show only expensive ads which usually pay $1 per click (well google takes $4+ to the advertiser) and your context may only show $0.05 ads. Other way you could cheat is to simulate clicks or force the user click on ads.

venimus
  • 5,907
  • 2
  • 28
  • 38
  • 8
    I disagree. If you ask, "How can I set my hair on fire", then "Don't do that!" is a good response. Though it would be better if it provided references for why one should not want to do that. – Tamzin Blake Jun 24 '11 at 15:33
  • 4
    @Thom: Agreed. This is useful information relevant to the question. – Sinan Ünür Jun 24 '11 at 15:33
  • What I mean is at that you need to revise your strategy to avoid using what you are thinking you should and I think it is an answer, although it is not what you want to hear. – venimus Jun 24 '11 at 16:01
  • No, when I ask "How can I set my hair on fire", you should answer "You can use matches. BuT TAKE THIS SERIOUSLY: Do not do that!" - it's better answer with a tip – genesis Jun 24 '11 at 16:30
  • You are right, but your question is actually "How can I set my hair on fire under water", you could use matches, but while it is wrong from the start, at the end you will fail to complete your task. The problem mate is that google take great attention to cheating and they prefer to restrict the fair users but not let cheating. And TOS is not their only defence. Asynchronous loading of ads is almost impossible because google already restricted most of the ways because they know that nobody reads TOSes. – venimus Jun 24 '11 at 16:48
  • Okay. Thanks. But, could you tell me, how is it possible to "cheat google and show $1 add? Just theoretically" – genesis Jun 24 '11 at 20:26
  • well theoretically you could use an iframe for the ads and put some keywords in that iframe (as text) that match expensive ads. – venimus Jun 26 '11 at 17:14
7

Seems like they've stopped google adsense for ajax service now. However, loading ads with javascript is not allowed in google terms of service and may get you banned. https://www.google.com/adsense/localized-terms

You agree to comply with the specifications provided by Google from time to time to enable proper delivery, display, tracking, and reporting of Ads, Links, Search Results, Referral Buttons, and Google Brand Features (as defined in Section 12 below) in connection with Your Property(ies), including without limitation by not modifying the JavaScript or other programming provided to You by Google in any way, unless expressly authorized in writing by Google (including by electronic mail).

Mridul Kashatria
  • 4,157
  • 2
  • 18
  • 15
  • sorry but. Are you blind? I have given same link in my questi – genesis Jun 18 '11 at 07:47
  • I'm sorry I didn't go through each of the links you had in the question. I figured out your problem by reading the content of your question as I had about the same problem and found that it is not allowed by google. – Mridul Kashatria Jun 18 '11 at 07:54
  • it's ok. please edit your answer so I can delete my down-vote – genesis Jun 18 '11 at 08:00
2

Load the page with the ads in a hidden iframe, and just get the contents of that when it's loaded.

I'm not sure it works with Google ad scripts specifically, but it seems to work with javascript in general.

HertzaHaeon
  • 601
  • 5
  • 7
  • I would do it, ONLY PROBLEM is that background is styled with background url and I can't just keep it white – genesis Jun 22 '11 at 21:12
  • You can do display:none on the iframe and still access it with javascript. – HertzaHaeon Jun 23 '11 at 07:43
  • so something like – genesis Jun 23 '11 at 10:02
  • Yes, that would hide the iframe. There are several techniques that use iframes this way, many of them listed here on Stack Overflow. [jquery/javascript: accessing contents of an iframe](http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe). [File upload with iframes](http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery). – HertzaHaeon Jun 23 '11 at 18:37
  • But how could I "move" that iframe content to normal div ? I tried ` ` It does return (an empty string) only ... why? – genesis Jun 24 '11 at 10:30