google广告 google分析

google广告

AFS广告主要是指嵌入在搜索引擎上的广告,用户在进行搜索时看到的广告,与搜索关键词息息相关。
AFC广告则是展示在网页内容中的广告,与网页的文本内容相关。

AFC类型广告

**AFC广告则是展示在网页内容中的广告,与网页的文本内容相关。**
  • 当只引入AFC广告链接时<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-123456***" crossorigin="anonymous"></script>,会自动显示display广告,具体如何显示是产品在后台设置,我们不用管。
  • 当产品需要让我在特定位置或特定时机显示广告时,我们需要插入HTML代码块<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-123456***" data-ad-slot="8*********" data-ad-format="auto" data-full-width-responsive="true"></ins>,或者使用js插入;然后执行代码插入语句 (adsbygoogle = window.adsbygoogle || []).push({});,即可在特定位置插入广告,但该广告也不是必现,主要靠产品在后台设置。
// AFC广告
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-123456***" crossorigin="anonymous"></script>

// 方法1:广告容器
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-123456***"
     data-ad-slot="8*********"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
	// 加载广告
	<script>
	     (adsbygoogle = window.adsbygoogle || []).push({
   });
	</script>

// 方法2:js创建广告容器
insertGgafc() {
   
	// 创建广告容器:给容器设置宽度就相当于给广告设置宽度
    const adContainer = document.createElement('div');
    adContainer.className = 'middle-ad-container';
    adContainer.style.cssText = 'margin: 20px 0; max-width: 520px;';

    // 创建广告元素
    const adInsElement = document.createElement('ins');
    adInsElement.className = 'adsbygoogle';
    adInsElement.style.display = 'block';
    adInsElement.setAttribute('data-ad-client', 'ca-pub-6468790746781495');
    adInsElement.setAttribute('data-ad-slot', '6799291808');
    adInsElement.setAttribute('data-ad-format', 'auto');
    adInsElement.setAttribute('data-full-width-responsive', 'true');
    // 将广告添加到容器
    adContainer.appendChild(adInsElement);
	// 加载广告
    try {
   
      (adsbygoogle = window.adsbygoogle || []).push({
   });
    } catch (err) {
   
      console.error('Ad load error:', err);
      adContainer.remove();
    }
}

AFS类型广告

AFS广告主要是指嵌入在搜索引擎上的广告,用户在进行搜索时看到的广告,与搜索关键词息息相关。 AFS广告比较麻烦了

// 以下两段代码都是产品给的,直接粘贴即可

// 搜索引擎
<script async src="https://cse.google.com/cse.js?cx=c123456***"></script>
// 搜索结果容器
<div class="gcse-searchresults-only"></div>

CSE广告

CSE广告(Customer Search Engine)通常指的是客户搜索引擎广告。

// 这里无需额外添加代码,上述搜索引擎结果会自带这个CSE广告

含有赞助商广告加粗字样的结果则为CSE广告
在这里插入图片描述

RS广告

RS广告通常指的是相关搜索广告(Related Search ads),这些广告一般显示在用户进行搜索时的结果页面上,与搜索的关键词相关。

其中pubIdstyleId需要产品给我们

// RS广告
    window.__gcse = {
   
      parsetags: 'onload', // Defaults to 'onload'
      initializationCallback: null,
      searchCallbacks: {
   
        web: {
   
          rendered: function (gname, query, promoElts, resultElts) {
   
            // 移除已存在的 RS 广告
            const existingRsBox = document.getElementById('rs-box-1');
            if (existingRsBox) {
   
              existingRsBox.remove();
            }

            // 只在第一页显示 RS 广告
            if (isPageOne()) {
   
              let rsContainer = document.createElement('div');
              rsContainer.id = 'rs-box-1';
              rsContainer.style.margin = '20px 0';
              let posE = resultElts[6];
              if (posE && posE.parentNode) {
   
                posE.parentNode.insertBefore(rsContainer, posE);
                afsInit();
              }
            }
          },
        },
      },
    };
    function afsInit() {
   
      var q = gaEventUtils.getParam('q');
      if (q) {
   
        loadSearchAd(q);
      }
    }
    function loadSearchAd(query) {
   
      if (query) {
   
        var searchPage = getSearchUrl(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值