Google analytic has version 4, which should be complemented with version 3, i.e. the code of version 4 is inserted and the other code from version 3 is added -> this is an important thing, that in this new version there is also the code of version 3.
Adding a new GA version, i.e. version 4, always comes with adding new conversions to final.latte (only if it is an e-shop) -> the procedure for adding conversions can be found here: https://wiki.czechgroup.cz/admin/menuitem/208.
We never overwrite existing code that is stored in translations (meaning only in translations, we can normally overwrite old code that is mostly in @layout.latte) on the web unless explicitly requested.
You can find the possibility to view e.g. the projects Briol, Runsport, Floristika
Process:
- the following code needs to be inserted into @layout.latte for Front (for understanding: due to the reason of enclosing into a subcondition and sometimes loading via ajax, the configs have to be put into an instantly called function, which results in loading under any conditions)
{if isset($web['GOOGLE_ANALYTICS']) && strlen($web['GOOGLE_ANALYTICS']) > 1 && (isset($cookieSettings, $cookieSettings['cookie_analytics']) || !isset($cookieSettings))} <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id={$web['GOOGLE_ANALYTICS']}"></script> <script> window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } (function () { gtag('js', new Date()); gtag('config', {$web['GOOGLE_ANALYTICS']}); })(); </script> {/if} - then it is necessary to wrap this code above in {snippet cookiesb} {/snippet} (or change the name of the snippet if cookiesb is already used) and then add {include './remarketing.latte'} to the snippet (if it is already present on the page in @layout.latte, then it is necessary to move it) -> it is important that it is above the initialization of the gtag code that is being added.
- for each additional analytics code it is necessary to add under gtag('config', {$web['GOOGLE_ANALYTICS']}); another config in this format (this way it is possible to add as many tags as you want, only each code must be added only once):
{if !empty($web['GOOGLE_ANALYTICS_SEC'])} gtag('config', {$web['GOOGLE_ANALYTICS_SEC']}); {/if}<script src="https://www.googletagmanager.com/gtag/js?id={$web['GOOGLE_ANALYTICS']}"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){ dataLayer.push(arguments); } (function () { gtag('js', new Date()); gtag('config', {$web['GOOGLE_ANALYTICS']}); {if !empty($web['GOOGLE_ANALYTICS_SEC'])} gtag('config', {$web['GOOGLE_ANALYTICS_SEC']}); {/if} })(); </script> - You also need to add all the translations to language mutation and set the correct GA tags.
Testing is then done on the live version after checking with someone sitting at analytics and checking if it works. This is usually done by the person who checks MR.