我需要将 pagePath 值动态传递到我的 amp 分析代码的变量值中。你能告诉我如何实现这一目标吗?例如,在下面的代码片段中,我需要根据当前页面路径将 pagePath 替换为不同的值。
<amp-analytics config="https://www.googletagmanager.com/amp.json?id=xxxxxxxxx>m.url=SOURCE_URL" data-credentials="include"
<script type="application/json">
{
"vars" : {
"pagePath" : { Needs to be passed dynamically }
}
}
</script>
<amp-analytics>
您将使用变量替换 (https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md(。
您感兴趣的变量是"规范路径"(https://github.com/ampproject/amphtml/blob/master/spec/amp-var-substitutions.md#canonical-path(。
在发送分析请求之前,您可以将字符串插入${canonicalPath}
您希望将其模板化的任何位置。例如:
<amp-analytics config="https://www.googletagmanager.com/amp.json?id=xxxxxxxxx>m.url=SOURCE_URL" data-credentials="include"
<script type="application/json">
{
"vars" : {
"pagePath" : "${canonicalPath}"
}
}
</script>
<amp-analytics>