SU-SWS/stanford_profile_helper

View on GitHub
js/stanford_profile_helper.siteimprove.analytics.js

Summary

Maintainability
A
0 mins
Test Coverage
(function ($) {
  'use strict';
  Drupal.behaviors.stanfordProfileHelperSiteImprove = {
    attach: function () {
      const analyticsSrc = '//siteimproveanalytics.com/js/siteanalyze_80352.js';
      // If a script tag with the source has already been added, do nothing.
      if ($(`script[src*="${analyticsSrc}"]`).length === 0) {
        const $script = $('<script>')
          .attr('type', 'text/javascript')
          .attr('async', true)
          .attr('src', analyticsSrc);

        $script.insertBefore($('script').first());
      }
    }
  };

})(jQuery);