Jump to content

How to insert Google Tag Manager code


Hedera
 Share

Recommended Posts

Hi,

 

Can you please help me with Google Tag Manager.

I need to insert a code before <body id="index">

 

 

Unfortunately I do not know how. I inserted in header.tpl and footer.tpl, but is is always shown after body tag in source code.

 

Thank you for your help.

 

Best,

Ivan

Share this post


Link to post
Share on other sites

Here it is (Google code is on top) in between {literal}:

 

START OF THE DOCUMENT

 

{literal}

 

<!-- Google Tag Manager -->

<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-F2AK"

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=

'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);

})(window,document,'script','dataLayer','GTM-F5BK');</script>

<!-- End Google Tag Manager -->

 

{/literal}

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{$lang_iso}">

<head>

<title>{$meta_title|escape:'htmlall':'UTF-8'}</title>

{if isset($meta_description) AND $meta_description}

<meta name="description" content="{$meta_description|escape:html:'UTF-8'}" />

{/if}

{if isset($meta_keywords) AND $meta_keywords}

<meta name="keywords" content="{$meta_keywords|escape:html:'UTF-8'}" />

{/if}

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />

<meta name="generator" content="PrestaShop" />

<meta name="robots" content="{if isset($nobots)}no{/if}index,follow" />

<link rel="icon" type="image/vnd.microsoft.icon" href="{$img_ps_dir}favicon.ico?{$img_update_time}" />

<link rel="shortcut icon" type="image/x-icon" href="{$img_ps_dir}favicon.ico?{$img_update_time}" />

<script type="text/javascript">

var baseDir = '{$content_dir}';

var static_token = '{$static_token}';

var token = '{$token}';

var priceDisplayPrecision = {$priceDisplayPrecision*$currency->decimals};

var priceDisplayMethod = {$priceDisplay};

var roundMode = {$roundMode};

</script>

{if isset($css_files)}

{foreach from=$css_files key=css_uri item=media}

<link href="{$css_uri}" rel="stylesheet" type="text/css" media="{$media}" />

{/foreach}

{/if}

<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>

{if isset($js_files)}

{foreach from=$js_files item=js_uri}

<script type="text/javascript" src="{$js_uri}"></script>

{/foreach}

{/if}

{$HOOK_HEADER}

<script type="text/javascript" src="{$js_dir}cookies.js"></script>

<script type="text/javascript" src="{$js_dir}script.js"></script>

</script> <script type="text/javascript" src="{$js_dir}jscript_xjquery.jqtransform.js"></script>

</head>

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}>

<!--[if lt IE 8]><div style='clear:both;height:59px;padding:0 15px 0 15px;position:relative;z-index:10000;text-align:center;'><a href="http://www.microsoft.com/windows/internet-explorer/default.aspx?ocid=ie6_countdown_bannercode"><img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." /></a></div><![endif]-->

{if !$content_only}

{if isset($restricted_country_mode) && $restricted_country_mode}<div id="restricted-country"><p>{l s='You cannot place a new order from your country.'} <span class="bold">{$geolocation_country}</span></p></div>{/if}

<p id="back-top"> <a href="#top"><span></span></a> </p>

<div id="wrapper1">

<div id="wrapper2">

<div id="wrapper3">

<!-- Header -->

<div id="header">

<a id="header_logo" href="{$link->getPageLink('index.php')}" title="{$shop_name|escape:'htmlall':'UTF-8'}">

<img class="logo" src="{$img_ps_dir}logo.jpg?{$img_update_time}" alt="{$shop_name|escape:'htmlall':'UTF-8'}" />

</a>

<div id="header_right">

{$HOOK_TOP}

</div>

</div>

<div id="columns">

<!-- Left -->

<div id="left_column" class="column">

{$HOOK_LEFT_COLUMN}

</div>

<!-- Center -->

<div id="center_column" class="center_column">

{/if}

 

END OF THE DOCUMENT

Share this post


Link to post
Share on other sites

Like Alexander said, why do you want it outside <body> tag, Google specifically mention to insert the code immediately after the opening <body> tag, which mean inside the <body>.

 

If you do want to insert a code before the <body> tag, you can just put it before </head>.

  • Like 1

Share this post


Link to post
Share on other sites

  • 1 year later...
  • 6 months later...
  • 7 months later...

as jasonhar wrote

 

only correct placement of GTM tag is right after <body> tag

 

regards, milan

 

 

