I have a requirement to conditionally load adsense to certain visitors like only organic visitors. I came across a solution in stackoverflow: ref: [stackoverflow.com...]
Does such a solution violate adsense TOS in any way?
JorgeV
1:07 pm on May 22, 2021 (gmt 0)
Hello,
Quick answer "no". You are free to display ads to who you want, or even pick different ad, based on the visitor.
Please note that, testing the referrer is okay in 90% of case, but, a referrer can be altered, or removed. Some privacy protection software, or VPN are removing it.
kkinfy
1:16 pm on May 22, 2021 (gmt 0)
@JorgeV I am concerned about the code modifications (like those in the stackoverflow page I had linked in my question) - using document.createElement and wrapping the adsense within javascript If condition. Are these kind of implementations OK as per Google TOS?
JorgeV
2:18 pm on May 22, 2021 (gmt 0)
Hello,
Theoretically "no", but this is tolerated, because it's not altering the behavior of the Adsense code. Also, all ad management system, are in a way or another calling the Adsense code that way. So, it's okay.
lammert
4:09 pm on May 22, 2021 (gmt 0)
I would personally prefer a server based solution based on the HTTP_REFERER header sent from the browser to the web-server. This is faster and leaner, because there is no extra JavaScript involved which must first be sent to the client and then executed.
Including or excluding AdSense code with server-side scripting is allowed by the ToS.
kkinfy
2:18 am on May 23, 2021 (gmt 0)
@lammert I am using a HTML cache plugin. Hence if I go for a server based solution, I may have to maintain two cached versions - one with and one without adsense (and use htaccess rewrite to serve the appropriate copy). Will that be fine?
lammert
3:04 pm on May 24, 2021 (gmt 0)
With HTML caching, doing things browser-side in JavaScript may be a better solution. Your specific use case is not mentioned in the AdSense support pages [support.google.com], but in general modifications are allowed if they do not alter the ad performance or harm conversions for the advertisers. The type of modification you propose (only display ads to a subset of visitors) falls within the allowed categories.