When we create an online shop with Shopware, a customer may request that Google Tag Manager be integrated as a supporting tool for online marketing. There are extensions available for this, but for technicians, doing it manually is basically easier and faster and generally does not result in compatibility issues or the need to make adjustments after updates. In principle, changes in just 2 places in Shopware are enough to make the online shop ready for Google Tag Manager.
First, we modify the file
themes/Frontend/DEINTHEMENAME/frontend/index/header.tpl
and add the following:
{literal}
<!-- Google Tag Manager -->
<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=
})(window,document,'script','dataLayer','DEINGOOGLETAGMANAGERCODE');</script>
<!-- End Google Tag Manager -->
{/literal}
We assume here that the header.tpl has already been created and configured ({extends file="parent:frontend/index/header.tpl"} etc.) and that the changes need to be made in the section {block name="frontend_index_header_javascript_tracking"}.
We then modify the file
themes/Frontend/DEINTHEMENAME/frontend/index/index.tpl
and add the following instruction:
{block name='frontend_index_after_body'}
{literal}
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=DEINGOOGLETAGMANAGERCODE"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
{/literal}
{/block}
That is all that is required to integrate Tag Manager into our online shop. Seen at our web agency in Shopware PE 5.5.8.
