用nuxt写官网
添加seo 添加GA代码
head(){
return{
show2:false,
title:this.title,
meta:[{
hid:'title',name:'title',content:this.title
},{
hid:'description',name:'description',content:this.description
},
{
hid:'keywords',name:'keywords',content:this.keywords
},
],
script:[{
async: "async",
src:'https://www.googletagmanager.com/gtag/js?id=XXXX'
}]
}
添加GTM代码
踩坑:使用了网上的谷歌追踪代码或者百度的代码,弄了gtm.js,单独给config.js引入,结果报错,不管是引入在html部分还是plugins,都不行。
有script和noscript部分
可以新增app.html,直接放置。
但不想新增html就
在要引入的页面mounted使用
inits(){
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXX')
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-xxxxx');
}
引入是否成功,可以查看谷歌插件Tag Assistant