!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd?define("liTrackClient",[],b):a.liTrackClient=b()}(this,function(){var a={AJAX_METHOD:"POST",DEFAULT_PAGE_TYPE:"ajax",globalTrackingUrl:null,globalTrackingAppId:"no.app.id",lastDisplayMetric:null,lastActionMetric:null,queue:[],maxQueueSize:1,queueTimeout:1e3,timeoutId:null,setProperty:function(a,b){if(b)return void(this[a]=b);var c=this.getMetaTag(a);return c?void(this[a]=c.content):void 0},setTrackingUrl:function(a){this.setProperty("globalTrackingUrl",a)},setAppId:function(a){this.setProperty("globalTrackingAppId",a)},createXmlHttpObject:function(){try{return new XMLHttpRequest}catch(a){}return null},ajax:function(a,b,c){var d;return this.globalTrackingUrl?(d=this.createXmlHttpObject(),void(d&&(d.open(this.AJAX_METHOD,this.globalTrackingUrl,!0),d.setRequestHeader("Content-type","application/json"),d.onreadystatechange=function(){return 4===d.readyState?200!==d.status&&304!==d.status?void(c&&c("Request returned "+d.status)):void("function"==typeof b&&b(d)):void 0},4!==d.readyState&&d.send(a)))):void(c&&c("Tracking url is not defined"))},flush:function(){var a=this;this.ajax(JSON.stringify(this.queue),null,a.logError),this.queue=[],clearTimeout(this.timeoutId),this.timeoutId=null},addToQueue:function(a){if(this.queue.push(a),this.queue.length>=this.maxQueueSize)return this.flush();if(!this.timeoutId){var b=this;this.timeoutId=setTimeout(function(){b.flush()},this.queueTimeout)}},track:function(a){return"object"!=typeof a?void this.logError("Track data must be an object"):(a=this.fillMissingData(a),void this.addToQueue(a))},trackWithCallback:function(a,b){var c=this;if("object"!=typeof a)return void this.logError("Track data must be an object");a=this.fillMissingData(a);var d=JSON.stringify(a);this.ajax(d,function(a){"function"==typeof b&&b(null,a.responseText)},function(a){c.logError(a),"function"==typeof b&&b(a)})},getTimestamp:function(){return Math.round((new Date).getTime()/1e3)},getTrackingCode:function(a){return a.eventBody.trackingCode?a.eventBody.trackingCode:"PageViewEvent"===a.eventInfo.eventName?"full"===a.eventBody.pageType?(this.lastDisplayMetric=a.eventBody.requestHeader.pageKey,this.lastActionMetric):(this.lastActionMetric=a.eventBody.requestHeader.pageKey,this.lastDisplayMetric):null},fillMissingData:function(a){if(!a.eventInfo)return this.logError("You must specify eventInfo");if(a.eventInfo.appId||(a.eventInfo.appId=this.globalTrackingAppId),!a.eventBody)return this.logError("You must specify eventBody");a.eventBody.trackingCode=this.getTrackingCode(a);var b=a.eventBody.trackingInfo||{};return b.clientTimestamp||(b.clientTimestamp=this.getTimestamp()),a.eventBody.trackingInfo=b,a},trackPageView:function(a){var b,c,d,e;"string"==typeof a?(b=a,e=this.DEFAULT_PAGE_TYPE):(b=a.pageKey,e=a.pageType||this.DEFAULT_PAGE_TYPE,c=a.trackingCode,d=a.trackingInfo);var f={eventInfo:{eventName:"PageViewEvent"},eventBody:{requestHeader:{pageKey:b},pageType:e}};return c&&(f.eventBody.trackingCode=c),d&&(f.eventBody.trackingInfo=d),b?void this.track(f):this.logError("You must provide a pageKey")},trackUnifiedAction:function(a){if(!a.requestHeader||!a.requestHeader.pageKey)return this.logError("You must provide pageKey");if(!a.action)return this.logError("You must provide action");if(!a.sponsoredFlag)return this.logError("You must provide sponsoredFlag");var b={eventInfo:{eventName:"UnifiedActionEvent"},eventBody:a};this.track(b)},trackArticleView:function(a){if(!a.requestHeader||!a.requestHeader.pageKey)return this.logError("You must provide pageKey");if(!a.articleId)return this.logError("You must provide articleId");var b={eventInfo:{eventName:"ArticleViewEvent"},eventBody:a};this.track(b)},trackUnifiedImpression:function(a){if(!a.requestHeader||!a.requestHeader.pageKey)return this.logError("You must provide pageKey");if(!a.results)return this.logError("You must provide results");var b={eventInfo:{eventName:"UnifiedImpressionEvent"},eventBody:a};this.track(b)},logError:function(a){console&&console.error&&console.error(a)},getMetaTag:function(a){var b,c,d=document.getElementById(a);if(d)return d;for(metas=document.getElementsByTagName("meta"),c=metas.length,b=0;c>b;b++)if(metas[b].getAttribute("name")===a)return metas[b];return null}};return a.setTrackingUrl(),a.setAppId(),a});