我想将Google标签管理器添加到Magento,但我不想为此使用插件,我的问题是什么是最佳实践?我已经阅读了一些有关创建模块的文章,还包括在身体标签内部包含GTM,问题是我要找到加载每个页面的文件的文件。
谢谢
只要您可以编辑主题文件即可,添加脚本块(或您可能需要的其他内容)非常简单。您可以从主题内部编辑page.xml文件。
magento app design frontend < your_interface> < your_theme> layout layout page.xml
在所有页面块中添加一个新块。在此块中,您会找到所有的HEAD脚本和CSS。下面的示例:
<default translate="label" module="page">
<label>All Pages</label>
<block type="page/html" name="root" output="toHtml" template="page/1column.phtml">
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
<action method="addItem"><type>skin_js</type><name>js/app.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/script.min.js</name></action>
<!-- Add stylesheets with media queries for use by modern browsers -->
<action method="addItem"><type>skin_css</type><name>css/styles.css</name><params/></action>
<!-- Sets viewport meta tag using text block -->
<block type="core/text" name="head.viewport">
<action method="setText"><text><![CDATA[<meta name="viewport" content="initial-scale=1.0, width=device-width, maximum-scale=1, user-scalable=no" />]]> </text></action>
</block>
</block>
<!-- add GTM block here -->
<block type="core/template" name="gtm" as="after_body_start" template="page/html/gtm.phtml" />
</block>
<block type="core/profiler" output="toHtml" name="core_profiler"/>
</default>
要添加的块将是这样的(请参见上面的代码中的块)
<block type="core/template" name="gtm" as="after_body_start" template="page/html/gtm.phtml" />
您只需要在主题中创建一个新文件:
Magento app design frontend &lt; your_interface&gt; &lt; your_theme&gt; template page pag html gtm.gtm.phtml 将您的gtm代码片段粘贴到gtm.phtml文件中。 在您的页面模板中,例如页面/1column.phtml,您将在开头的主体标签之后找到PHP的摘要: 这是您的GTM代码将在所有页面上添加的地方。<?php echo $this->getChildHtml('after_body_start') ?>