尝试使用Adsterra将网站(Next Js)货币化



我正试图使用Adsterra将我的网站(Next Js(货币化。我试着把自己建立在Next js的Google Adsense代码的基础上,但没有成功。

_document.js 中使用的代码

<script dangerouslySetInnerHTML={{
__html: `
atOptions = {
'key' : 'xxxxxxx',
'format' : 'iframe',
'height' : 60,
'width' : 468,
'params' : {}
};
document.write('<scr' + 'ipt type="text/javascript" src="http' + (location.protocol === 'https:' ? 's' : '') + '://www.effectivecreativeformats.com/xxxxxxxxxx/invoke.js"></scr' + 'ipt>');
`,
}} />

下面是一个组件的代码,创建后插入到我想放置广告的页面上

import React, { useEffect } from "react";
export default function Adsterra() {
const loadAds = () => {
try {
if (typeof document  !== "undefined") {
atOptions = {
'key' : 'xxxxxxxxxx',
'format' : 'iframe',
'height' : 60,
'width' : 468,
'params' : {}
};
document.write('<scr' + 'ipt type="text/javascript" src="http' + (location.protocol === 'https:' ? 's' : '') + '://www.displaynetworkprofit.com/xxxxxxxxxxx/invoke.js"></scr' + 'ipt>');
}
} catch (error) {
console.log("adsense error", error.message);
}
};
useEffect(() => {
loadAds();
}, []);
return (
<ins
key = 'xxxxxxxxxxx'
format = 'iframe'
height = '60'
width = '468'
params = '{}'
></ins>
);
}

您应该尝试制作一个具有内部Html的脚本。像这样。。。

var scr1 = document.createElement("script");
scr1.innerHTML = `
var scr = document.createElement("script");
var atOptions = {
'key' : 'xxxxx',
'format' : 'iframe',
'height' : 90,
'width' : 728,
'params' : {}
}
scr.src =
"http" +
(location.protocol === "https:" ? "s" : "") +
"://www.profitabledisplayformat.com/xxxxx/invoke.js";
document.querySelector("#_MainOuterIndexJs").appendChild(scr);
`;
document.querySelector("#_MainOuterIndexJs").appendChild(scr1);

最新更新