Jump to content
nadie

Free Module - Add code Google Tag Manager in Prestashop 1.7

Recommended Posts

Instruction guide: https://victor-rodenas.com/como-anadir-el-codigo-de-google-tag-manager-en-prestashop/ (in spanish)

For English, use Google translator: https://translate.google.com/translate?sl=es&tl=en&js=y&prev=_t&hl=es&ie=UTF-8&u=https%3A%2F%2Fvictor-rodenas.com%2Fcomo-anadir-el-codigo-de-google-tag-manager-en-prestashop%2F&edit-text=&act=url

displayHeader -> googletag_header.tpl
displayAfterBodyOpeningTag -> googletag_body.tpl

Last Version:  https://victor-rodenas.com/wp-content/uploads/2018/04/googletag.zip

Attachment version 0.0.1 of the module in the forum
 

 

Tested in Prestashop 1.7 (up to Prestashop 1.7.3.1)

Sorry for my English,

googletag.zip

Edited by nadie (see edit history)

Share this post


Link to post
Share on other sites
On 4/17/2018 at 2:48 PM, nadie said:

Instruction guide: https://victor-rodenas.com/como-anadir-el-codigo-de-google-tag-manager-en-prestashop/ (in spanish)

For English, use Google translator: https://translate.google.com/translate?sl=es&tl=en&js=y&prev=_t&hl=es&ie=UTF-8&u=https%3A%2F%2Fvictor-rodenas.com%2Fcomo-anadir-el-codigo-de-google-tag-manager-en-prestashop%2F&edit-text=&act=url

displayHeader -> googletag_header.tpl
displayAfterBodyOpeningTag -> googletag_body.tpl

Last Version:  https://victor-rodenas.com/wp-content/uploads/2018/04/googletag.zip

Attachment version 0.0.1 of the module in the forum
 

 

Tested in Prestashop 1.7 (up to Prestashop 1.7.3.1)

Sorry for my English,

googletag.zip

Hi, 

Thanks for the module. I edit the .tpl files, but I got the error 500. Then I add {literal} and {/literal} to codes and I dont get the error again. but when I check it with tag manager assistance, there are two errors: 

An error occured while the tag was fired: net::ERR_ABORTED
 
Error while sending request: net::ERR_ABORTED
 
What should I do ? 
 
Note that my presta version is 1.7.4.2.
 

Share this post


Link to post
Share on other sites
On 11/4/2018 at 10:52 PM, LaimuX said:

Hi, and what about 1.6 versions? How to manage with Google Tags?

 

did you tried it on 1.6?

Share this post


Link to post
Share on other sites

Thank you!  This is working on my site.

I tweaked this somewhat, but my biggest contributions are this:

In the googletag_body.tpl, ensure you use the literal tag around the script portion.

https://www.smarty.net/docsv2/en/language.function.literal

Second, where the body script is loading now ('displayAfterBodyOpeningTag') is above real content and that is not a great spot if you are focused on the customer and even Google Best Practices.

A better spot, imo, is 'displayBeforeBodyClosingTag'

You need only edit two lines in the PHP file to install that in that location instead, and the description of that Position is: "Use this hook for your modals or any content you want to load at the very end" - Perfect.

Again, thanks for posting this as I was able create my first module with this as the foundation.

Share this post


Link to post
Share on other sites

It is better to use in this case the internal files of prestashop. for example for the file layout-both-columns.tpl which is in themes / classic / templates / layouts.

You add the first google code tag "<script>" (function ...
below the <head> tag

For the second code put it below the <body> tag

 

example:

 

 <head>
   <!-- Google Tag Manager -->
     {literal}
    <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','GTM---------');</script>

    {/literal}
  <!-- End Google Tag Manager -->

 

 <body id="{$page.page_name}" class="{$page.body_classes|classnames}">

    <!-- Google Tag Manager (noscript) -->
    {literal}
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-----------"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    {/literal}
    <!-- End Google Tag Manager (noscript) -->


It avoids installing a module for nothing

 

 

Edited by najtem (see edit history)
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
On 2/1/2019 at 9:36 AM, najtem said:

It is better to use in this case the internal files of prestashop. for example for the file layout-both-columns.tpl which is in themes / classic / templates / layouts.

*snip*


It avoids installing a module for nothing

 

 

My goal is to not modify any of the files that Prestashop provides unless it is the last possible alternative.  "a module for nothing" is a relative statement depending on your deployment methodology.

I ended up going with the CDC GoogleTags Manager from the module store, ultimately, because building out the data structures for all the pages was going to be a huge task compared to the cost of the module.

CDC GoogleTags Manager is working really well, I believe on our site www.greenmeadowmemorials.com - if you look at it with the Google Tag Examiner you can see that they are are at work and upon viewing the source code that the datalayer is present even in categories, which IMO was going to be the time consuming part of the task.  https://www.greenmeadowmemorials.com/metal-cremation-urns - I am thankful this module works as well as it does.

Watch out though, as it splices into your header.tpl and if you update the template or change templates, it breaks the module.  Your best bet is to put the hook into your header.tpl manually and make sure it persists across template updates.

Edited by juchems (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites
On 4/18/2018 at 6:48 AM, nadie said:

Instruction guide: https://victor-rodenas.com/como-anadir-el-codigo-de-google-tag-manager-en-prestashop/ (in spanish)

For English, use Google translator: https://translate.google.com/translate?sl=es&tl=en&js=y&prev=_t&hl=es&ie=UTF-8&u=https%3A%2F%2Fvictor-rodenas.com%2Fcomo-anadir-el-codigo-de-google-tag-manager-en-prestashop%2F&edit-text=&act=url

displayHeader -> googletag_header.tpl
displayAfterBodyOpeningTag -> googletag_body.tpl

Last Version:  https://victor-rodenas.com/wp-content/uploads/2018/04/googletag.zip

Attachment version 0.0.1 of the module in the forum
 

 

Tested in Prestashop 1.7 (up to Prestashop 1.7.3.1)

Sorry for my English,

googletag.zip

Working well in PS1.7.6.0 :)

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

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