Commit df351c09 authored by Joachim Feltkamp's avatar Joachim Feltkamp
Browse files

Issue #3200980 by kirkkala, bmunslow: GTM script duplicating after accepting the cookies

parent 2c1c50f6
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
/**
 * @file
 * Defines Javascript behaviors for the cookies module.
 */;

 */
(function (Drupal) {
  'use strict';

  /**
   * Define defaults.
   */
  Drupal.behaviors.cookies_ga = {
  Drupal.behaviors.cookiesGa = {

    activate: function () {
      var scriptIds = [
@@ -24,7 +23,7 @@
          var attributes = Array.from(script.attributes);
          for (var attr in attributes) {
            var name = attributes[attr].nodeName;
            if (name !== 'type') {
            if (name !== 'type' && name !== 'id') {
              newScript.setAttribute(name, attributes[attr].nodeValue);
            }
          }
@@ -38,10 +37,10 @@
      var self = this;
      document.addEventListener('cookiesjsrUserConsent', function (event) {
        var service = (typeof event.detail.services === 'object') ? event.detail.services : {};
        if (typeof service['analytics'] !== 'undefined' && service['analytics']) {
        if (typeof service.analytics !== 'undefined' && service.analytics) {
          self.activate(context);
        }
      });
    }
  }
  };
})(Drupal);
+5 −5
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
  /**
   * Define defaults.
   */
  Drupal.behaviors.cookies_gtag = {
  Drupal.behaviors.cookiesGtag = {

    activate: function () {
      var $script = $('script#cookies_gtag');
@@ -17,22 +17,22 @@
        var newScript = document.createElement('script');
        newScript.innerHTML = this.innerHTML;
        $.each(this.attributes, function( index, attr ) {
          if (attr.name !== 'type') {
          if (attr.name !== 'type' && attr.name !== 'id') {
            newScript.setAttribute(attr.name, attr.value);
          }
        });
        this.parentNode.replaceChild(newScript, this);
      })
      });
    },

    attach: function (context) {
      var self = this;
      document.addEventListener('cookiesjsrUserConsent', function (event) {
        var service = (typeof event.detail.services === 'object') ? event.detail.services : {};
        if (typeof service['gtag'] !== 'undefined' && service['gtag']) {
        if (typeof service.gtag !== 'undefined' && service.gtag) {
          self.activate(context);
        }
      });
    }
  }
  };
})(Drupal, jQuery);
+9 −6
Original line number Diff line number Diff line
/**
 * @file
 * Defines Javascript behaviors for the cookies module.
 */;

 */
(function (Drupal, $) {
  'use strict';

  /**
   * Define defaults.
   */
  Drupal.behaviors.cookies_instagram = {
  Drupal.behaviors.cookiesInstagram = {

    id: 'instagram',

@@ -26,8 +25,12 @@
          var src = script.getAttribute('src');
          var newScript = document.createElement('script');
          newScript.setAttribute('id', id);
          if (src) newScript.setAttribute('src', src)
          else newScript.innerHTML = script.innerHTML;
          if (src) {
            newScript.setAttribute('src', src);
          }
          else {
            newScript.innerHTML = script.innerHTML;
          }
          // Replace script.
          script.parentNode.replaceChild(newScript, script);
        }
@@ -51,5 +54,5 @@
        }
      });
    }
  }
  };
})(Drupal, jQuery);
+4 −5
Original line number Diff line number Diff line
/**
 * @file
 * Defines Javascript behaviors for the cookies module.
 */;

 */
(function (Drupal) {
  'use strict';

  /**
   * Define defaults.
   */
  Drupal.behaviors.cookies_ivw = {
  Drupal.behaviors.cookiesIvw = {

    activate: function () {
      var scriptIds = [
@@ -37,10 +36,10 @@
      var self = this;
      document.addEventListener('cookiesjsrUserConsent', function (event) {
        var service = (typeof event.detail.services === 'object') ? event.detail.services : {};
        if (typeof service['ivw'] !== 'undefined' && service['ivw']) {
        if (typeof service.ivw !== 'undefined' && service.ivw) {
          self.activate(context);
        }
      });
    }
  }
  };
})(Drupal);
+4 −5
Original line number Diff line number Diff line
/**
 * @file
 * Defines Javascript behaviors for the cookies module.
 */;

 */
(function (Drupal) {
  'use strict';

  /**
   * Define defaults.
   */
  Drupal.behaviors.cookies_matomo = {
  Drupal.behaviors.cookiesMatomo = {

    activate: function () {
      var scriptIds = [
@@ -37,10 +36,10 @@
      var self = this;
      document.addEventListener('cookiesjsrUserConsent', function (event) {
        var service = (typeof event.detail.services === 'object') ? event.detail.services : {};
        if (typeof service['matomo'] !== 'undefined' && service['matomo']) {
        if (typeof service.matomo !== 'undefined' && service.matomo) {
          self.activate(context);
        }
      });
    }
  }
  };
})(Drupal);
Loading