我正在尝试从AMP页面向Google Analytics发送自定义页面名称(页面网址)。通常我会发送这样的自定义页面名称:
ga('send', 'pageview', {'page': 'myPageName'});
但只能从此JSON代码中自定义分析:
<amp-analytics type="googleanalytics" id="analytics1">
<script type="application/json">
{
"vars": {
"account": "UA-664228-1"
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "pageview",
"vars": {
"title": "<?php the_title() ?>",
"ampdocUrl": "${canonicalUrl}"
}
}
}
</script>
</amp-analytics>
如何修改报告回Google Analytics的网页名称(页面网址)?
答案 0 :(得分:2)
好的,我明白了。您添加了一个documentLocation变量。方法如下:
<amp-analytics type="googleanalytics" id="analytics1">
<script type="application/json">
{
"vars": {
"account": "UA-664228-1"
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "pageview",
"vars": {
"title": "<?php the_title() ?>",
"ampdocUrl": "${canonicalUrl}",
"documentLocation": "myCustomPage"
}
}
}
</script>
</amp-analytics>
答案 1 :(得分:0)
您可以使用variable substiution。