Refresh a Div that has a Google ad inside it
Asked Answered
R

7

40

I have a <div> that holds a google ad. My website is mostly AJAX and there is no need for a browser refresh. That means my ads will not refresh either, which isn't ideal, a user staring at one ad all day.

So I wanted a way to refresh a particular <div> on a page. I found many solutions but they didn't work. For example, using JQuery's html function:

$("#ads").html("google ad script here");

This managed to refresh the whole page no idea how. I can also make an AJAX request to a HTML page that contains the Google ad but I am guessing it will have the same effect as the above attempt.

I do not want to use iFrames.

Is there any other option open to me? My pea brain can not think of anymore. :)

EDIT:

It is allowed since I will be initiating the refresh only when a user clicks a link.

A prime example is Yahoo Mail - their new AJAX mailbox uses this same method, when a user clicks a link then a new ad is shown.

Rhizotomy answered 12/1, 2009 at 13:27 Comment(0)
F
50

As both of the other answers state, refreshing your AdSense advertisements automatically isn't allowed. I understand that you only intend to refresh the ad in response to user action, but it still isn't allowed, even though it should be!

Remember, the reason why you want to update the advertisements is so that you can show new ones. Displaying an advertisement is called an "impression." When you use code to refresh the ads, you are automatically generating ad impressions.

AdSense Program Policies state (emphasis mine):

Invalid Clicks and Impressions

Clicks on Google ads must result from genuine user interest. Any method that artificially generates clicks or impressions on your Google ads is strictly prohibited. These prohibited methods include but are not limited to repeated manual clicks or impressions, using robots, automated click and impression generating tools, third-party services that generate clicks or impressions such as paid-to-click, paid-to-surf, autosurf, and click-exchange programs, or any deceptive software.

Refreshing your advertisements is a violation of the letter of the rule against generating impressions. With that said, I think any reasonable person would agree that refreshing advertisements in an AJAX app in response to user behavior (e.g. in response to a click) isn't a violation of the spirit of the rule.

For example, imagine rewriting your entire app to stop using AJAX. That's clearly a worse experience for your users (it's slower, the page flashes on every click, the page can't dynamically update in the background), but, by a technicality, it's not a violation of the AdSense Program Policies.

Clearly Google meant to prohibit automatically replacing the advertisements every five seconds (creating a "slideshow" of advertisements). Google also meant to prohibit making your site look more attractive to advertisers by appearing to have more visits than you actually have. I'm sure they didn't intend to prevent you from designing a high-performance AJAX website... but unfortunately sometimes rules have unintended consequences.

Of course, as you originally pointed out, you CAN still refresh your advertisements if you embed them in an iframe and modify its location. (Here's how to use iframes in an AJAX application to refresh AdSense.)

You rejected iframes in your initial question, perhaps because you knew that using iframes would violate Google's policies... but if you insist on breaking the rules, you might as well break them all the way! ;-)

Ultimately, I think you'll find that generating impressions this way isn't worth the risk: you'll "refresh" the ads only to find that Google is just showing you the exact same ads as before.

Felicafelicdad answered 14/1, 2009 at 0:16 Comment(14)
That was a good read thanks :) - I am still determined that it is not illegal. I have a different interpretation of the sentence that is in bold. I do not believe a function being triggered because of a user clicking a link is artificial in anyway! :)Rhizotomy
I don't think that the OP's scheme violates any reasonable interpretation of the letter of the policy. It's hard to see any relevant difference between what OP is proposing, and the common practice of using JavaScript to trap button clicks and load a new URL. In both cases we have user action -> JavaScript -> change page contents.Spectroscope
Think of it this way: Google's product is called "AdSense for Content." It's not for webapps; it's for static pages, like blogs. (In general, AdSense for Webapps would be a much more complicated and ambitious project, because webapps change constantly; you can see why they took the easy route.) Changing contents in web pages is common practice in webapps, but that doesn't mean AdSense supports it!Felicafelicdad
Yesterday, Google announced AdSense for Ajax, which is what you really wanted all along.Felicafelicdad
And now it seems AdSense for AJAX was axed. They are no longer accepting requests so either they're close to launch or have decided it's not worth the threat to their business. While all of us on this thread have valid reasons for trying this, the clowns who try to game the system threaten the integrity of their ad platform making it less desirable for folks to advertise. Humph. Anyone had success with AdSense for Maps?Burstone
If you notice the ads on gmail, whenever you click on an email (an ajax call), the ad refreshes. So this makes me think that refreshing the ad based on a user click is legal.Minter
@Minter Gmail is a Google product; they're not using AdSense for Content. It would be very unwise to assume you can do something as an AdSense partner just because Google allows themselves to do it.Felicafelicdad
@DanFabulich -- If it doesn't say adsense on the ad it doesn't mean that the source of the advertised content isn't adsense, or do you think that google created a separate advertisement platform for gmail? :) If I'm left without a viable alternative, I'll take my chances. The part in bold talks about artificially generating impressions -- navigating a rich-client, ajax-based application isn't artificial in my vocabulary.Minter
@Minter It's up to you, but, as I said, I think it's not worth the risk, because most of the time you'll get no benefit at all. Refreshing the ad will just show the same ad a second time. You're risking a permanent lifetime ban for nothing. (Yes, they really do that.)Felicafelicdad
How Mashable guys doing it ? , Checkout , mashable.com/2012/08/19/top-10-tech-10/… Checkout the image slideshow, down the page , on click on each image, ad gets refreshed ?Diedra
@pradeep , actualy they are using ajax to get new data on scroll down since is infinite scroll, and adding ads each 2 posts. Their ads are located in another html file so its not called trigered refresh of google ads, its trigger refreshed of a mashable.com html file.I think this is how they are doing it.Anyway the infinite scroll eats my RAMDisjoin
A page impression is not the same as a page request. A single request can result in several impressions. So you are actually allowed to refresh the ad, when the visitor generates a new page impression. When you have an ajax picture gallery, viewing a new image = a new page impresisonDimity
Google "Generally, an impression translates to a user view of a particular item on your site[...]" Maybe this answer was correct in 2009, but it is wrong in 2015.Dimity
This answer is complete BS. Nothing in the answer supports the claim that Google prohibits automatic refreshes on single-page apps. And in fact, if you read their page, although it doesn't expressly address that issue, it clearly is within the spirit of their terms.Tormentil
N
28

