javascriptjqueryajaxadsensegoogle-publisher-tag

Best way to go about refreshing Adsense ads on a usr action on an ajax website


First let me say I know refreshing ads is against the Adsnese policies.

Ajax sites can be a hassle in terms of the ads sitting on one ad because the page doesn't refreshing as the user navigates the website. I have been talking to adsense and they understand my problem and have agreed to review a test page of ads refreshing on user actions.

I plan on doing it all by their books, using DFP (because its an ajax site) and GPT to refresh the ads.

The problem I'm stuck on is a way to call the ad refresh. Looking at the GPT ad refresh help article they have a method for refreshing ads every x seconds. I don't want this. At the very bottom they have a submit button that you can implement to test the ad refreshes. This 'refresh' action on the button submit will refresh the ads.

It doesn't say anywhere the button is strictly only for testing so I plan on using what it provides. But having buttons look like links isn't ideal.

Is there another way to implement the ad refresh call on the GPT coding the same way the button test example does?


Solution

  • Yes, you can use the javascript from the form onsubmit attribute anywhere in your js:

    googletag.pubads().refresh();