Jump to content

Recommended Posts

Hey!

Ive tried to find a free module to integrate GTM into PS and couldnt find one. So I've created one.

Here it is - https://github.com/MSiliunas/Prestashop-GoogleTagManager

What does it do?

  • Has configuration screen in back office where you enter your gtm id;
  • Adds gtm tags in <head> section and before <body> closing tag (as per Google recommendation);

Any comments, ideas and pull requests are more than welcome!

Edited by MSiliunas
update description (see edit history)
  • Like 3

Share this post


Link to post
Share on other sites
  • 3 weeks later...
  • 3 weeks later...

Thanks a lot @MSiliunas for your module. I very much appreciate it. So far I had GTM hardcoded in my files but with your module I'll change it.
Tell me, I've recognized that you added the <noscript> part before the closing </body> tag. On purpouse?
I am just asking because according to GTM implementation this code should be added just after the opening <body> tag.
 

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

 

  • Haha 1

Share this post


Link to post
Share on other sites
  • 4 weeks later...

@MSiliunas I just found out that GTM is not active anymore on the checkout. Therefore it is not tracking anything on the whole checkout, no revenue, just nothing.
Any idea? If you want to check it on my test environment go to playground.merkado.ch.

Your feedback & help is highly appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites
  • 5 months later...
  • 2 weeks later...
  • 2 weeks later...
  • 4 months later...

@henrique.signed : the module is wrote for PS 1.7.1 min.
You can edit the file msiliunas_googletagmanager.php and change the line 23

        $this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_);

To

        $this->ps_versions_compliancy = array('min' => '1.6.0.0', 'max' => _PS_VERSION_);

I do not test, so not sure it works.

Share this post


Link to post
Share on other sites

@mamascotte : I change the TPL file /views/templates/hook/header.tpl like this :

So, I put total amount HT in value for conversion.
For transaction_id : I use address id delivery, because cart id is not available.
It's not the best... but it's the simplest.

 

{if isset($gtm_id) && $gtm_id && isset($cart.totals.total_excluding_tax.amount)}
<!-- Global site tag (gtag.js) - Google Ads: gtmId -->
{literal}
<script async src="https://www.googletagmanager.com/gtag/js?id={/literal}{$gtm_id}{literal}"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', '{/literal}{$gtm_id}{literal}');
</script>
<!-- Event snippet for conversion page -->
<script>
  gtag('event', 'conversion', {
      'send_to': '{/literal}{$gtm_id}{literal}/hyTfCKabjsYBEPOzpOoD',
      'value': {/literal}{$cart.totals.total_excluding_tax.amount|replace:',':'.'}{literal},
      'currency': '{/literal}{$currency.iso_code}{literal}',
      'transaction_id': '{/literal}{if isset($cart.id_address_delivery)}{$cart.id_address_delivery}{/if}{literal}'
  });
</script>
{/literal}
{/if}

 

Share this post


Link to post
Share on other sites
  • 5 months later...
  • 3 months later...
On 10/1/2019 at 11:36 AM, mamascotte said:

Hello

Plugin does not work anymore ... it seems that URL offered is not the right one anymore : https://www.googletagmanager.com/gtm.js?id=xxxxx => GTM is replaced by GTAG https://www.googletagmanager.com/gtag/js?id=xxxx

Can you please tell me how to change in your module ?

Thanks

Just for future reference ‚Äď this is not true.

gtm and gtag are different products as stated here: https://support.google.com/tagmanager/answer/7582054?hl=en

Share this post


Link to post
Share on other sites
On 10/10/2019 at 1:33 PM, henrique.signed said:

I install on version 1.6.0.14 but after successful installation, the module does not appear¬†ūüėě

The module uses a hook that is only supported in 1.7.x. There is a PR for 1.6 version on github.

Share this post


Link to post
Share on other sites

Does it work on PS 1.7.7.0 ?

I think the code was just changed by Google like this: 

 

Install Google Tag Manager

Copy the code below and paste it onto every page of your website.

Paste this code as high in the <head> of the page as possible:

<!-- 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','GTM-PXSCPLJ');</script>
<!-- End Google Tag Manager -->

Additionally, paste this code immediately after the opening <body> tag:

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

For more information about installing the Google Tag Manager snippet, visit our Quick Start Guide .

Share this post


Link to post
Share on other sites
  • 1 month later...

Bonjour 

je rencontre un problème avec ce module. Je n'arrive pas à recupérer les variables $gtm_id dans mes templates du coup cette variable est considérer comme un caractère dans head.tpl et body.tpl.

 

image.png.ff0f63ea7e9385c57f7ecd3a054e2b47.png

Share this post


Link to post
Share on other sites

Hello

I am having a problem with this module. I can't get the $ gtm_id variables in my templates so this variable is considered a character in head.tpl and body.tpl.

 

image.thumb.png.f00de77cd46b21d783e1caa99a42d0f3.png

Share this post


Link to post
Share on other sites
On 1/27/2021 at 4:18 PM, ApNiklaus said:

Bonjour 

je rencontre un problème avec ce module. Je n'arrive pas à recupérer les variables $gtm_id dans mes templates du coup cette variable est considérer comme un caractère dans head.tpl et body.tpl.

 

image.png.ff0f63ea7e9385c57f7ecd3a054e2b47.png

 

On 1/27/2021 at 4:39 PM, ApNiklaus said:

Hello

I am having a problem with this module. I can't get the $ gtm_id variables in my templates so this variable is considered a character in head.tpl and body.tpl.

 

image.thumb.png.f00de77cd46b21d783e1caa99a42d0f3.png

 

You have to edit "modules/msiliunas_googletagmanager/views/templates/hook/body.tpl"

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

 

and "modules/msiliunas_googletagmanager/views/templates/hook/header.tpl"

{if isset($gtm_id) && $gtm_id}
{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',{/literal}'{$gtm_id}'{literal});</script>
<!-- End Google Tag Manager -->
{/literal}  
{/if}

 

  • Like 1

Share this post


Link to post
Share on other sites
  • 2 weeks later...

Hello MSiliunas!

Thanks a lot for sharing your work!

It seems that this modul is very useful. I am not familiar with programming...

Is it possible to get a link to zip file for PrestaShop 1.7.6.3?

Thanks a lot in advance!

Kate

 

Share this post


Link to post
Share on other sites

Hi! Thanks for your module, @MSiliunas.

The module is working, but I think now in a very basic way. What about adding events for main PS actions? For example, when adding a product to cart, or confirming an order, registering a new user, ....

It would be great to add variables and events to dataLayer, using PS hooks. If you are interested in it, maybe we can help improving module features.

Share this post


Link to post
Share on other sites
  • 3 weeks later...
On 1/27/2021 at 5:39 PM, ApNiklaus said:

Hello

I am having a problem with this module. I can't get the $ gtm_id variables in my templates so this variable is considered a character in head.tpl and body.tpl.

 

image.thumb.png.f00de77cd46b21d783e1caa99a42d0f3.png

@ApNiklaus @maccio you don't have to edit nothing. just don't use the archive on the zip .  archive the folder as is says in documentation.

please look at first issue as well on git https://github.com/MSiliunas/Prestashop-GoogleTagManager/issues/4

 

 

 

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

Important Information

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