【发布时间】:2018-12-06 20:42:26
【问题描述】:
对于这个菜鸟问题我很抱歉,我刚开始使用 next.js 模板表单https://github.com/zeit/next.js/tree/canary/examples/hello-world/pages 通常我只会将 gtag.js 添加到 index.html,但对于这个 next.js,只有 index.js。问题是我怎么能包括这个?我曾尝试将 gtag 作为组件并尝试导入它并包含脚本,因为它位于 index.js 的渲染函数中,但到目前为止它不起作用!请帮帮我!
Gtag:
<script async src="https://www.googletagmanager.com/gtag/js?
id=GA_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_TRACKING_ID');
</script>
index.js:
import Link from 'next/link'
export default () => (
<div>Hello World. <Link href='/about'><a>About</a></Link></div>
)
【问题讨论】:
标签: javascript next.js gtag.js