(function(r){typeof define=="function"&&define.amd?define(r):r()})(function(){"use strict";(function(i){typeof define=="function"&&define.amd?define(["backbone"],i):typeof exports=="object"?module.exports=i(require("backbone")):i(window.Backbone)})(function(i){var e=i.History.prototype.loadUrl;i.History.prototype.loadUrl=function(t){var n=e.apply(this,arguments),g=this.fragment;if(!this.options.silent)return this.options.silent=!0,n;/^\//.test(g)||(g="/"+g),typeof window._gaq<"u"&&window._gaq.push(["_trackPageview",g]);var o;return window.GoogleAnalyticsObject&&window.GoogleAnalyticsObject!=="ga"?o=window.GoogleAnalyticsObject:o=window.ga,typeof o<"u"&&(o("set","page",g),o("send","pageview")),n}});function r(i,e,t,n){if(!(i instanceof Error))throw i;if(!(typeof window>"u"&&e||n))throw i.message+=" on line "+t,i;var g,o,u,a;try{n=n||require("fs").readFileSync(e,{encoding:"utf8"}),g=3,o=n.split(`
`),u=Math.max(t-g,0),a=Math.min(o.length,t+g)}catch(l){return i.message+=" - could not read from "+e+" ("+l.message+")",void r(i,null,t)}g=o.slice(u,a).map(function(l,b){var d=b+u+1;return(d==t?"  > ":"    ")+d+"| "+l}).join(`
`),i.path=e;try{i.message=(e||"Pug")+":"+t+`
`+g+`

`+i.message}catch{}throw i}function F(i){var e="",t,n;try{n=1,t="/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug",e=e+'<div class="g-config-breadcrumb-container"></div>',n=2,t="/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug",e=e+'<p class="g-google-analytics-description">',n=3,t="/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug",e=e+"To track pageviews in Girder, enter your Google Analytics tracking ID here.</p>",n=4,t="/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug",e=e+'<form id="g-google_analytics-form" role="form">',n=5,t="/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug",e=e+'<div class="form-group">',n=6,t="/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug",e=e+'<label class="control-label" for="g-google-analytics-tracking-id">',n=6,t="/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug",e=e+"Google Analytics Tracking ID</label>",n=7,t="/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug",e=e+'<input class="input-sm form-control" id="g-google-analytics-tracking-id" type="text" placeholder="Tracking ID"/></div>',n=9,t="/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug",e=e+'<p class="g-validation-failed-message" id="g-google_analytics-error-message"></p>',n=10,t="/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug",e=e+'<input class="btn btn-sm btn-primary" type="submit" value="Save"/></form>'}catch(g){r(g,t,n)}return e}const C="",p=girder.views.widgets.PluginConfigBreadcrumbWidget,f=girder.views.View,y=girder.events,{restRequest:s}=girder.rest;var m=f.extend({events:{"submit #g-google_analytics-form":function(i){i.preventDefault(),this.$("#g-google_analytics-error-message").empty(),this._saveSettings([{key:"google_analytics.tracking_id",value:this.$("#g-google-analytics-tracking-id").val().trim()}])}},initialize:function(){s({method:"GET",url:"system/setting",data:{list:JSON.stringify(["google_analytics.tracking_id"])}}).done(i=>{this.render(),this.$("#g-google-analytics-tracking-id").val(i["google_analytics.tracking_id"])})},render:function(){return this.$el.html(F()),this.breadcrumb||(this.breadcrumb=new p({pluginName:"Google Analytics",el:this.$(".g-config-breadcrumb-container"),parentView:this}).render()),this},_saveSettings:function(i){s({method:"PUT",url:"system/setting",data:{list:JSON.stringify(i)},error:null}).done(()=>{y.trigger("g:alert",{icon:"ok",text:"Settings saved.",type:"success",timeout:4e3})}).fail(e=>{this.$("#g-google_analytics-error-message").text(e.responseJSON.message)})}});const _=girder.router,w=girder.events,{exposePluginConfig:h}=girder.utilities.PluginUtils;h("google_analytics","plugins/google_analytics/config"),_.route("plugins/google_analytics/config","googleAnalyticsConfig",function(){w.trigger("g:navigateTo",m)});const c=girder.events,{restRequest:v}=girder.rest;c.on("g:appload.after",function(){var i=navigator.doNotTrack||window.doNotTrack;i!=="1"&&i!=="yes"&&(function(e,t,n,g,o,u,a){e.GoogleAnalyticsObject=o,e[o]=e[o]||function(){(e[o].q=e[o].q||[]).push(arguments)},e[o].l=1*new Date,u=t.createElement(n),a=t.getElementsByTagName(n)[0],u.async=1,u.src=g,a.parentNode.insertBefore(u,a)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),v({method:"GET",url:"google_analytics/id"}).done(e=>{e.google_analytics_id&&typeof ga<"u"&&ga("create",e.google_analytics_id,"none")}))}),c.on("g:hierarchy.route",function(i){var e=i.route;/^\//.test(e)||(e="/"+e),typeof ga<"u"&&ga("send","pageview",e)})});
//# sourceMappingURL=girder-plugin-google-analytics.umd.cjs.map
