Jump to content

Adding Google Tag Manager code to Prestashop 1.7


Pvv

Recommended Posts

Hello. 

 

I am trying to add a google tag manager code to my prestashop 1.7 installation and all the instructions are saying that i should edit the header.tpl file in head and body. but the header.tpl file does not have any head and body parts of code, only a lot of divs.

 

Has anyone had any experience with this?  

Link to comment
Share on other sites

  • 1 month later...

you really dont

 

No one with an idea?

I can't believe that we are forced to buy a module  :)

 

you really don't :) Simply paste your script to themes/classic/templates/_partials/head.tpl. Don't forget to include <script> tag. And clear cache after you edit the template file. Example:

 

{block name='javascript_head'}
  {include file="_partials/javascript.tpl" javascript=$javascript.head vars=$js_custom_vars}
{/block}


<script type="text/javascript">
  // your google tag manager init script goes here
</script>


{block name='hook_header'}
  {$HOOK_HEADER nofilter}
{/block}
Edited by DataKick (see edit history)
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

 

you really dont

 

 

you really don't :) Simply paste your script to themes/classic/templates/_partials/head.tpl. Don't forget to include <script> tag. And clear cache after you edit the template file. Example:

 

{block name='javascript_head'}
  {include file="_partials/javascript.tpl" javascript=$javascript.head vars=$js_custom_vars}
{/block}


<script type="text/javascript">
  // your google tag manager init script goes here
</script>


{block name='hook_header'}
  {$HOOK_HEADER nofilter}
{/block}

 

 

Dear DataKick,

 

Thanks for your reply, the google tag manager needs to put two scripts:

 

1) in section HEAD

1) in section BODY

 

 

Have you any info where is bettere to put the part dedicated for the body

 

Thanks and Regard

Edited by Web Curator (see edit history)
Link to comment
Share on other sites

Dear DataKick,

 

Thanks for your reply, the google tag manager needs to put two scripts:

 

1) in section HEAD

1) in section BODY

 

 

Have you any info where is bettere to put the part dedicated for the body

 

Thanks and Regard

 

you could try to add this to  themes/classic/templates/_partials/header.tpl

 

Alternatively, you can add both scripts to layout file - themes/classic/templates/layouts/layout-both-columns.tpl (or whatever layout/theme you are using)

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

I suggest to make this steps:

 

1) REMOVE THE COMMENTS

 

<!-- Google Tag Manager -->

<!-- End Google Tag Manager -->

 

2) open a tag {literal} and close it at the end of each snipplet {/literal}

{literal}

    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=XXXXXXX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>

{/literal}

3) Insert in: head.tpl  (and not header.tpl) one part and the other in layout-both-columns.tpl

 

4) Check if everything is fine via the Chrome Add-on Google-Tag-Assistent 

  • Like 3
  • Thanks 2
Link to comment
Share on other sites

  • 2 months later...

I suggest to make this steps:

 

1) REMOVE THE COMMENTS

 

<!-- Google Tag Manager -->

<!-- End Google Tag Manager -->

 

2) open a tag {literal} and close it at the end of each snipplet {/literal}

{literal}

    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=XXXXXXX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>

{/literal}

3) Insert in: head.tpl  (and not header.tpl) one part and the other in layout-both-columns.tpl

 

4) Check if everything is fine via the Chrome Add-on Google-Tag-Assistent 

 

To include the two .js you can create a custom module that implement two hooks :

displayHeader (to add js in header)

displayAfterBodyOpeningTag (to add js in body)

 

Then :

You should create two templates files(.tpl) : 1 per js

for each tpl, copy/paste the GTM js code following step 1 and step 2 above

 

In your module configuration file, you just have to implement the two hooks by returning the two tpl :

return $this->fetch(YOUR_TPL_PATH);

Link to comment
Share on other sites

  • 11 months later...
2 minutes ago, Knowband Plugins said:

Did you check the same in other browser & system?

Search the NET ABORTED Google Tag manager issue in the Google & you can find many help link to diagnose the same like

http://mixedanalytics.com/blog/tag-assistant-error-occurred-while-tag-fired/

 

Some people said its not an error to worry about as its just different order of triggers. So We  have fixed it by just adding a tag in the tag manager and publishing it and the it all worked fine - if its helpful for anyone!

Link to comment
Share on other sites

  • 3 months later...
  • 5 years later...
On 6/6/2017 at 3:06 PM, Web Curator said:

I suggest to make this steps:

 

1) REMOVE THE COMMENTS

 

<!-- Google Tag Manager -->

<!-- End Google Tag Manager -->

 

2) open a tag {literal} and close it at the end of each snipplet {/literal}

{literal}

    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=XXXXXXX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>

{/literal}

3) Insert in: head.tpl  (and not header.tpl) one part and the other in layout-both-columns.tpl

 

4) Check if everything is fine via the Chrome Add-on Google-Tag-Assistent 

Confirmed working still in Prestashop 8.1.4 for anyone landing here.
No need for modules to include GTM script (although the suggestion after above comment is valid)
 

Link to comment
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
×
×
  • Create New...