在Firefox上,AMP收到错误:" window.AMP未定义"

时间:2016-07-21 19:45:18

标签: amp-html

我开始了一个包括放大器的新项目。

Firefox会系统地报告此错误:

  

TypeError:window.AMP未定义

我按照入门步骤进行操作。以下是索引的head标记的样子:

<html amp lang="fr">
<head>
  <meta charset="utf-8">
  <title>my title</title>
  <link rel="canonical" href="http://example.com/non-amp_index.php" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="description" content="description">
  <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

  <meta property="og:url"          content="http://example.com/home" />
  <meta property="og:type"         content="article" />
  <meta property="og:title"        content="title" />
  <meta property="og:description"  content="description" />
  <meta property="og:image"        content="sharedImage" />

  <meta name="twitter:card"  content="summary_large_image">
  <meta name="twitter:site"  content="@client">
  <meta name="twitter:title" content="title">
  <meta name="twitter:description" content="description">
  <meta name="twitter:image" content="sharedImage">

  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
  <noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>

  <!-- AMP properties -->
  <script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "NewsArticle",
    "mainEntityOfPage":{
      "@type":"WebPage",
      "@id":"http://example.com"
    },
    "headline": "<?=$copyDeck['title'] ?>",
    "image": {
      "@type": "ImageObject",
      "url": "http://example.com/cover.jpg",
      "height": 800,
      "width": 800
    },
    "datePublished": "2016-09-02T08:00:00+08:00",
    "dateModified": "2016-09-02T09:20:00+08:00",
    "author": {
      "@type": "Organization",
      "name": "Client"
    },
    "publisher": {
      "@type": "Organization",
      "name": "Client",
      "logo": {
        "@type": "ImageObject",
        "url": "https://example.com/logo.png",
        "width": 320,
        "height": 120
      }
    },
    "description": "description"
  }
  </script>

  <!-- Analytics -->
  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
    ga('create', 'UA-ANALYTICS', 'auto');
    ga('send', 'pageview');
  </script>

  <!-- comScore -->
  <script type="text/javascript">
  // <![CDATA[
  function udm_(a){var b="comScore=",c=document,d=c.cookie,e="",f="indexOf",g="substring",h="length",i=2048,j,k="&ns_",l="&",m,n,o,p,q=window,r=q.encodeURIComponent||escape;if(d[f](b)+1)for(o=0,n=d.split(";"),p=n[h];o<p;o++)m=n[o][f](b),m+1&&(e=l+unescape(n[o][g](m+b[h])));a+=k+"_t="+ +(new Date)+k+"c="+(c.characterSet||c.defaultCharset||"")+"&c8="+r(c.title)+e+"&c7="+r(c.URL)+"&c9="+r(c.referrer),a[h]>i&&a[f](l)>0&&(j=a[g](0,i-8).lastIndexOf(l),a=(a[g](0,j)+k+"cut="+r(a[g](j+1)))[g](0,i)),c.images?(m=new Image,q.ns_p||(ns_p=m),m.src=a):c.write("<","p","><",'img src="',a,'" height="1" width="1" alt="*"',"><","/p",">")}
  udm_('http://b.scorecardresearch.com/p?c1=2&c2=ID&ns_site=cmf-fmc&application_id=ID&cmf_ev=start');
  // ]]>
  </script>
  <noscript><p><img src="http://b.scorecardresearch.com/p?c1=2&c2=ID" height="1" width="1" alt="*"></p></noscript>
  <!-- End comScore Inline Tag -->
  <!-- Begin comScore Inline Tag 1.1111.15 -->
  <script type="text/javascript" language="JavaScript1.3" src="http://b.scorecardresearch.com/c2/ID/cs.js"></script>
  <!-- End comScore Inline Tag -->

  <script async src="https://cdn.ampproject.org/v0.js"></script>
</head>

1 个答案:

答案 0 :(得分:2)

尝试使用<amp-analytics>等效项替换两个分析脚本。

您需要使用AMP库<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>和两个JSON个岛屿;一个用于Google Analytics,另一个用于comScore。

以下是文档:

https://developers.google.com/analytics/devguides/collection/amp-analytics/

https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/amp-analytics.md