我使用Compositon和ı实现了GPT广告服务。当我第一次加载页面时,它工作得很好,但是如果我在页面之间切换,我的广告区域就会消失,我会得到错误消息。
ads.js
export const adIntegration = () => {
const adScript = document.createElement('script');
adScript.type = 'text/javascript';
adScript.src = 'https://securepubads.g.doubleclick.net/tag/js/gpt.js';
document.head.appendChild(adScript);
};
export const mainPageAd = ({ path, size, id }) => {
adIntegration();
window.googletag = window.googletag || { cmd: [] };
googletag.cmd.push(() => {
googletag.defineSlot(path, size, id).addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
googletag.display(id);
});
};
index.vue
<template lang="pug">
.home-page
.advertisement( :id="adSlot.id" style='min-width: 955px; min-height: 240px')
<script>
import { mainPageAd } from '~/common/utils/ads';
setup(){
const adSlots = ref({
path: '/21737763597/adunit-1',
size: [320, 100],
id: 'div-gpt-ad-1559997122392-0',
});
onMounted(() => {
mainPageAd({ path: adSlot.value.path, size: adSlot.value.size, id: adSlot.value.id });
}
return{adSlots}
我的错误
优先:错误在googletag.defineSlot:无法创建槽/1347001/主-masthead。Div元素"div-gpt-ad-1559997122392-0“已经与另一个插槽相关联: /1347001/main-masthead。
第二种: pubads_impl_2022092701.js?cb=31069995:18异常在排队的GPT命令TypeError:无法读取属性为null (读取'addService')
发布于 2022-09-29 13:26:20
export const adIntegration = () => {
const adScript = document.createElement('script');
adScript.type = 'text/javascript';
adScript.src = 'https://securepubads.g.doubleclick.net/tag/js/gpt.js';
document.head.appendChild(adScript);
};
export const mainPageAd = ({ path, size, id }) => {
adIntegration();
if (window.googletag) window.googletag.pubads().refresh();
window.googletag = window.googletag || { cmd: [] };
googletag.cmd.push(() => {
googletag.defineSlot(path, size, id).addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
googletag.display(id);
});
};
https://stackoverflow.com/questions/73891196
复制相似问题