【问题标题】:AMP analytics events for scroll用于滚动的 AMP 分析事件
【发布时间】:2017-06-22 01:09:27
【问题描述】:

我正在尝试向我的 AMP 页面添加分析。而 tra

<!doctype html>
<html amp lang="en">

<head>
  <meta charset="utf-8">
  <title>Hello, AMP Analytics</title>
  <link rel="canonical" href="http://example.ampproject.org/article-metadata.html" />
  <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
  <script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
  <style>
    body {
      opacity: 0
    }
  </style><noscript><style>body {opacity: 1}</style></noscript>
  <script async src="https://cdn.ampproject.org/v0.js"></script>
</head>

<body>
  <amp-analytics type="googleanalytics">
    <script type="application/json">
      {
        "vars": {
          "account": "UA-xxxxxxxx-x"
        },
        "triggers": {
          "trackPageview": {
            "on": "visible",
            "request": "pageview"
          },
          "scrollPings": {
            "on": "scroll",
            "scrollSpec": {
              "verticalBoundaries": [10, 20, 30, 40, 50, 60, 70, 80, 90]
            },
            "request": "event",
            "vars": {
              "eventId": "scroll"
            }
          },
          "trackEvent": {
            "selector": "#event-test",
            "on": "click",
            "request": "event",
            "vars": {
              "eventCategory": "${canonicalUrl}",
              "eventAction": "click"
            }
          }

        }
      }
    </script>
  </amp-analytics>

  <h1 id="header">AMP Page</h1>

  <span id="event-test" class="box">
    Click here to generate an event
  </span>
  <h2>

    Page semi-protected Blog From Wikipedia, the free encyclopedia "Blogger" redirects here. For the Google service with same name, see Blogger (service). For other uses, see Blog (disambiguation). Not to be confused with .blog. Journalism Simons Perskaart
    DOM.jpg News Writing style Ethics Objectivity News values Attribution Defamation Editorial independence Journalism school Index of journalism articles Areas Arts Business Data Entertainment Environment Fashion Medicine Politics Science Sports Technology
    Trade Traffic Weather World Genres Advocacy Analytic Blogging Broadcast Citizen Civic Collaborative Comics-based Community Data Database Gonzo Immersion Investigative Literary Muckraking Narrative "New Journalism" Non-profit Online Opinion Peace Photojournalism
    Scientific Sensor Underground Visual Watchdog Social impact Fake news Fourth Estate Fifth Estate Freedom of the press Infotainment Media bias Public relations Press service Propaganda model Yellow journalism News media Newspapers Magazines TV and
    radio Internet News agencies Alternative media Roles Journalists (reporters) Columnist Blogger Editor Copy editor Meteorologist News presenter Photographer Pundit / commentator Newspaper nicu buculei 01.svg Journalism portal Category: Journalism v
    t e A blog (a truncation of the expression "weblog")[1] is a discussion or informational website published on the World Wide Web consisting of discrete, often informal diary-style text entries ("posts"). Posts are typically displayed in reverse chronological
    order, so that the most recent post appears first, at the top of the web page. Until 2009, blogs were usually the work of a single individual,[citation needed] occasionally of a small group, and often covered a single subject or topic. In the 2010s,
    "multi-author blogs" (MABs) have developed, with posts written by large numbers of authors and sometimes professionally edited. MABs from newspapers, other media outlets, universities, think tanks, advocacy groups, and similar institutions account
    for an increasing quantity of blog traffic. The rise of Twitter and other "microblogging" systems helps integrate MABs and single-author blogs into the news media. Blog can also be used as a verb, meaning to maintain or add content to a blog. This
    page was last edited on 18 May 2017, at 21:34. Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered
    trademark of the Wikimedia Foundation, Inc., a non-profit organization. Privacy policyAbout WikipediaDisclaimersContact WikipediaDevelopersCookie statementMobile viewWikimedia Foundation Powered by MediaWiki
  </h2>
</body>

</html>

ckPageview 和 trackEvent 生成事件。 scrollPings 没有。 有人试过这个吗? ** scrollPing 的参考代码来自 AMP by Example 页面。 在此先感谢

< amp - analytics type = "googleanalytics" >
  <script type = "application/json" > {
    "vars": {
      "account": "UA-XXXXXXXX-X"
    },
    "triggers": {
      "trackPageview": {
        "on": "visible",
        "request": "pageview"
      },
      "scrollPings": {
        "on": "scroll",
        "scrollSpec": {
          "verticalBoundaries": [10, 20, 30, 40, 50, 60, 70, 80, 90]
        },
        "request": "event",
        "vars": {
          "eventId": "scroll"
        }
      },
      "trackEvent": {
        "selector": "#event-test",
        "on": "click",
        "request": "event",
        "vars": {
          "eventCategory": "${canonicalUrl}",
          "eventAction": "click"
        }
      }

    }
  } 
</script> 
</amp-analytics>

【问题讨论】:

  • 可以显示 amp 验证器返回的日志吗?
  • 另外,如果它托管在某个地方,你能显示整个页面吗?
  • 我已经更新了整个页面。谢谢
  • 你有什么收获吗?
  • @GuyBowden 不

标签: google-analytics amp-html


【解决方案1】:

与我们的另一位开发人员合作,我们设法解决了这个问题,至少部分解决了这个问题。有一些 URL 替代变量,您需要使用 verticalScrollBoundary 的变量来报告百分比(就像您在那里为测试事件所做的那样)。请注意,'${verticalScrollBoundary}%' 变量后面的百分号是可选的,并添加到我们的分析报告中以与非 AMP 滚动深度跟踪保持一致。

这对我们有用:

'scrollPings' => array(
  'on' => 'scroll',
  'request' => 'event',
  'scrollSpec' => array(
    'verticalBoundaries' => array( 0, 25, 50, 75, 100 )
  ),
  'vars' => array(
    'eventCategory' => 'AMP Scroll Depth',
    'eventAction'   => 'Scrolled',
    'eventLabel'    => '${verticalScrollBoundary}%',
  ),
),

抱歉,我们正在使用 WordPress 插件,这是被翻译成 JSON b/c 的 PHP 语法。对于 JSON,它会是(我相信):

"scrollPings": {
  "on": "scroll",
  "request": "event",
  "scrollSpec": {
    "verticalBoundaries": [0, 25, 50, 75, 100]
  },
  "vars": {
    "eventCategory": "AMP Scroll Depth",
    "eventAction": "Scrolled",
    "eventLabel": "${verticalScrollBoundary}%"
  },
}

我们还没有弄清楚的一件事是,如果您在@987654324 末尾包含一个百分号,它似乎正在记录“(未设置)”或“%”的空值@ 多变的。请注意,百分号是可选的。如果没有百分号,我们只会记录一个(未设置)值,该值似乎不等于 0(您会注意到我在可能值数组中添加了 0)。

【讨论】:

  • 感谢基本功能现在似乎可以使用
猜你喜欢
  • 1970-01-01
  • 2021-11-02
  • 1970-01-01
  • 2019-04-09
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多