Search code examples
prestashopgtag.js

How to change existing gtag code in prestashop


I have a website which is in Prestashop. There is a gtag code between head tags. I have to replace this code. I looked to ~/www/site/themes/laber_complex_home1/templates/_partials/head.tpl etc. But I didn't see gtag code in here. How can I change it. Is there anywhere where users add custom codes to the head tag. Sorry but I am new prestashop.

{block name='head_charset'}
  <meta charset="utf-8">
{/block}
{block name='head_ie_compatibility'}
  <meta http-equiv="x-ua-compatible" content="ie=edge">
{/block}

{block name='head_seo'}
  <title>{block name='head_seo_title'}{$page.meta.title}{/block}</title>
  <meta name="description" content="{block name='head_seo_description'}{$page.meta.description}{/block}">
  <meta name="keywords" content="{block name='head_seo_keywords'}{$page.meta.keywords}{/block}">
  {if $page.meta.robots !== 'index'}
    <meta name="robots" content="{$page.meta.robots}">
  {/if}
  {if $page.canonical}
    <link rel="canonical" href="{$page.canonical}">
  {/if}
{/block}

{block name='head_viewport'}
  <meta name="viewport" content="width=device-width, initial-scale=1">
{/block}

{block name='head_icons'}
  <link rel="icon" type="image/vnd.microsoft.icon" href="{$shop.favicon}?{$shop.favicon_update_time}">
  <link rel="shortcut icon" type="image/x-icon" href="{$shop.favicon}?{$shop.favicon_update_time}">
{/block}
<script type="text/javascript" src="{$urls.js_url}jquery-1.7.1.min.js"></script>
{block name='stylesheets'}
  {include file="_partials/stylesheets.tpl" stylesheets=$stylesheets}
{/block}

{block name='javascript_head'}
  {include file="_partials/javascript.tpl" javascript=$javascript.head vars=$js_custom_vars}
{/block}
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800i" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:100,100i,300,300i,400,400i,500,500i,700,700i,900,900i" rel="stylesheet">
{block name='hook_header'}
  {$HOOK_HEADER nofilter}
{/block}

{block name='hook_extra'}{/block}
{hook h='displayAdminlabthemeoptions'}

Solution

  • there might be two reasons why you cannot find it there.

    1. it might simply not be the right place
    2. it might be embedded via module

    Search in your entire repo about the string googletagmanager and have a look if the script is somewhere else. In general, the script should be something like this

    {literal} <!-- Global site tag (gtag.js) - Google Analytics -->
        <script async src="https://www.googletagmanager.com/gtag/js?id=UA-*********-*"></script>
        <script>
          window.dataLayer = window.dataLayer || [];
          function gtag(){dataLayer.push(arguments);}
          gtag('js', new Date());
        
          gtag('config', 'UA-*********-*');
        </script>  
    {/literal}
    

    If you cannot find anything, there is a good chance that a third-party module is embedding the script for you. In that case, go to Prestashop back office and click Modules -> Module manager and search for something congruent with Google analytics.