我正在尝试向Next.js AMP页面中的GA跟踪的窗口对象添加值。但是我无法编辑窗口对象。
import Head from 'next/head';
import React,{ Component } from 'react';
import get from 'lodash/get';
import styles from './styles';
export default class AMPHeader extends Component {
render() {
`let contentData;`
`for (const key in this.props) {`
`if (this.props[key].templateTitle === 'mainNavigation') {`
`contentData = this.props[key];`
`break;`
`}`
`}`
return (
`<>`
`<Head>`
`<script`
`async`
`custom-element="amp-sidebar"`
`src="https://cdn.ampproject.org/v0/amp-sidebar-0.1.js"`
`></script>`
`<script`
`async`
`custom-element="amp-script"`
`src="https://cdn.ampproject.org/v0/amp-script-0.1.js"`
`></script>`
`</Head>`
`<amp-script layout="container" src="https://example.com/hello-world.js">`
`<button>Hello amp-script!</button>`
`</amp-script>`
`<script id="hello-world" type="text/plain" target="amp-script">`
`{(window.test = 'Test')}`
`</script>`