nlr_p nlr_p - 4 months ago 8
HTML Question

How to include HTML tags in amphtml

This is my script tag when trying to add amp to it, validator says script tags are not allowed except in some cases.Can someone help me out please.

<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-71734474-1', 'auto');
ga('send', 'pageview');

</script>

Answer

in amp, analytics are surrounded by extra tags

<amp-analytics type="googleanalytics" id="analytics1">
<script>

</script>
</amp-analytics>

but google analytics do not generally take the same format

its's usually something like this

"vars": {
    "account": "UA-XXXXX-Y" //your ga number
  },
  "triggers": {
    "trackPageview": {
      "on": "visible",
      "request": "pageview"
    }
  }

See the amp developers page for more info