Vue Google 广告的配置

前置条件:已经在Google AdSense 中 添加网站 并通过审核 同时已创建广告单元。

因 VUE 的 Script 配置问题,所以不能直接拷贝内容。

index.html 配置

添加 Google 广告的脚本。

复制代码
//index.template.html
/* *
在head标签中添加 script
【 **** 】:你的发布商 ID
*/
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4797644559430915"
            crossorigin="anonymous"></script>

//index.template.html
//在body标签中为window添加函数
<body>
 
  <div id="q-app"></div>

<script>
    window['googlAdsense'] = function () {
        let chlid = document.getElementsByClassName('google-adsense-slot')
        for (let index = 0; index < chlid.length; index++) {
            (adsbygoogle = window.adsbygoogle || []).push({});
        }
    }
</script>
</body>

组件中

组件中添加应用。

复制代码
onMounted(() => {
   window.googlAdsense();
});

为广告添加占位符。

复制代码
//将广告单元代码添加到盒子中
<template>
            <div class="col google-adsense-slot">
              <ins
                  class="adsbygoogle"
                  style="display: block"
                  data-ad-client="ca-pub-4797644559430915"
                  data-ad-slot="4417932244"
                  data-ad-format="auto"
                  data-full-width-responsive="true"
              ></ins>
            </div>
</template>

https://www.isharkfly.com/t/vue-google/16438/1

相关推荐
卸任11 小时前
Vibe coding工具使用心得
前端·ai编程
brien911 小时前
为什么模型标称 1M,Google Antigravity 聊到 256K 却突然失忆?我们给它做了个原生行内监控圆环
前端
修炼的dance12 小时前
录屏关键帧间隔多少合适?六档实测,2秒到10秒小了75.6%
前端
Lank_M12 小时前
关键帧从1秒拉到10秒,录屏小87.3%,摄像头小10.8%
前端
补码缩写12 小时前
用 ffprobe 拆录屏,八成字节在 29 个关键帧上
前端
百思不得小李12 小时前
一个复杂的动态表单是如何实现的
前端·设计模式
陈随易12 小时前
Cmder 停更 17 个月,2.0 支持 Windows Terminal
前端·后端·程序员
清晨Coding12 小时前
删了 Cookie 还能自动登录?Google系网站登录态自动恢复的原理分析
javascript
风骏时光牛马12 小时前
前沿视界
前端
kyriewen12 小时前
我扫了 814 个依赖,97 个还敢要 Node 10
前端·javascript·程序员