The new Google DFP 'tags' allow specifically 'ad refreshing for AJAX'

refresh

pubService.refresh(slots) Refreshes the specified array of slots on the page with new ads.

Parameters:

array slots - Optional array of slots to refresh. If not supplied, all ad slots are refreshed. Example:

var slot1 = googletag.defineUnit("/1234567/leaderboard", [728, 90], "div-1").addService(googletag.pubads());

var slot2 = googletag.defineUnit("/1234567/skyscraper", [160, 600], "div-2").addService(googletag.pubads());

// The call to refresh fetches a new ad for each slot

googletag.pubads().refresh([slot1, slot2]); http://support.google.com/dfp_sb/bin/answer.py?hl=en&answer=2372721&expand=pubservice_details#refresh

Nehru answered 23/8, 2012 at 1:58 Comment(4)
+1, while this is not AdSense, it does offer a decent alternative. I'm very happy they brought this back! It was gone for some time.Coleencolella
I work with a live cricket sports app, that refreshes the adverts each time a new over is bowled. Its no different to the TV.Spotted
Just an FYI - DFP doesn't support AdSense link units (15px-high units). It supports only ad units.Claviform
The above will only work if initialized with the async code. Please refer to this article: support.google.com/dfp_sb/answer/3058726?hl=enSociopath
O
1

I know I'm a year and a half late to the party, but... It's possible that the problem with the ads is that they are using document.write (Ad servers are notorious for this, but I don't know if AdSense uses it or not.)

If that's the case, I have a library that can help: writeCapture.js. Example:

$('#ads').writeCapture().html('<script src="whatever-your-adsense-code-is"> </script>');

That's using jQuery, but there is also a standalone version.

As for whether it's a TOS violation... Gmail changes ads dynamically, so it can't be that bad. As long as the content is changing too, I would think it was OK.

Overdevelop answered 7/5, 2010 at 1:52 Comment(2)
Your are not late (i'm really late). I'll try your script right now cause I'm having the same problem, can't refresh a div with an adsense block.Regimentals
You can not really argument it's ok for everyone to do so because gmail does it; please keep in mind gmail and adsense both belong to the same company. You most likely don't.Elizebethelizondo
S
0

You can refresh the Google Ad Slots with the following code. Put this in the JS function you want to refresh the Ads. It should refresh all of the ads on the page.

if ( undefined !== googletag ) {
  googletag.pubads().refresh();
}

Google Ad Manager Help - Reload ads without a page refresh

Sluggard answered 16/1, 2019 at 19:22 Comment(0)
M
-1

Just include the ads in the pages you are loading via ajax. There can be nothing wrong with loading the ads from a file via ajax on a per page basis.

if I load Read.inc which has some content and an ad Click something on the page and it takes you to Make.inc which has content an an ad.

Whats wrong with that? That's organic. One load with the ad as part of the content.

It's the same as clicking a link.

I haven't actually tried this yet, but it certainly seems logical.

Macri answered 4/12, 2009 at 13:35 Comment(1)
That won't work with adsense. It will load at most 3 ads per page. You need to somehow unload old ads for which there is no API.Claviform
G
-2

It is not allowed (according to AdSense terms) to try and reload ads during the page life-cycle. Also, it is hardly possible (thanks to the platform architecture).

Geminate answered 12/1, 2009 at 13:45 Comment(2)
Do you have a link to back this up?Rhizotomy
that surely possible with double click implementationShantelleshantha
I
-3

It is not allowed. but I think you can use a iframe for that. I saw good tutorials of that. I tried do it by ajax by I rollback my changes for the Adsense TOS

Implant answered 12/1, 2009 at 13:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.