When testing locally, I need to turn on the testing mode, so I need to add 'data-adbreak-test': 'on'
to the script.
However, this attribute needs to be deleted in a production environment.
dev:
{
async: true,
src: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js',
'data-ad-client': process.env.NUXT_PUBLIC_ADSENSE_CLIENT_ID,
'data-ad-frequency-hint': '30s',
'data-adbreak-test': 'on' // open testing mode
},
prod
{
async: true,
src: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js',
'data-ad-client': process.env.NUXT_PUBLIC_ADSENSE_CLIENT_ID,
'data-ad-frequency-hint': '30s',
// 'data-adbreak-test': 'on' // close testing mode
},
It needs to be commented out every time before going online. The operation is too cumbersome, and it is easy to forget to comment. Cause errors in the production environment. Is there a value similar to 'off'
to disable testing mode? In this case, I can control whether testing mode needs to be turned on through Nuxt environment variables.
I checked the documentation and didn't find any other values besides 'on'
google adsense doc
Or is there any other way that can be automatically controlled without manual annotation?
I have tried 'data-adbreak-test': 'off'
and 'data-adbreak-test': ''
with no effect
I solved this problem, if there is a better way, please feel free to comment.
{
async: true,
src: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js',
'data-ad-client': process.env.NUXT_PUBLIC_ADSENSE_CLIENT_ID,
'data-ad-frequency-hint': '30s',
...(process.env.NUXT_ENV === 'development' ? { 'data-adbreak-test': 'on' } : {}),
},