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. All you need to do is enter the Google Analytics ID 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 includes.global.php and defines the required source code (JavaScript), which is generated with the specified ID for the output.

Beispiel: Auszug aus /[IHR-GLOBALES-PROJEKT]/wGlobal/layout/templates/misc/includes.global.php zu Google Analytics

...
  <!-- HTML-Header -->
  <xsl:template name="htmlHeader" wChecksum="fee24c1a5e922c98c3fe4baeb1794a69">
    ...
    ...
    <!-- Falls Google Analytics aktiviert ist -->
    <xsl:if test="php:functionString('wVariables::getValue', 'googleAnalytics_id', $wGlobalProjectPath) != ''">      
      <xsl:call-template name="googleAnalytics"/>
    </xsl:if>  

  </xsl:template>
...
...
  <!-- Tracking Code für Google Analytics -->
  <xsl:template name="googleAnalytics">
    <xsl:if test="$wUsertype != 'admin' and $wUsertype != 'standard'">    
      <script>
        
        var confirmBeforeTrack = '<xsl:value-of select="php:functionString('wVariables::getValue', 'confirm_before_track', $wGlobalProjectPath, '')"/>';
        if(confirmBeforeTrack != 'yes' || document.cookie.indexOf('allowTracking=1') != -1){
          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{
            (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!