(function(e){typeof define==`function`&&define.amd?define([],e):e()})(function(){var e=((e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports))(((e,t)=>{t.exports={}}));function t(n,r,i,a){if(!(n instanceof Error))throw n;if(!(typeof window>`u`&&r||a))throw n.message+=` on line `+i,n;var o,s,c,l;try{a||=e().readFileSync(r,{encoding:`utf8`}),o=3,s=a.split(`
`),c=Math.max(i-o,0),l=Math.min(s.length,i+o)}catch(e){n.message+=` - could not read from `+r+` (`+e.message+`)`,t(n,null,i);return}o=s.slice(c,l).map(function(e,t){var n=t+c+1;return(n==i?`  > `:`    `)+n+`| `+e}).join(`
`),n.path=r;try{n.message=(r||`Pug`)+`:`+i+`
`+o+`

`+n.message}catch{}throw n}function n(e){var n=``,r,i;try{i=1,r=`/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug`,n+=`<div class="g-config-breadcrumb-container"></div>`,i=2,r=`/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug`,n+=`<p class="g-google-analytics-description">`,i=3,r=`/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug`,n+=`To track pageviews in Girder, enter your Google Analytics tracking ID here.</p>`,i=4,r=`/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug`,n+=`<form id="g-google_analytics-form" role="form">`,i=5,r=`/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug`,n+=`<div class="form-group">`,i=6,r=`/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug`,n+=`<label class="control-label" for="g-google-analytics-tracking-id">`,i=6,r=`/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug`,n+=`Google Analytics Tracking ID</label>`,i=7,r=`/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug`,n+=`<input class="input-sm form-control" id="g-google-analytics-tracking-id" type="text" placeholder="Tracking ID"/></div>`,i=9,r=`/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug`,n+=`<p class="g-validation-failed-message" id="g-google_analytics-error-message"></p>`,i=10,r=`/home/circleci/project/girder/plugins/google_analytics/girder_google_analytics/web_client/templates/configView.pug`,n+=`<input class="btn btn-sm btn-primary" type="submit" value="Save"/></form>`}catch(e){t(e,r,i)}return n}var r=girder.views.widgets.PluginConfigBreadcrumbWidget,i=girder.views.View,a=girder.events,{restRequest:o}=girder.rest,s=i.extend({events:{"submit #g-google_analytics-form":function(e){e.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(){o({method:`GET`,url:`system/setting`,data:{list:JSON.stringify([`google_analytics.tracking_id`])}}).done(e=>{this.render(),this.$(`#g-google-analytics-tracking-id`).val(e[`google_analytics.tracking_id`])})},render:function(){return this.$el.html(n()),this.breadcrumb||=new r({pluginName:`Google Analytics`,el:this.$(`.g-config-breadcrumb-container`),parentView:this}).render(),this},_saveSettings:function(e){o({method:`PUT`,url:`system/setting`,data:{list:JSON.stringify(e)},error:null}).done(()=>{a.trigger(`g:google_analytics.save`),a.trigger(`g:alert`,{icon:`ok`,text:`Settings saved.`,type:`success`,timeout:4e3})}).fail(e=>{this.$(`#g-google_analytics-error-message`).text(e.responseJSON.message)})}}),c=girder.router,l=girder.events,{exposePluginConfig:u}=girder.utilities.PluginUtils;u(`google_analytics`,`plugins/google_analytics/config`),c.route(`plugins/google_analytics/config`,`googleAnalyticsConfig`,function(){l.trigger(`g:navigateTo`,s)});var d=girder.$,f=girder.events,{restRequest:p}=girder.rest;function m(){p({method:`GET`,url:`google_analytics/id`}).done(e=>{if(e.google_analytics_id){let t=e.google_analytics_id;d.getScript({url:`https://www.googletagmanager.com/gtag/js?id=${t}`,success:function(){window.dataLayer=window.dataLayer||[];function e(){dataLayer.push(arguments)}e(`js`,new Date),e(`config`,t),window.gtag=e}})}})}f.on(`g:appload.after`,function(){m()}),f.on(`g:google_analytics.save`,function(){m()}),f.on(`g:hierarchy.route`,function(e){let t=e.route;/^\//.test(t)||(t=`/`+t),window.gtag&&window.gtag(`event`,`page_view`,{girder_route:t})}),f.on(`g:navigateTo`,function(e){let t=location.hash;t=t.replace(/^#/,``),window.gtag&&window.gtag(`event`,`page_view`,{girder_route:t})})});