简体   繁体   English

为 amp-next-page 组合 amp-analytics

[英]Combine amp-analytics for amp-next-page

I am currently using the code below to track pageviews on my AMP accelerated pages on a WordPress website:我目前正在使用以下代码在 WordPress 网站上跟踪我的 AMP 加速页面的浏览量:

    {
    "vars": {
        "account": "UA-12345678-1"
    },
    "triggers": {
        "trackPageview": {
            "on": "visible",
            "request": "pageview"
        }
    }
}

I have just implemented infinite scroll on single pages and i need the next-page to be tracked on scroll or click also.我刚刚在单页上实现了无限滚动,我还需要在滚动或单击时跟踪下一页。 I found the below code on the official "amp.dev" page:我在官方“amp.dev”页面上找到了以下代码:

 <amp-analytics>
  <script type="application/json">
    {
      "requests": {
        "nextpage": "https://example.com/pixel?RANDOM&toURL=${toURL}"
      },
      "triggers": {
        "trackScrollThrough": {
          "on": "amp-next-page-scroll",
          "request": "nextpage"
        },
        "trackClickThrough": {
          "on": "amp-next-page-click",
          "request": "nextpage"
        }
      }
    }
  </script>
</amp-analytics>

How can I combine both codes into one such that it can track both pageviews and the infinite scroll (both on-click and on-scroll)如何将两个代码合并为一个,以便它可以跟踪综合浏览量和无限滚动(点击和滚动)

I managed to find a work-around, i added the code below in my footer and it works:我设法找到了解决方法,我在页脚中添加了以下代码,它可以工作:

<amp-analytics id="11e2c333333a" type="googleanalytics">
  <script type="application/json">
    {
      "requests": {
        "nextpage": "<?php get_permalink(get_the_ID()); ?>?amp"
      },
    "vars": {
        "account": "UA-12345678-1"
    },
      "triggers": {
        "trackScrollThrough": {
          "on": "amp-next-page-scroll",
          "request": "nextpage"
        },
        "trackClickThrough": {
          "on": "amp-next-page-click",
          "request": "nextpage"
        },
    "trackPageview": {
            "on": "visible",
            "request": "pageview"
        }
      }
    }
  </script>
</amp-analytics>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM