var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
class UNLAnalytics {
  static {
    __name(this, "UNLAnalytics");
  }
  debugMode = "false";
  unlProp = "G-XYGRJGQFZK";
  thisURL = String(window.location);
  mediaHubOrigin = "https://mediahub.unl.edu";
  constructor(options = {}) {
    if (window.UNL = window.UNL || {}, window.UNL.analytics = window.UNL.analytics || {}, window.UNL.analytics.config = window.UNL.analytics.config || {}, "debugMode" in window.UNL.analytics.config && typeof window.UNL.analytics.config.debugMode == "boolean" ? this.debugMode = window.UNL.analytics.config.debugMode : "debugMode" in options && typeof options.debugMode == "boolean" && (this.debugMode = options.debugMode), "unlProp" in window.UNL.analytics.config && typeof window.UNL.analytics.config.unlProp == "string" ? this.unlProp = window.UNL.analytics.config.unlProp : "unlProp" in options && typeof options.unlProp == "string" && (this.unlProp = options.unlProp), window.UNL.analytics.callTrackEvent = (category, eventAction, label, value, noninteractive = !1) => {
      this.callTrackEvent(category, eventAction, label, value, noninteractive);
    }, document.querySelector('script[data-unl-initialized="true"]') !== null)
      return;
    const headTag = document.querySelector("head");
    if (document.querySelector('script[src*="larue.unl.edu"],script[src*="webanalytics.unl.edu"]') === null) {
      const newLarueScriptTag = document.createElement("script");
      newLarueScriptTag.innerHTML = `
                var _paq = window._paq = window._paq || [];
                /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
                _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
                _paq.push(["setCookieDomain", "*.unl.edu"]);
                _paq.push(["setDomains", ["*.unl.edu"]]);
                _paq.push(['trackPageView']);
                _paq.push(['enableLinkTracking']);
                (function() {
                    var u="https://larue.unl.edu/";
                    _paq.push(['setTrackerUrl', u+'main.php']);
                    _paq.push(['setSiteId', '1']);
                    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
                    g.async=true; g.src=u+'main.js?v=6.1.1'; s.parentNode.insertBefore(g,s);
                })();
                const listenToAllLinks = () => {
                    document.body.addEventListener('click', (e) => {
                        // Double check we clicked a link
                        const link = e.target.closest('a[href]');
                        if (!link) {
                            return;
                        }

                        // Get the base url of the site/links
                        const baseTag = document.querySelector('base');
                        let baseUrl = window.location.href;
                        if (baseTag !== null) {
                            const baseTagHref = baseTag.getAttribute('href');
                            if (baseTagHref !== null && baseTagHref.length > 1) {
                                baseUrl = baseTagHref;
                            }
                        }

                        const linkUrlHref = link.getAttribute('href');
                        if (linkUrlHref === null || linkUrlHref.length <= 1) {
                            // If we are here then there is no link to track
                            return;
                        }

                        const linkUrl = new URL(linkUrlHref, baseUrl);
                        _paq.push([
                            'trackEvent',
                            'Link Clicked',
                            linkUrl.toString()
                        ]);
                    });
                };
                if (document.readyState === 'loading') {
                    document.addEventListener('DOMContentLoaded', listenToAllLinks);
                } else {
                    listenToAllLinks();
                }
            `, headTag.append(newLarueScriptTag);
    }
    if (document.querySelector(`script[src*=googletagmanager][src*='${this.unlProp}']`) === null) {
      const newGtagScript = document.createElement("script");
      newGtagScript.setAttribute("async", ""), newGtagScript.setAttribute("src", `https://www.googletagmanager.com/gtag/js?id=${this.unlProp}`), headTag.append(newGtagScript);
    }
    const newGtagSetup = document.createElement("script");
    newGtagSetup.dataset.unlInitialized = "true", newGtagSetup.innerHTML = `
            window.dataLayer = window.dataLayer || [];
            function gtag() {
                dataLayer.push(arguments);
            }
            gtag("js", new Date());
            gtag("config", "${this.unlProp}", {
                ${this.debugMode ? "debug_mode: true," : ""}
            });
            // These will be updated once idm initializes
            gtag('set', 'user_properties', {
                UNL_Affiliation: "None",
                login_status: "Not Logged In",
            });
        `, headTag.append(newGtagSetup), window.addEventListener("idmStateSet", () => {
      let affiliation = window.UNL.idm.getPrimaryAffiliation();
      affiliation = affiliation.toLowerCase().replace(/\b[a-z]/g, function(letter) {
        return letter.toUpperCase();
      }), this.#gtag("set", "user_properties", {
        UNL_Affiliation: affiliation,
        login_status: affiliation === "None" ? "Not Logged In" : "Logged In"
      });
    }), window.UNL.analytics.loaded = !0, document.dispatchEvent(new CustomEvent(UNLAnalytics.events("UNLAnalyticsReady"), {
      detail: {
        classInstance: this
      }
    }));
  }
  // The names of the events to be used easily
  static events(name) {
    const events = {
      UNLAnalyticsReady: "UNLAnalyticsReady"
    };
    return Object.freeze(events), name in events ? events[name] : void 0;
  }
  /**
   * This function will send a page_view event to GA4.
   * GTAG config will send the initial page_view event so this does not need to run on page load.
   * @param {string} thePage URL of the page that has or will be viewed
   * @return { void }
   */
  callTrackPageview(thePage) {
    const eventData = {
      page_location: thePage,
      send_to: this.unlProp
    };
    this.debugMode && (eventData.debug_mode = !0), this.#gtag("event", "page_view", eventData);
  }
  /**
   * This function will send any event with specific data to GA4.
   * @param { string } eventName Name of the event to be sent
   * @param { Object } event_data Data to be send to GA4
   * @return { void }
   */
  sendEvent(eventName, eventData) {
    eventData.send_to = this.unlProp, this.debugMode && (eventData.debug_mode = !0), this.#gtag("event", eventName, eventData);
  }
  /**
   * This function will send any event to GA4.
   * !This will not be able to send any custom data.
   * @deprecated
   * @param { string } category Event category
   * @param { string } eventAction Event name
   * @param { string } label Label for the event
   * @param { string } value Value of the send
   * @param { bool } noninteractive If the event was interactive or not
   * @return { void }
   */
  callTrackEvent(category, eventAction, label, value, noninteractive = !1) {
    const eventData = {
      event_category: category,
      event_label: label,
      send_to: this.unlProp
    };
    this.debugMode && (eventData.debug_mode = !0), value !== void 0 && (eventData.value = value), noninteractive && (eventData.noninteractive = !0), this.#gtag("event", eventAction, eventData);
  }
  /**
   * This function will set up event listeners for Media Hub related events
   * @return { void }
   */
  recordMediaHubEvents() {
    window.addEventListener("message", function(event) {
      this.mediaHubOrigin === event.origin && event.data.message_type === "ga_event" && this.callTrackEvent("media", event.data.event, event.data.media_title);
    });
  }
  #gtag(arg1, arg2, arg3) {
    window.dataLayer = window.dataLayer || [];
    function gtag() {
      window.dataLayer.push(arguments);
    }
    __name(gtag, "gtag"), gtag(arg1, arg2, arg3);
  }
}
export {
  UNLAnalytics as default
};
//# sourceMappingURL=component.analytics.js.map
