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

如何从Google AdSense代码中移除Google Fonts以满足欧盟合规要求?

解决Google AdSense自动加载Google Fonts的欧盟隐私合规问题

可行方案:通过前端代码拦截Google Fonts请求

核心思路是阻止AdSense注入的Google Fonts加载请求,同时强制广告元素使用本地或系统默认字体,以下是两种实现方式:

1. JavaScript拦截+样式覆盖

这段代码会拦截Google Fonts的网络请求,并强制所有广告单元使用系统通用字体:

document.addEventListener('DOMContentLoaded', function() {
  // 拦截fetch请求中的Google Fonts
  if ('fetch' in window) {
    const originalFetch = window.fetch;
    window.fetch = function(resource) {
      if (typeof resource === 'string' && resource.includes('fonts.googleapis.com')) {
        return Promise.reject(new Error('Blocked Google Fonts'));
      }
      return originalFetch.apply(this, arguments);
    };
  }

  // 强制广告元素使用系统字体
  const fontStyle = document.createElement('style');
  fontStyle.textContent = `
    ins.adsbygoogle,
    ins.adsbygoogle * {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif !important;
    }
  `;
  document.head.appendChild(fontStyle);
});

2. Content Security Policy (CSP) 全局拦截

若你有权限配置网站HTTP响应头,可添加CSP规则禁止加载Google Fonts,同时指定允许的字体来源:

Content-Security-Policy: font-src 'self' data:;

注:该规则会全局阻止所有Google Fonts请求,若你的网站自身原本依赖Google Fonts,需先将这些字体本地化部署。

关键注意点

  • 以上方法未违反AdSense政策,仅修改广告字体渲染方式,未篡改广告内容或干扰加载逻辑。
  • 测试时需确认广告替换字体后排版正常,避免出现布局错乱。
  • 对于后台无法修改字体的展示广告单元,JavaScript样式覆盖是最直接的解决方式。

内容的提问来源于stack exchange,提问作者Dirk T

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 18:01:14