marketo_suite-1.0.x-dev/js/e3_marketo_munchkin.js

js/e3_marketo_munchkin.js
/**
 * @file
 * Injects Marketo munchkin tracking.
 */
(function (Drupal, cookies) {
  'use strict';

  Drupal.behaviors.marketoMunchkin = {

    attach: function (context, settings) {

      /**
       * Init Munchkin tracking.
       */
      const init = function () {

        // Integrate with the GDPR module if it is installed.
        let cookiesAccepted = true;
        if (typeof GDPR !== 'undefined') {
          cookiesAccepted = GDPR.cookiesAccepted();
        }

        if (cookiesAccepted  && typeof Munchkin !== 'undefined') {
          let config = getMunchkinID();
          Munchkin.init(config);
        }
        else if (!cookiesAccepted) {
          cookies.remove('_mkto_trk');
        }
      };

      /**
       * Get Munchkin ID from Marketo Settings.
       */
      const getMunchkinID = function () {
        if (typeof(settings.marketoForms) != 'undefined' &&
            typeof(settings.marketoForms.munchkinId) != 'undefined' &&
            settings.marketoForms.munchkinId) {

          return settings.marketoForms.munchkinId;
        }

        return false;
      };

      // Delay init if GDPR module is installed.
      if (typeof GDPR !== 'undefined' && !GDPR.initialisationComplete) {
        window.addEventListener("gdpr:load", function () {
          init();
        });
      }
      else {
        init();
      }
    }
  }

})(Drupal, window.Cookies);

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc