You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在AdSense中实现非个性化广告?代码放置位置咨询

How to Add Non-Personalized Ads Request to Your Google AdSense Code

Hey there! I’ve helped tons of developers with this exact setup, so let’s get this sorted for you right away.

The line (adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=1 needs to go after the AdSense library loads, but before you trigger the ad render with .push({}). This ensures the non-personalized ad setting is applied when the ad request is sent.

Here’s your updated, fully functional code with the line placed in the correct spot:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- leaderboard -->
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-xxxxxxxxxxxxxxxx" data-ad-slot="1234567890"></ins>
<script>
  // Enable non-personalized ads
  (adsbygoogle = window.adsbygoogle || []).requestNonPersonalizedAds = 1;
  // Trigger ad loading
  (adsbygoogle = window.adsbygoogle || []).push({});
</script>

Quick breakdown of why this works:

  • The first script loads the AdSense library, which initializes the window.adsbygoogle array if it doesn’t already exist.
  • Setting requestNonPersonalizedAds=1 configures the ad request before we call .push({})—this way, the setting is active when AdSense sends the request for your ad.
  • You could also place this line right after the initial AdSense script (before the <ins> tag) and it would work just as well, but keeping it grouped with the ad trigger script makes your code cleaner and easier to maintain.

内容的提问来源于stack exchange,提问作者Adrian yo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:50:32