Configure Google AdSense and Google Analytics in VitePress
This article is original, reproduced please indicate the source
add ads.txt
Add to your website root directory!!!
You can find it like this
Click on the Adsense home page to enter the website page, and then click on the "website URL"
add script at config
txt
head: [
//Google Analytics
[
'script',
{ async: '', src: 'https://www.googletagmanager.com/gtag/js?id=YOURID' } //[!code focus]
],
[
'script',
{},
`window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'YOURID');` //[!code focus]
],
//Google AdSense
[
"script",
{
"data-ad-client": "YOURCLIENTID like ca-pub-3798***", //[!code focus]
async: '',
src: "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js",
},
],
],
You can find it like this
YOURID: Enter the Analytics personal homepage, search for ID
YOURCLIENTID: Click on the Adsense homepage to enter the advertise page, and then click on the "get code"