!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd?define("externalTracking",[],b):a.externalTracking=b()}(this,function(){var a={samplingFraction:null,documentPageKeyOverride:null,TRACK_CLIENT:"liTrackClient",EVENT_NAME:"ExternalTrackingPageViewEvent",CHROME_INITIATOR:"CHROME",APP_INITIATOR:"APP",COMSCORE_DATA:{c1:2,c2:6402952,c3:"",c4:"",c5:"",c6:"",c15:""},COMSCORE_BEACON_URL:"http"+("s"===document.URL.charAt(4)?"s://sb":"://b")+".scorecardresearch.com/b?",setTreatment:function(a){try{var b,c;this.samplingFraction=null,a&&0===a.indexOf("enabled")&&(b=a.split("_"),2===b.length&&(c=parseFloat(b[1]),c>=0&&1>=c&&(this.samplingFraction=c)))}catch(d){this._logError("failed to set treatment: "+d)}},setDocumentPageKeyOverride:function(a){this.documentPageKeyOverride=a},trackWithComScoreForChromeInit:function(){this._trackWithComScore(this.documentPageKeyOverride,this.CHROME_INITIATOR)},trackWithComScore:function(a){this._trackWithComScore(a,this.APP_INITIATOR)},_trackWithComScore:function(a,b){var c,d,e,f="ns_",g=[],h=window,i=document,j=h.encodeURIComponent,k=this.COMSCORE_DATA;if(h.COMSCORE&&"function"==typeof h.COMSCORE.beacon)COMSCORE.beacon(k);else{for(d in k)k.hasOwnProperty(d)&&g.push(j(d)+"="+j(k[d]));g.push(f+"_t="+ +new Date),g.push(f+"c="+(i.characterSet||i.defaultCharset||"")),g.push("c8="+j(i.title)),g.push("c7="+j(i.URL)),g.push("c9="+j(i.referrer)),c=this.COMSCORE_BEACON_URL+g.join("&"),e=new Image,e.src=c}try{this._trackExternalPageViewRequest(a||this._getDocumentPageKey(),["COMSCORE"],b)}catch(l){this._logError("failed to track external page view")}},_trackExternalPageViewRequest:function(a,b,c){var d=this;if(null!==d.samplingFraction){var e={eventInfo:{eventName:d.EVENT_NAME,appId:d._getAppName()},eventBody:{pageViewPageKey:a,pageViewPath:d._getDocumentPath(),samplingFraction:d.samplingFraction,providers:b,initiator:c,requestHeader:{pageKey:d._getDocumentPageKey()}}};if(window.liTrackClient)try{window.liTrackClient.track(e)}catch(f){d._logError("failed to track external page view with "+d.TRACK_CLIENT)}else if(window.require&&"function"==typeof window.require.ensure)try{require.ensure([d.TRACK_CLIENT],function(a){try{var b=a(d.TRACK_CLIENT);b.track(e)}catch(c){d._logError("failed to track external page view with "+d.TRACK_CLIENT)}})}catch(f){d._logError("failed to require "+d.TRACK_CLIENT)}else d._logError(d.TRACK_CLIENT+" not found")}else d._logError("sampling fraction not set")},_getDocumentPageKey:function(){var a=this._getMetaTag("pageKey");return a?a.content:(this._logError("pageKey not found"),"")},_getDocumentPath:function(){return window.location.pathname.split("?")[0]},_getAppName:function(){var a=this._getMetaTag("appName");return a?a.content:(this._logError("appName not found"),"")},_getMetaTag:function(a){var b,c=document.getElementsByTagName("meta"),d=c.length;for(b=0;d>b;b++)if(c[b].getAttribute("name")===a)return c[b];return null},_logError:function(a){console&&console.error&&console.error(a)}};return a});