在zend 2.3.5中添加脚本

时间:2018-06-14 08:50:28

标签: html zend-framework google-analytics

在过去的几个小时里,我一直在尝试将谷歌分析添加到页面,我认为我遵循文档,但它只是对我不起作用。

我试图实现:

<script async src="https://www.googletagmanager.com/gtag/js?id=xxxx"></script>
  <script>
      window.dataLayer = window.dataLayer || [];
      function gtag() { dataLayer.push(arguments); }
      gtag('js', new Date());

      gtag('config', 'xxxx');
  </script>

我做了:

<?php
    echo $this->headScript()            
            ->appendFile(
                'https://www.googletagmanager.com/gtag/js?id=xxxx', 
                null, 
                array("async" => "true")
              )
            ->appendFile($this->basePath('/js/gtag.js'))
    ?>

不起作用(我不认为我可以像这样添加gtag脚本。结果:

<script type="" src="https://www.googletagmanager.com/gtag/js?id=UA-120611634-1"></script>

还尝试了appendingScript

 ->appendScript("
            window.dataLayer = window.dataLayer || [];
            function gtag() { dataLayer.push(arguments); }
            gtag('js', new Date());

            gtag('config', 'xxxx');
            ")

结果:

<script type="text/javascript">
    //<!--

                window.dataLayer = window.dataLayer || [];
                function gtag() { dataLayer.push(arguments); }
                gtag('js', new Date());

                gtag('config', 'xxxx');

    //-->
</script>

以前从未处理过Zend,但是在网上跟踪了一些例子,它就不会工作了。我要感谢任何提示或帮助

0 个答案:

没有答案