关于Google Adsense中打开和关闭测试模式的问题

问题描述 投票:0回答:1

本地测试时,需要开启测试模式,所以需要在脚本中添加

'data-adbreak-test': 'on'
。 但在生产环境中需要删除该属性。 开发人员: enter image description here 产品 enter image description here

每次上线前都需要注释掉。操作太繁琐,很容易忘记评论。导致生产环境出现错误。是否有类似于

'off'
的值来禁用测试模式?这样的话,我可以通过Nuxt环境变量来控制是否需要开启测试模式。

我检查了文档,除了

'on'
google adsense doc

之外,没有发现任何其他值

或者有没有其他方式可以自动控制,无需手动标注?

我已经尝试了

'data-adbreak-test': 'off'
'data-adbreak-test': ''
,但没有效果

javascript typescript nuxt.js environment adsense
1个回答
0
投票
// Check if we are in the production environment
const isProduction = process.env.NODE_ENV === 'production';

// Get a reference to the script element
const script = document.getElementById('your-script-id'); // Replace 'your-script-id' with the actual ID of your script element

// Conditionally add or remove the attribute
if (!isProduction) {
  script.setAttribute('data-adbreak-test', 'on');
} else {
  script.removeAttribute('data-adbreak-test');
}

You can try this

© www.soinside.com 2019 - 2024. All rights reserved.