Template-Quelle: core/base/base.html

{% extends "core/base/base.html" %}
{% load i18n l10n hijack_tags canonical_tags %}
{% get_current_language as LANGUAGE_CODE %}

{% block google-analytics %}
    <script>
     {% if GOOGLE_ANALYTICS_ID %}
        var gaProperty = '{{ GOOGLE_ANALYTICS_ID }}';
    {% else %}
        var gaProperty = '{{ GOOGLE_ADWORDS_ID }}';
    {% endif %}

    // Disable tracking if the opt-out cookie exists.
    var disableStr = 'ga-disable-' + gaProperty;
    if (document.cookie.indexOf(disableStr + '=true') > -1) {
      window[disableStr] = true;
    }

    // Opt-out function
    function gaOptout() {
      document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
      window[disableStr] = true;
    }
    </script>

    {% if GOOGLE_ANALYTICS_ID %}
        <script async src="https://www.googletagmanager.com/gtag/js?id={{ GOOGLE_ANALYTICS_ID }}"></script>
    {% else %}
        <script async src="https://www.googletagmanager.com/gtag/js?id={{ GOOGLE_ADWORDS_ID }}"></script>
    {% endif %}
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        {% if GOOGLE_ANALYTICS_ID %}gtag('config', '{{ GOOGLE_ANALYTICS_ID }}');{% endif %}
        {% if GOOGLE_ADWORDS_ID %}gtag('config', '{{ GOOGLE_ADWORDS_ID }}');{% endif %}
    </script>
{% endblock %}