Skip to content

Commit

Permalink
Add datalayer and js to header section
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed Jan 23, 2017
1 parent 53c94f0 commit d959e71
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"magento/framework": "100.0.*|100.1.*"
},
"type": "magento2-module",
"version": "1.2.2",
"version": "1.2.3",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MagePal_GoogleTagManager" setup_version="1.2.2">
<module name="MagePal_GoogleTagManager" setup_version="1.2.3">
<sequence>
<module name="Magento_Store"/>
</sequence>
Expand Down
7 changes: 5 additions & 2 deletions view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="after.body.start">
<block class="MagePal\GoogleTagManager\Block\Tm" name="magepal_gtm_datalayer" as="magepal_gtm_datalayer" template="data_layer.phtml" />
<block class="MagePal\GoogleTagManager\Block\GtmCode" name="gtm_code" as="gtm_code" template="gtm_code.phtml" />
<block class="MagePal\GoogleTagManager\Block\GtmCode" name="gtm_iframe" as="gtm_iframe" template="MagePal_GoogleTagManager::iframe.phtml" />
</referenceContainer>
<referenceBlock name="head.additional">
<block class="MagePal\GoogleTagManager\Block\Tm" name="magepal_gtm_datalayer" as="magepal_gtm_datalayer" template="MagePal_GoogleTagManager::data_layer.phtml" />
<block class="MagePal\GoogleTagManager\Block\GtmCode" name="gtm_js" as="gtm_js" template="MagePal_GoogleTagManager::js.phtml" />
</referenceBlock>
</body>
</page>
2 changes: 1 addition & 1 deletion view/frontend/templates/data_layer.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
?>

<script>
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
<?php /** @var $block \MagePal\GoogleTagManager\Block\Tm **/ ?>
<?php echo $block->getGtmTrackingCode(); ?>
Expand Down
15 changes: 15 additions & 0 deletions view/frontend/templates/iframe.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* MagePal Google Tag Manager for Magento 2
*
* Copyright © 2016 MagePal. All rights reserved.
* See COPYING.txt for license details.
*/
?>
<?php /** @var $block \MagePal\GoogleTagManager\Block\Tm **/ ?>
<?php $accountId = $block->getAccountId(); ?>

<!-- Google Tag Manager by MagePal -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=<?php echo $accountId ?>"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager by MagePal -->
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<?php $accountId = $block->getAccountId(); ?>

<!-- Google Tag Manager by MagePal -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=<?php echo $accountId ?>"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
Expand Down

0 comments on commit d959e71

Please sign in to comment.