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

相关推荐
curdcv_po7 小时前
我接入了微信小说小程序官方阅读器
前端·微信小程序
程序员鱼皮7 小时前
什么是 RESTful API?凭什么能流行 20 多年?
前端·后端·程序员
+VX:Fegn08957 小时前
计算机毕业设计|基于springboot + vue健身房管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
www_stdio7 小时前
让大语言模型拥有“记忆”:多轮对话与 LangChain 实践指南
前端·langchain·llm
inferno7 小时前
JavaScript 基础
开发语言·前端·javascript
cindershade7 小时前
Intersection Observer 的实战方案
前端
青莲8437 小时前
Kotlin Flow 深度探索与实践指南——中部:实战与应用篇
android·前端
cindershade7 小时前
事件委托(Event Delegation)的原理
前端
开发者小天7 小时前
React中useMemo的使用
前端·javascript·react.js
1024肥宅7 小时前
JS复杂去重一定要先排序吗?深度解析与性能对比
前端·javascript·面试