INFO: Version en.xStandard

Google Analytics

With Google Analytics, you can analyze the traffic to your website and monitor the activities on your pages in real time. General information on the Google Analytics tool can be found via the links at the end of the article.

Weblication® CMS offers you an easy way to integrate the required tracking code into your websites. In BASE projects, the tracking snippet is already stored in the output template. This makes it easy to use Google Analytics via the output template. You only need to store the ID in the project configuration. The template is prepared for Google Consent Mode V2 and the parameters are generally set to reject everything by default (see script excerpt below).

Please note that either the Google Analytics or the Tag Manager script according to Google may be integrated (not both at the same time) and therefore either the Google Analytics ID or the Tag Manager ID should be stored in the project configuration.

Project configuration - Analysis - Google Analytics
Project configuration - Analysis - Google Analytics

If a Google Analytics ID is stored in the project configuration, the tracking code is generated with this ID in the pages for users who are not logged in (site visitors).

The display template used for the web pages (e.g. standard.wDocument.php) includes the templates for the tracking codes at the end. This is stored in a global template and defines the required source code (JavaScript), which is generated with the specified ID for the output. With regard to Google Consent Mode V2, adjust the values in the template as required for your project. General information on this can be found in the Google documentation, for which various articles are already linked at the bottom of the page.

Beispiel: Auszug aus /[IHR-GLOBALES-PROJEKT]/wGlobal/layout/templates/globals/googleAnalytics.wGlobal.php

...
  <!-- Tracking Code für Google Analytics -->

  <xsl:template name="googleAnalytics">
    
    <xsl:if test="$wUsertype != 'admin' and $wUsertype != 'standard'">     
      <script>
        var confirmTypes       = '<xsl:value-of select="php:functionString('wVariables::getValue', 'confirm_cookie_types', $wGlobalProjectPath, '')"/>';
        var confirmBeforeTrack = '<xsl:value-of select="php:functionString('wVariables::getValue', 'confirm_before_track', $wGlobalProjectPath, '')"/>';
        if(confirmTypes != 'yes' &amp;&amp; confirmBeforeTrack != 'yes' || document.cookie.indexOf('allowTracking=1') != -1 || /Google-AdWords-Express/i.test(navigator.userAgent)){
          window['gaId'] = '<xsl:value-of select="php:functionString('wVariables::getValue', 'googleAnalytics_id', $wGlobalProjectPath)"/>';

          if(document.cookie.indexOf('disableGoogleAnalytics=1') != -1){
            window['ga-disable-' + window['gaId']] = true;
          }
          else if(window['gaId'].substr(0, 2) == 'G-' || window['gaId'].substr(0, 3) == 'AW-'){
            (function(i,s,o,g){a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
            })(window,document,'script','https://www.googletagmanager.com/gtag/js?id='+window['gaId']);        
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            /* For more information on the following parameters, see: https://developers.google.com/tag-platform/security/guides/consent?hl=de&amp;consentmode=advanced) */
            gtag('consent', 'default', {
              'ad_storage': 'granted',          // Anzeigenbezogenes Tracking erlauben (granted) oder nicht erlauben (denied)
              'ad_user_data': 'denied',        // Nutzerdaten für Anzeigen erlauben (granted) oder nicht erlauben (denied)
              'ad_personalization': 'denied',   // Anzeigen personalisieren erlauben (granted) oder nicht erlauben (denied)
              'analytics_storage': 'granted'     // Analytics-Cookies und Tracking erlauben (granted) oder nicht erlauben (denied)
            });
            gtag('js', new Date());
            gtag('config', window['gaId']);
          }
          else{
            (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
            })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

            ga('create', window['gaId'], 'auto');
            ga('set', 'anonymizeIp', true);
            //ga('require', 'linkid', 'linkid.js');
            ga('send', 'pageview');
          }
        }
      </script>
    </xsl:if>  
  </xsl:template>
...

Please note

  • The JavaScript is only generated in the web pages if the page visitor is not logged in as a Weblication® user (user type administrator or maintenance user) and a Google Analytics ID is stored in the project configuration.
  • By default, the code of the tracking snippet is delivered in such a way that the IP addresses are anonymized. Check this in your project for data protection reasons!