START OF THE DOCUMENT
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR...D/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{$lang_iso}">
<head>
<title>{$meta_title|escape:'htmlall':'UTF-8'}</title>
{if isset($meta_description) AND $meta_description}
<meta name="description" content="{$meta_description|escape:html:'UTF-8'}" />
{/if}
{if isset($meta_keywords) AND $meta_keywords}
<meta name="keywords" content="{$meta_keywords|escape:html:'UTF-8'}" />
{/if}
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<meta name="generator" content="PrestaShop" />
<meta name="robots" content="{if isset($nobots)}no{/if}index,follow" />
<link rel="icon" type="image/vnd.microsoft.icon" href="{$img_ps_dir}favicon.ico?{$img_update_time}" />
<link rel="shortcut icon" type="image/x-icon" href="{$img_ps_dir}favicon.ico?{$img_update_time}" />
<script type="text/javascript">
var baseDir = '{$content_dir}';
var static_token = '{$static_token}';
var token = '{$token}';
var priceDisplayPrecision = {$priceDisplayPrecision*$currency->decimals};
var priceDisplayMethod = {$priceDisplay};
var roundMode = {$roundMode};
</script>
{if isset($css_files)}
{foreach from=$css_files key=css_uri item=media}
<link href="{$css_uri}" rel="stylesheet" type="text/css" media="{$media}" />
{/foreach}
{/if}
<link href='http://fonts.googlea...amily=Open Sans' rel='stylesheet' type='text/css'>
{if isset($js_files)}
{foreach from=$js_files item=js_uri}
<script type="text/javascript" src="{$js_uri}"></script>
{/foreach}
{/if}
{$HOOK_HEADER}
<script type="text/javascript" src="{$js_dir}cookies.js"></script>
<script type="text/javascript" src="{$js_dir}script.js"></script>
</script> <script type="text/javascript" src="{$js_dir}jscript_xjquery.jqtransform.js"></script> 
</head>
<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}>
{literal}
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-F2AK"
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=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-F5BK');</script>
<!-- End Google Tag Manager -->
{/literal}
<!--[if lt IE 8]><div style='clear:both;height:59px;padding:0 15px 0 15px;position:relative;z-index:10000;text-align:center;'><a href="http://www.microsoft...annercode"><img src="http://storage.ie6co...ar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." /></a></div><![endif]-->
{if !$content_only}
{if isset($restricted_country_mode) && $restricted_country_mode}<div id="restricted-country"><p>{l s='You cannot place a new order from your country.'} <span class="bold">{$geolocation_country}</span></p></div>{/if}
<p id="back-top"> <a href="#top"><span></span></a> </p>
<div id="wrapper1">
<div id="wrapper2">
<div id="wrapper3">
<!-- Header -->
<div id="header">
<a id="header_logo" href="{$link->getPageLink('index.php')}" title="{$shop_name|escape:'htmlall':'UTF-8'}">
<img class="logo" src="{$img_ps_dir}logo.jpg?{$img_update_time}" alt="{$shop_name|escape:'htmlall':'UTF-8'}" />
</a>
<div id="header_right">
{$HOOK_TOP}
</div>
</div>
<div id="columns">
<!-- Left -->
<div id="left_column" class="column">
{$HOOK_LEFT_COLUMN}
</div>
<!-- Center -->
<div id="center_column" class="center_column">
{/if}
 
END OF THE DOCUMENT 

Share this post


Link to post
Share on other sites

THANKS FOR THE COMMENT,

 

It is fixed now,

 

the issue was that; I missed the {literal} ... {/literal} from the beginning and end of the insert. putting that in place made it work.

 

thanks,

Share this post


Link to post
Share on other sites

  • 2 months later...

At the end I found the solution to make GTM code be detected by tag assistant and of course, working.

It's really important that the given code to be placed between {literal} & {/literal} and leave NO spaces or "tabs" from the other code in header.tpl

 

Hope it helps somebody...

Share this post


Link to post
Share on other sites

  • 1 month later...

Hi, i install the code of Google Tag manager in header.tlp


 


and i have an error: HTTP response code indicates tag failed fire: Status 404


 


{literal}

<!-- Google Tag Manager -->

<noscript><iframe src="//www.googletagmanager.com/ns.html?id=XXXXXX"

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=

'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);

})(window,document,'script','dataLayer','XXXXXX');</script>

<!-- End Google Tag Manager -->

{/literal}

 

Any help? My site is http://www.skyway.mx

Share this post


Link to post
Share on other sites

hi

have done the steps mentioned on Google ?

 

The ID should be set to your ID it should not be left as XXXXX, i guess it is in two places in the same phrase.

 

Also it is important to exactly place the code after <body> opening tag, it can be a lengthy one like <body ........... ..... /> HERE the google code should be located starting with {literlal}

 

check again and make sure all steps as written on google site are followed it should work.

 

good luck

Share this post


Link to post
Share on other sites

  • 6 months later...
  • 9 months later...
  • 1 year later...

It's an older thread so maybe this was good before, but nowadays: Tag manager code should be put in the HEAD tag, the further up the better. There's an additional but optional code that should be but right AFTER the body tag. But the main snippet goes into the head, not the body ;) And especially not right before the body tag!

Share this post


Link to post
Share on other sites

On 3/14/2017 at 5:05 PM, softhightech said:

just put your code inside  {literal}your google tag manager here {/literal}

Cool that you know a way, maybe be more specific about where and how to do so, so everyone could follow?

Share this post


Link to post
Share on other sites

  • 1 year later...

where is correct placement of GTM tag is right after <head> tag?

 

-->
<html{if isset($language_code) && $language_code} lang="{$language_code|escape:'html':'UTF-8'}"{/if}>
    <head>
        {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=
                        'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
                })(window,document,'script','dataLayer',xxxx');</script>
            <!-- End Google Tag Manager -->
        {/literal}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More