var _userId = null; var _endpoint = 'http://iptracker.getachoo.com/api/1/track?message='; var _pageTitle = document.title; var pgtl = "TITLE"; var isRoot = location.pathname == "/"; var rootValue = 0; var enterTime = new Date(); var now; var cookieName = "Session"; var cookieTime = "Time"; var cookieFullUrl = "FullUrl"; var expires; var fullUrl; var activeInfluencers; function loadScript(url,test,callback){ var isLoaded = false; // Adding the script tag to the head as suggested before var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; var callbackTimer = setInterval(function() { var call = false; try { call = test.call(); } catch (e) {} if (call) { clearInterval(callbackTimer); callback.call(); } }, 100); // Then bind the event to the callback function. // There are several events for cross browser compatibility. //script.onreadystatechange = callback; //script.onload = callback; // Fire the loading head.appendChild(script); }; // if (typeof jQuery === "undefined") { // loadScript("https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"); // } // Start : Iframe tracking plugin /** * jQuery iframe click tracking plugin * * @author Vincent Paré (www.finalclap.com) * @copyright © 2013-2015 Vincent Paré * @license http://opensource.org/licenses/Apache-2.0 * @version 1.1.0 */ function initIframeTracker(){ (function($){ // if (typeof jQuery === "undefined") { // loadScript("https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"); // } // Tracking handler manager $.fn.iframeTracker = function(handler){ var target = this.get(); if (handler === null || handler === false) { $.iframeTracker.untrack(target); } else if (typeof handler == "object") { $.iframeTracker.track(target, handler); } else { throw new Error("Wrong handler type (must be an object, or null|false to untrack)"); } }; // Iframe tracker common object $.iframeTracker = { // State focusRetriever: null, // Element used for restoring focus on window (element) focusRetrieved: false, // Says if the focus was retrived on the current page (bool) handlersList: [], // Store a list of every trakers (created by calling $(selector).iframeTracker...) isIE8AndOlder: false, // true for Internet Explorer 8 and older // Init (called once on document ready) init: function(){ // Determine browser version (IE8-) ($.browser.msie is deprecated since jQuery 1.9) try { if ($.browser.msie == true && $.browser.version < 9) { this.isIE8AndOlder = true; } } catch(ex) { try { var matches = navigator.userAgent.match(/(msie) ([\w.]+)/i); if (matches[2] < 9) { this.isIE8AndOlder = true; } } catch(ex2) {} } // Listening window blur $(window).focus(); $(window).blur(function(e){ $.iframeTracker.windowLoseFocus(e); }); // Focus retriever (get the focus back to the page, on mouse move) $('body').append('
'); this.focusRetriever = $('#focus_retriever'); this.focusRetrieved = false; $(document).mousemove(function(e){ if (document.activeElement && document.activeElement.tagName == 'IFRAME') { $.iframeTracker.focusRetriever.focus(); $.iframeTracker.focusRetrieved = true; } }); // Special processing to make it work with my old friend IE8 (and older) ;) if (this.isIE8AndOlder) { // Blur doesn't works correctly on IE8-, so we need to trigger it manually this.focusRetriever.blur(function(e){ e.stopPropagation(); e.preventDefault(); $.iframeTracker.windowLoseFocus(e); }); // Keep focus on window (fix bug IE8-, focusable elements) $('body').click(function(e){ $(window).focus(); }); $('form').click(function(e){ e.stopPropagation(); }); // Same thing for "post-DOMready" created forms (issue #6) try { $('body').on('click', 'form', function(e){ e.stopPropagation(); }); } catch(ex) { console.log("[iframeTracker] Please update jQuery to 1.7 or newer. (exception: " + ex.message + ")"); } } }, // Add tracker to target using handler (bind boundary listener + register handler) // target: Array of target elements (native DOM elements) // handler: User handler object track: function(target, handler){ // Adding target elements references into handler handler.target = target; // Storing the new handler into handler list $.iframeTracker.handlersList.push(handler); // Binding boundary listener $(target) .bind('mouseover', {handler: handler}, $.iframeTracker.mouseoverListener) .bind('mouseout', {handler: handler}, $.iframeTracker.mouseoutListener); }, // Remove tracking on target elements // target: Array of target elements (native DOM elements) untrack: function(target){ if (typeof Array.prototype.filter != "function") { console.log("Your browser doesn't support Array filter, untrack disabled"); return; } // Unbinding boundary listener $(target).each(function(index){ $(this) .unbind('mouseover', $.iframeTracker.mouseoverListener) .unbind('mouseout', $.iframeTracker.mouseoutListener); }); // Handler garbage collector var nullFilter = function(value){ return value === null ? false : true; }; for (var i in this.handlersList) { // Prune target for (var j in this.handlersList[i].target) { if ($.inArray(this.handlersList[i].target[j], target) !== -1) { this.handlersList[i].target[j] = null; } } this.handlersList[i].target = this.handlersList[i].target.filter(nullFilter); // Delete handler if unused if (this.handlersList[i].target.length == 0) { this.handlersList[i] = null; } } this.handlersList = this.handlersList.filter(nullFilter); }, // Target mouseover event listener mouseoverListener: function(e){ e.data.handler.over = true; try {e.data.handler.overCallback(this);} catch(ex) {} }, // Target mouseout event listener mouseoutListener: function(e){ e.data.handler.over = false; $.iframeTracker.focusRetriever.focus(); try {e.data.handler.outCallback(this);} catch(ex) {} }, // Calls blurCallback for every handler with over=true on window blur windowLoseFocus: function(event){ for (var i in this.handlersList) { if (this.handlersList[i].over == true) { try {this.handlersList[i].blurCallback();} catch(ex) {} } } } }; // Init the iframeTracker on document ready $(document).ready(function(){ $.iframeTracker.init(); }); })(jQuery); }; // End : Iframe tracking plugin if (_pageTitle != "") { pgtlArray = _pageTitle.split("|"); pgtl = pgtlArray[0]; } //var netId= netId || 0; if (typeof _netId == "undefined") { _netId = 0; } if (typeof _country == "undefined" || _country == undefined || _country == "DA") { _country = 'DK'; } if (window.location.hostname.indexOf(":80") > -1) { window.location.hostname = window.location.hostname.replace(":80", "/"); } if (window.location.pathname.indexOf(":80") > -1) { window.location.pathname = window.location.pathname.replace(":80", "/"); } // checking for country domain extension, change current country var h = window.location.hostname; if (h.substr(h.length - 3) == ".dk") _country = "DK"; if (h.substr(h.length - 3) == ".se") _country = "SE"; if (h.substr(h.length - 3) == ".fi") _country = "FI"; if (h.substr(h.length - 3) == ".no") _country = "NO"; if (isRoot) { rootValue = 1; } var generalPageHandler = { test: function (url) { if (url.indexOf('http://') == -1 && url.indexOf('https://') == -1) url = 'http://' + url; var l = document.createElement("a"); l.href = url; //temporary remove below check // if (l.pathname == '/') // return true; var date = new Date; //elements of pathname var e = l.pathname.split('/'); //2015/12/09/my-book-2016/ /*REMOVED as the valid post link might starting with number and will be set as true in this case ( true mean common/ignored pages ) //2014 if (this.isset(e[1]) && parseInt(e[1]) >= 0 && parseInt(e[1]) <= date.getFullYear() && !this.isset(e[2])){ // console.log("test //2014 : TRUE"); return true; } //2014/2 if (this.isset(e[1]) && parseInt(e[1]) >= 0 && parseInt(e[1]) <= date.getFullYear() && this.isset(e[2]) && parseInt(e[2]) >= 0 && (!this.isset(e[3]) || e.length == 4)){ // console.log("test //2014/2 : TRUE"); return true; } */ //2012/12/page/2/ if (this.isset(e[1]) && parseInt(e[1]) >= 0 && this.isset(e[2]) && parseInt(e[2]) >= 0 && this.isset(e[3]) && e[3] == 'page'){ // console.log("test //2014/12/page/2 : TRUE"); return true; } if (url.indexOf('page') >= 0){ // console.log("page : TRUE"); return true; } //2014/page/17/ if (this.isset(e[1]) && parseInt(e[1]) >= 0 && this.isset(e[2]) && e[2] == 'page' && this.isset(e[3]) && parseInt(e[3]) >= 0){ // console.log("test //2014/page/17 : TRUE"); return true; } //page/3 //temporary remove e[1] == '' if (this.isset(e[1]) && (e[1] == 'page' || e[1] == 'tag' || e[1] == 'category')/* || e[1] == ''*/){ // console.log("test //page/3 : TRUE"); return true; } // if (this.isset(e[1]) && ['om', 'about', 'about-2', 'about-me', 'About', 'About-us', 'contact', 'search'].indexOf(e[1]) >= 0){ // console.log("test //om-about-contact... : TRUE"); return true; } if (url.indexOf('copenhagencakes.com') >= 0 && (this.isset(e[1]) && !isNaN(parseInt(e[1])) && this.isset(e[2]) && this.isset(e[3]) && this.isset(e[4]) && this.isset(e[5]) && e[5] != '')){ // console.log("test //copenhagencakes : TRUE"); return true; } if(url.indexOf('facebook.com') >= 0 || url.indexOf('twitter.com') >= 0){ // console.log("test //facebook : TRUE"); return true } return false; }, isset: function (v) { return typeof(v) != 'undefined' } }; var isIframeFinished = false; function checkPageType1(element){ if(element !== null && element !== undefined && element.find("h1, h2, h3, h4") !== null && element.find("h1, h2, h3, h4") !== undefined && element.find("h1, h2, h3, h4").length > 0 && element.find("h1, h2, h3, h4")[0] !== null && element.find("h1, h2, h3, h4, a")[0] !== undefined && element.find("h1, h2, h3, h4")[0].firstElementChild !== null && element.find("h1, h2, h3, h4")[0].firstElementChild !== undefined && element.find("h1, h2, h3, h4")[0].firstElementChild.href !== null && element.find("h1, h2, h3, h4")[0].firstElementChild.href !== undefined && element.find("h1, h2, h3, h4")[0].firstElementChild.text != null && element.find("h1, h2, h3, h4")[0].firstElementChild.text !== undefined){ return true; }else{ return false; } }; function checkPageType2(element){ if(element !== null && element !== undefined && element.children() !== null && element.children() !== undefined && element.children()[0] !== null && element.children()[0] !== undefined && element.children()[0].firstElementChild !== null && element.children()[0].firstElementChild !== undefined && element.children()[0].firstElementChild.href !== null && element.children()[0].firstElementChild.href !== undefined && element.children()[0].firstElementChild.text !== null && element.children()[0].firstElementChild.text !== undefined){ return true; }else{ return false; } }; function iframeOnload(){ isIframeFinished = true; }; var AIP = { createIframe: function (requestBody) { var ifrm = document.createElement('iframe'); ifrm.setAttribute('id', 'achoo_ifrm'); ifrm.setAttribute('src', _endpoint + encodeURIComponent(requestBody) + "&origin=" + encodeURIComponent(window.location.host)); ifrm.setAttribute('onload', 'iframeOnload()'); //ifrm.style.display = 'none'; // console.log("iframe day : " + ifrm); document.body.appendChild(ifrm); }, absolutePath: function (href) { var link = document.createElement("a"); link.href = href; return (link.protocol + "//" + link.host + link.pathname + link.search); }, getArticleLinks: function () { var linkObjects = null; var links = []; var titles = []; linkObjects = jQuery("h1 a, h2 a, h3 a, h4 a"); linkObjectsClosest = jQuery("h1, h2, h3, h4").closest("a"); if (linkObjects.length > 0) { linkObjects.each(function () { var pathImage =null; var p1 =jQuery(this).parent().parent().parent(); var images = jQuery( p1 ).find( "img" ); images.each(function () { var srcImage = jQuery(this).attr('src'); if (this.width > 16 && this.height > 16) { if(pathImage==null){ pathImage =srcImage; } } }); var tempHref = jQuery(this).attr('href'); // Remove "/" if href starting with front-slash "/" if(tempHref.startsWith("/")){ tempHref = tempHref.split("/")[1]; } // Check href starting with front-slash "/" -> valid href and add domain before it // Check valid href ( contain window.location.protocol + // + and domain must have atleast 1 dot inside) // return the valid href by adding protocol if(tempHref.indexOf(window.location.protocol + "//") < 0 && tempHref.indexOf(".") < 0){ tempHref = window.location.protocol + "//" + window.location.hostname + "/" + tempHref; } //Skip if href have different hostname if(tempHref.indexOf(window.location.hostname) < 0){ return; } //Skip if link is equal to hostname/domain if(tempHref.split("//")[1].localeCompare(window.location.hostname.concat("/")) === 0 || tempHref.split("//")[1].localeCompare(window.location.hostname) === 0){ return; } //Skip if link is equal to window.location.href if(tempHref.localeCompare(window.location.href) === 0){ return; } var href = tempHref; var title = jQuery(this).text(); if (generalPageHandler.test(href) === false) { links.push({ url: href, title: title, image:pathImage }); } }); return links; } if (linkObjectsClosest.length > 0) { linkObjectsClosest.each(function () { var pathImage =null; var p1 =jQuery(this).parent().parent().parent(); var images = jQuery( p1 ).find( "img" ); images.each(function () { var srcImage = jQuery(this).attr('src'); if (this.width > 16 && this.height > 16) { if(pathImage==null){ pathImage =srcImage; } } }); var tempHref = jQuery(this).attr('href'); var tempHref = jQuery(this).attr('href'); // Check valid href ( contain window.location.protocol + // + and domain must have atleast 1 dot inside) // return the valid href by adding protocol if(tempHref.indexOf(window.location.protocol + "//") < 0 && tempHref.indexOf(".") < 0){ tempHref = window.location.protocol + "//" + window.location.hostname + "/" + tempHref; } //Skip if href have different hostname if(tempHref.indexOf(window.location.hostname) < 0){ return; } //Skip if link is equal to hostname/domain if(tempHref.split("//")[1].localeCompare(window.location.hostname.concat("/")) === 0 || tempHref.split("//")[1].localeCompare(window.location.hostname) === 0){ return; } //Skip if link is equal to window.location.href if(tempHref.localeCompare(window.location.href) === 0){ return; } var href = tempHref; var title = jQuery(this).text(); if (generalPageHandler.test(href) === false) { links.push({ url: href, title: title, image:pathImage }); } }); return links; } return []; }, imageHandler: { relativeImages: [], best: function () { var best = { surfice: 0 }; var images = this.imageDetector(); images.forEach(function (img) { best = img.surfice > best.surfice ? img : best; }) return best.img ? best.img.src : null; }, popularContainers: ["#content #main", "#content article", "article .entry-content", ".post1", ".post"], imageDetector: function () { var instance = this; var found = false; if (window.jQuery) for (var key in this.popularContainers) { var selector = this.popularContainers[key]; if (jQuery(selector).length > 0) { instance.generateImageArray(instance.toArray(jQuery(selector + " img"))); break; } } if (this.relativeImages.length == 0) { var images = document.getElementsByTagName('img'); this.generateImageArray(this.toArray(images)); } return this.relativeImages; }, generateImageArray: function (el) { if (el.length == 0) return; var relativeImages = this.relativeImages; el.forEach(function (img) { var surfice = img.naturalWidth * img.naturalHeight; relativeImages.push({ img: img, surfice: surfice }) }) }, toArray: function (a) { var result = []; var i = a.length; while (i--) { result[i] = a[i]; } return result; } }, getLandingPageFlag: function() { var currentUrl = window.location.href.split(window.location.protocol + "//")[1]; if(currentUrl.localeCompare(window.location.host.toString().concat("/")) === 0){ return true; }else{ return false; } }, /* * Function to find if the given URL ( val ) is exist in the AIP.getArticleLinks ( arr ) */ isSameLink: function(arr,val){ return arr.some(function(value,index,linkObject) { return val.localeCompare(AIP.absolutePath(value.url)) === 0 ? true : val.localeCompare(value.url) === 0; }); }, /* * Function to find the Post's Url for the given element ( jQuery element if user click on hyperlink ) */ getPostUrl: function(element){ var tempResult = []; var tempPostFullUrl = null; var tempPostTitle = null; var tempPostCurrentUrl = null; var tempElement = element; var isPost = false; var type1 = false;// type1 : header ( contain page title/url ) is under parallel div with content div var type2 = false;// type2 : header ( contain page title/url ) is under parent div of content div var resetElement = false; findPostUrlLoop: while(tempPostFullUrl == null){ type1 = checkPageType1(tempElement); type2 = type1 ? false : checkPageType2(tempElement); if(tempElement !== null && tempElement !== undefined && (type1 || type2)) { var tempDomain; if(type1){ tempDomain = tempElement.find("h1, h2, h3, h4")[0].firstElementChild.href.split("//")[1].split("/")[0]; }else if (type2){ tempDomain = tempElement.children()[0].firstElementChild.href.split("//")[1].split("/")[0]; } if(tempDomain !== null && tempDomain !== undefined && tempDomain.localeCompare(window.location.host.toString()) === 0){ if(type1){ tempPostFullUrl = tempElement.find("h1, h2, h3, h4")[0].firstElementChild.href; tempPostTitle = tempElement.find("h1, h2, h3, h4")[0].firstElementChild.text; }else if(type2){ tempPostFullUrl = tempElement.children()[0].firstElementChild.href; tempPostTitle = tempElement.children()[0].firstElementChild.text; } if(tempPostFullUrl !== null && tempPostFullUrl.localeCompare(window.location.protocol + "//" + window.location.hostname + window.location.pathname) === 0){ isPost = true; } if(!isPost){ // If isPost === true then check tempPostFullUrl against AIP.getArticleLinks array // if tempPostFullURL is exist in AIP.getArticleLinks array if(AIP.getArticleLinks().length > 0 && tempPostFullUrl !== null && !isPost && AIP.isSameLink(AIP.getArticleLinks(),tempPostFullUrl)){ break findPostUrlLoop; }else{ resetElement = true; } } } else{ if(tempElement.length > 0){ resetElement = true; }else{ break findPostUrlLoop; } } } else{ if(tempElement.length > 0){ resetElement = true; }else{ break findPostUrlLoop; } } if(resetElement){ resetElement = false; tempElement = tempElement.parent(); tempPostFullUrl = null; tempPostTitle = null; tempPostCurrentUrl = null; isPost = false; type1 = false; type2 = false; } }; if(tempPostFullUrl !== null && tempPostTitle !== null){ tempResult.push(tempPostFullUrl); tempResult.push(tempPostTitle); } if(tempPostCurrentUrl !== null){ tempResult.push(tempPostCurrentUrl); }else if(tempPostCurrentUrl == null && tempPostFullUrl !== null){ tempResult.push(tempPostFullUrl); } if(tempResult !== null && tempResult !== undefined && tempResult.length == 3){ _aip_params.fullUrl = tempResult[0]; _aip_params.pageTitle = tempResult[1]; _aip_params.currentUrl = tempResult[2]; _aip_params.landingPageFlag = false; }else{ _aip_params.fullUrl = window.location.protocol + "//" + window.location.hostname + window.location.pathname; _aip_params.pageTitle = pgtl; _aip_params.currentUrl = window.location.protocol + "//" + window.location.hostname + window.location.pathname; } } }; var _aip_params = { "isEngagement": 0, "netId": _netId, "root": rootValue, "country": _country, // disable image sending "image": AIP.imageHandler.best(), "fullUrl": window.location.protocol + "//" + window.location.hostname + window.location.pathname, "hash": window.location.hash, "host": window.location.hostname, "protocol": window.location.protocol, "engagementType": "", "pageTitle": pgtl, "eventdata": {}, "userinfo": {}, "landingPageFlag": AIP.getLandingPageFlag(), "currentUrl": window.location.href }; function sendAjaxRequest(json,targetToRedirect){ $.ajax({ type: "GET", url: _endpoint, crossDomain: true, data: json, complete: function(){ redirectAfterResponse(targetToRedirect); } }); }; function redirectAfterResponse(targetToRedirect){ if (targetToRedirect.attr("target") !== undefined && targetToRedirect.attr("target") !== null && targetToRedirect.attr("target") == "_blank") { window.open(targetToRedirect.attr("href"), "_blank"); } else { window.location = targetToRedirect.attr("href"); } }; function sendEngagement(element,engagementType,postUrl){ //event.preventDefault(); _aip_params.engagementType = engagementType; _aip_params.isEngagement = 1; if(postUrl == null){ AIP.getPostUrl(element); }else{ _aip_params.fullUrl = postUrl; _aip_params.pageTitle = pgtl; _aip_params.currentUrl = postUrl; } var json = JSON.stringify(_aip_params); //sendAjaxRequest(json,targetToRedirect); AIP.createIframe(json); //while(isIframeFinished==false){} }; function checkShareCommentType(){ var facebookShareType = [ //ShareThis.Com type '.st_facebook_buttons' ,'.st_facebook_counter' ,'.st_facebook_large' ,'.st_facebook_hcount' ,'.st_facebook_vcount' ,'.st_facebook_stbar' //Facebook button plugin ( using iframe ) ,'.fb-share-button' ]; var twitterShareType = [ '.st_twitter_buttons' ,'.st_twitter_counter' ,'.st_twitter_large' ,'.st_twitter_hcount' ,'.st_twitter_vcount' ,'.st_twitter_stbar' //Twitter button plugin ( using iframe ) ,'.twitter-share-button' ]; var commentSubmitType = [ '#submit' ,'#edit-submit' ,'#postCommentSubmit' ]; var tempFacebookType = null; facebookShareType.forEach(function(value){ if(jQuery(value).length > 0){ tempFacebookType = value; return; } }); var tempTwitterType = null; twitterShareType.forEach(function(value){ if(jQuery(value).length > 0){ tempTwitterType = value; return; } }); var tempCommentType = null; commentSubmitType.forEach(function(value){ if(jQuery(value).length > 0){ tempCommentType = value; return; } }); shareCommentType.facebook = tempFacebookType; shareCommentType.twitter = tempTwitterType; shareCommentType.comment = tempCommentType; }; function checkShareIframe(){ var tempTwitterTagName = null; var tempFacebookTagName = null; var isIframe = false; if(jQuery(shareCommentType.twitter) !== undefined && jQuery(shareCommentType.twitter) !== null && jQuery(shareCommentType.twitter).length > 0 & jQuery(shareCommentType.twitter)[0] !== undefined && jQuery(shareCommentType.twitter)[0] !== null && jQuery(shareCommentType.twitter)[0].tagName !== undefined && jQuery(shareCommentType.twitter)[0].tagName !== null){ tempTwitterTagName = jQuery(shareCommentType.twitter)[0].tagName; } if(jQuery(shareCommentType.facebook) !== undefined && jQuery(shareCommentType.facebook) !== null && jQuery(shareCommentType.facebook).length > 0 & jQuery(shareCommentType.facebook)[0] !== undefined && jQuery(shareCommentType.facebook)[0] !== null && jQuery(shareCommentType.facebook)[0].firstElementChild !== undefined && jQuery(shareCommentType.facebook)[0].firstElementChild !== null && jQuery(shareCommentType.facebook)[0].firstElementChild.firstElementChild !== undefined && jQuery(shareCommentType.facebook)[0].firstElementChild.firstElementChild !== null && jQuery(shareCommentType.facebook)[0].firstElementChild.firstElementChild.tagName !== undefined && jQuery(shareCommentType.facebook)[0].firstElementChild.firstElementChild.tagName !== null){ tempFacebookTagName = jQuery(shareCommentType.facebook)[0].firstElementChild.firstElementChild.tagName; } if(tempTwitterTagName !== null){ isIframe = "IFRAME".localeCompare(tempTwitterTagName) == 0 ? true : false; } if(!isIframe && tempFacebookTagName !== null){ isIframe = "IFRAME".localeCompare(tempFacebookTagName) == 0 ? true : false; } return isIframe; }; function checkShareThisApi(){ typeof stLight !== "undefined" && stLight !== null ? true : false; }; var shareCommentType = { "facebook" : null, "twitter" : null, "comment" : null }; function checkShareLink(url){ if(url.indexOf("facebook.com/share") >= 0){ return true; }else if(url.indexOf("twitter.com/share") >= 0){ return true; }else if(url.indexOf("blogger.com/share") >= 0){ return true; }else{ return false; } }; function getTempPostUrl(element){ var tempDataUrl = element.attr('data-url') !== undefined && element.attr('data-url') !== null ? element.attr('data-url') : null; var tempDataHref = element.attr('data-href') !== undefined && element.attr('data-href') !== null ? element.attr('data-href') : null; var tempHref = element.attr("href") !== undefined && element.attr("href") !== null ? element.attr("href") : null; var tempPostUrl = tempDataUrl !== null ? tempDataUrl : tempDataHref !== null ? tempDataHref : tempHref !== null ? tempHref : null; return tempPostUrl; }; function cleanShareUrl(url){ if(url.indexOf("blogger.com/share") >= 0){ return null; } else if(url.indexOf("=") >= 0 && url.indexOf("&") >= 0){ return url.split("=")[1].split("&")[0]; }else if(url.indexOf("=") >= 0){ return url.split("=")[1]; }else{ return url; } }; function sendComment(element){ _aip_params.engagementType = "comment"; _aip_params.isEngagement = 1; AIP.getPostUrl(element); //_aip_params.fullUrl = window.location.protocol + "//" + window.location.hostname + window.location.pathname; //_aip_params.currentUrl = window.location.href; var json = JSON.stringify(_aip_params); AIP.createIframe(json); //Wait till iframe sending tracking request complete while(isIframeFinished==false){} } function sendRead(){ var currentHref = window.location.protocol + "//" + window.location.hostname + window.location.pathname; if(AIP.getArticleLinks().length > 0 && AIP.isSameLink(AIP.getArticleLinks(),currentHref)){ AIP.getArticleLinks().forEach(function (linkObject) { var linkObjectUrl = AIP.absolutePath(linkObject.url); // Skip if url not contains hostname/domain in itself ( not belong to host/domain ) if(linkObjectUrl.indexOf(window.location.protocol + "//" + window.location.hostname) < 0){ return; } //saveUrlToCookie(url); _aip_params.fullUrl = linkObjectUrl; _aip_params.pageTitle = linkObject.title; _aip_params.image = linkObject.image; _aip_params.isEngagement = 1; _aip_params.engagementType = "read"; //_aip_params.currentUrl = window.location.href; // _aip_params.landingPageFlag = AIP.getLandingPageFlag(); var json = JSON.stringify(_aip_params); AIP.createIframe(json); console.log("Engagement :" + _aip_params.isEngagement); console.log("Engagement :" + _aip_params.engagementType); console.log("Engagement : fullUrl: " + _aip_params.fullUrl); //console.log("Engagement : currentUrl:" + _aip_params.currentUrl); }) } else{ //saveUrlToCookie(url); _aip_params.fullUrl = currentHref; _aip_params.currentUrl = currentHref; _aip_params.pageTitle = pgtl; _aip_params.image = AIP.imageHandler.best(); _aip_params.isEngagement = 1; _aip_params.engagementType = "read"; //_aip_params.currentUrl = window.location.href; // _aip_params.landingPageFlag = AIP.getLandingPageFlag(); var json = JSON.stringify(_aip_params); AIP.createIframe(json); console.log("Engagement :" + _aip_params.isEngagement); console.log("Engagement :" + _aip_params.engagementType); console.log("Engagement : fullUrl: " + _aip_params.fullUrl); //console.log("Engagement : currentUrl:" + _aip_params.currentUrl); } } function sendReach() { var currentHref = window.location.protocol + "//" + window.location.hostname + window.location.pathname; if(AIP.getArticleLinks().length > 0 && AIP.isSameLink(AIP.getArticleLinks(),currentHref)){ AIP.getArticleLinks().forEach(function (linkObject) { var url = linkObject.url; url = AIP.absolutePath(linkObject.url); _aip_params.fullUrl = url; _aip_params.currentUrl = currentHref; _aip_params.pageTitle = linkObject.title; _aip_params.image = linkObject.image; _aip_params.isEngagement = 0; _aip_params.engagementType = ""; //_aip_params.currentUrl = window.location.href; // _aip_params.landingPageFlag = AIP.getLandingPageFlag(); var json = JSON.stringify(_aip_params); AIP.createIframe(json); console.log("Reach :" + _aip_params.isEngagement); console.log("Reach :" + _aip_params.engagementType); console.log("Reach : fullUrl: " + _aip_params.fullUrl); //console.log("Reach : currentUrl: " + _aip_params.currentUrl); }) }else{ _aip_params.fullUrl = currentHref; _aip_params.currentUrl = currentHref; _aip_params.pageTitle = pgtl; _aip_params.image = AIP.imageHandler.best(); _aip_params.isEngagement = 0; _aip_params.engagementType = ""; //_aip_params.currentUrl = window.location.href; // _aip_params.landingPageFlag = AIP.getLandingPageFlag(); var json = JSON.stringify(_aip_params); AIP.createIframe(json); console.log("Reach :" + _aip_params.isEngagement); console.log("Reach :" + _aip_params.engagementType); console.log("Reach : fullUrl: " + _aip_params.fullUrl); //console.log("Reach : currentUrl: " + _aip_params.currentUrl); } } function sendVisit() { /*if (generalPageHandler.test(window.location.href) === false) { _aip_params.isEngagement = 2; _aip_params.engagementType = "visit"; //_aip_params.currentUrl = window.location.href; var json = JSON.stringify(_aip_params); AIP.createIframe(json); console.log("Visit : isEngagement: " + _aip_params.isEngagement); console.log("Visit : engagementType: " + _aip_params.engagementType); console.log("Visit : fullUrl: " + _aip_params.fullUrl); AIP.getArticleLinks().forEach(function (linkObject) { var url = linkObject.url; url = AIP.absolutePath(linkObject.url); _aip_params.fullUrl = url; _aip_params.pageTitle = linkObject.title; _aip_params.image = linkObject.image; _aip_params.isEngagement = 2; _aip_params.engagementType = "visit"; //_aip_params.currentUrl = window.location.href; // _aip_params.landingPageFlag = AIP.getLandingPageFlag(); var json = JSON.stringify(_aip_params); AIP.createIframe(json); console.log("Visit : isEngagement: " + _aip_params.isEngagement); console.log("Visit : engagementType: " + _aip_params.engagementType); console.log("Visit : fullUrl: " + _aip_params.fullUrl); }) } else { _aip_params.fullUrl = window.location.protocol + "//" + window.location.hostname + window.location.pathname; _aip_params.isEngagement = 2; _aip_params.engagementType = "visit"; //_aip_params.currentUrl = window.location.href; var json = JSON.stringify(_aip_params); AIP.createIframe(json); console.log("Visit : isEngagement: " + _aip_params.isEngagement); console.log("Visit : engagementType: " + _aip_params.engagementType); console.log("Visit : fullUrl: " + _aip_params.fullUrl);*/ var currentHref = window.location.protocol + "//" + window.location.hostname + window.location.pathname; if(AIP.getArticleLinks().length > 0 && AIP.isSameLink(AIP.getArticleLinks(),currentHref)){ AIP.getArticleLinks().forEach(function (linkObject) { var url = linkObject.url; url = AIP.absolutePath(linkObject.url); _aip_params.fullUrl = url; _aip_params.pageTitle = linkObject.title; _aip_params.image = linkObject.image; _aip_params.isEngagement = 2; _aip_params.engagementType = "visit"; //_aip_params.currentUrl = window.location.href; // _aip_params.landingPageFlag = AIP.getLandingPageFlag(); var json = JSON.stringify(_aip_params); AIP.createIframe(json); console.log("Visit : isEngagement: " + _aip_params.isEngagement); console.log("Visit : engagementType: " + _aip_params.engagementType); console.log("Visit : fullUrl: " + _aip_params.fullUrl); //console.log("Visit : currentUrl: " + _aip_params.currentUrl); }) }else{ _aip_params.fullUrl = currentHref; _aip_params.currentUrl = currentHref; _aip_params.pageTitle = pgtl; _aip_params.image = AIP.imageHandler.best(); _aip_params.isEngagement = 2; _aip_params.engagementType = "visit"; //_aip_params.currentUrl = window.location.href; // _aip_params.landingPageFlag = AIP.getLandingPageFlag(); var json = JSON.stringify(_aip_params); AIP.createIframe(json); console.log("Visit : isEngagement: " + _aip_params.isEngagement); console.log("Visit : engagementType: " + _aip_params.engagementType); console.log("Visit : fullUrl: " + _aip_params.fullUrl); //console.log("Visit : currentUrl: " + _aip_params.currentUrl); } //} } // interval 2s for loading complete all necessary javascript on blog ( e.g jQuery lib ) var interval = setInterval(function () { // if (typeof jQuery === "undefined") { // loadScript("https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"); // } jQuery(document).ready(function ($) { // Check site to findout which type of sharethis type are using checkShareCommentType(); //Handle common click on 'a' tag - Send Link-Engagement type jQuery('a').click(function (event) { event.preventDefault(); var tempElement = jQuery(this); var tempPostUrl = getTempPostUrl(tempElement); var isShareLink = checkShareLink(tempPostUrl); //event.stopPropagation(); // links with domain not equals to host ( links and host have diff domain ) if(!generalPageHandler.test(tempPostUrl) && tempPostUrl.indexOf(window.location.host.toString()) < 0 && !isShareLink){ sendEngagement(tempElement,"link",null); redirectAfterResponse(tempElement); } // Share twitter/facebook using A tag ( direct link ) else if(generalPageHandler.test(tempPostUrl) && isShareLink){ tempPostUrl = cleanShareUrl(tempPostUrl); sendEngagement(tempElement,"share",tempPostUrl); redirectAfterResponse(tempElement); } //links with domain equals to host( links and host have same domain ) else{ redirectAfterResponse(tempElement); } }); var current = window.location.protocol + "//" + window.location.hostname + window.location.pathname; //Cases to doCookie() ( might send Visit-Engagement ) and send Reach/Read //Ensure that trackingScript will send Reach/Read only and only for //1. User navigate to new url : getFullUrl() = "" //2. User navigate to new url : getFullUrl() != "" and not equal to current url //3. User navigate to new url : getFulUrl() != "" and euqal to current url and session = 1 ( new session ) if(getFullUrl() === "" || (getFullUrl() !== "" && current.localeCompare(getFullUrl()) !== 0 ) || (getFullUrl() !== "" && current.localeCompare(getFullUrl()) === 0 && getSession() === 1)){ doCookie(); setTimeout(function () { sendRead(); sendReach(); }, 6000); } //Not send Reach/Read in case getFullUrl != "" and equal to current url but session != 1 ( session 2 onwards ) else{ doCookie(); } //Handle for Share-Engagement if (generalPageHandler.test(window.location.href) === false) { // Handle for Sharing Twitter/Facebook using Iframe if(checkShareIframe()){ if(typeof($.iframeTracker) === "undefined"){ initIframeTracker(); } // Handle Twitter Share for those blog are using iframe // Send Share-Engagement type jQuery(shareCommentType.twitter).iframeTracker({ blurCallback: function(){ var tempPostUrl = cleanShareUrl(getTempPostUrl(this._overElement)); sendEngagement(null,"share",tempPostUrl); }, overCallback: function(element){ this._overId = $(element).attr('id'); // Saving the iframe wrapper id this._overElement = $(element); // Saving the iframe element }, outCallback: function(element){ this._overId = null; // Reset hover iframe wrapper id this._overElement = null; // Reset hover iframe element }, _overId: null, _overElement: null }); // Handle Facebook Share for those blog are using iframe // Send Share-Engagement type jQuery(shareCommentType.facebook).iframeTracker({ blurCallback: function(){ var tempPostUrl = cleanShareUrl(getTempPostUrl(this._overElement)); sendEngagement(null,"share",tempPostUrl); }, overCallback: function(element){ this._overName = $(element).children().children().attr('name'); // Saving the iframe wrapper id this._overElement = $(element); // Saving the iframe element }, outCallback: function(element){ this._overName = null; // Reset hover iframe wrapper id this._overElement = null; // Reset hover iframe element }, _overName: null, _overElement: null }); } // Handle Share for those blog are using 3rd party javascript API (e.g ShareThis javascript API) else if(checkShareThisApi()){ // Handle Twitter Share for those blog are using 3rd party javascript API : ShareThis // Send Share-Engagement type jQuery(shareCommentType.twitter).click(function (event){ var tempElement = jQuery(this); var tempPostUrl = getTempPostUrl(tempElement); sendEngagement(tempElement,"share",tempPostUrl); }); // Handle Facebook Share for those blog are using 3rd party javascript API : ShareThis // Send Share-Engagement type jQuery(shareCommentType.facebook).click(function (event){ var tempElement = jQuery(this); var tempPostUrl = getTempPostUrl(tempElement); sendEngagement(tempElement,"share",tempPostUrl); }); } // Handle Share for blog using Twitter API else if(typeof(twttr) !== "undefined" && twttr !== null) { console.log("Twitter is defined. "); var postUrlTitle; jQuery(document).ready(function () { jQuery('a').click(function (event) { event.stopPropagation(); AIP.getPostUrl(jQuery(event)); }); }); twttr.ready(function (twttr) { // bind to the tweet event twttr.events.bind('tweet', function(event){ var tempElement = jQuery(event); var tempPostUrl = null; if(checkShareIframe()){ tempElement = jQuery(event.target); tempPostUrl = getTempPostUrl(tempElement); }else{ tempPostUrl = AIP.getPostUrl(tempElement); } //_aip_params.engagementType = "share"; //_aip_params.isEngagement = 1; if(tempPostUrl !== null){ sendEngagement(event,"share",tempPostUrl); }else{ sendEngagement(event,"share",null); } //_aip_params.fullUrl = window.location.protocol + "//" + window.location.hostname + window.location.pathname; //_aip_params.currentUrl = window.location.protocol + "//" + window.location.hostname + window.location.pathname //var json = JSON.stringify(_aip_params); //AIP.createIframe(json); }); }); } else{ console.log("NO TWTTER OBJECT FOUND. "); } if (typeof(FB) !== "undefined" && FB !== null) { console.log("FB is defined. "); console.log("Tracking FB shares is not available in FB API"); // _aip_params.engagementType = "share"; // _aip_params.isEngagement = 1; // FB.ui( // { // method: 'share', // href: 'https://www.facebook.com' + window.location.href, // }, // // callback // function(response) { // if (response && !response.error_message) { // alert('Posting completed.'); // } else { // alert('Error while posting.'); // } // } // ); // FB.Event.subscribe('message.send', // function (response) { // console.log("LIKED ON FACEBOOK."); // } // ); } else { console.log("NO FB OBJECT FOUND."); } //var submitedCommentEvent = false; //Handle for comment submission jQuery(shareCommentType.comment).click(function (ev) { // if (submitedCommentEvent == false) { // ev.preventDefault(); ev.stopPropagation(); sendComment(jQuery(this)); jQuery(shareCommentType).click(); // } }); }; }); clearInterval(interval); }, 2000); function getFullUrl() { fullUrl = ""; if(document.cookie) { index = document.cookie.indexOf(cookieFullUrl); if (index != -1) { countbegin = (document.cookie.indexOf("=", index) + 1); countend = document.cookie.indexOf(";", index); if (countend == -1) { countend = document.cookie.length; } fullUrl = document.cookie.substring(countbegin, countend); } } return(fullUrl); }; function getSession() { session=0; if(document.cookie) { index = document.cookie.indexOf(cookieName); if (index != -1) { countbegin = (document.cookie.indexOf("=", index) + 1); countend = document.cookie.indexOf(";", index); if (countend == -1) { countend = document.cookie.length; } session = eval(document.cookie.substring(countbegin, countend)); } } return(session); }; function getTime() { time = 0; if(document.cookie) { oldFullUrl = getFullUrl(); newFullUrl = window.location.protocol + "//" + window.location.hostname + window.location.pathname; if (newFullUrl.localeCompare(oldFullUrl) == 0) { index = document.cookie.indexOf(cookieTime); if (index != -1) { countbegin = (document.cookie.indexOf("=", index) + 1); countend = document.cookie.indexOf(";", index); if (countend == -1) { countend = document.cookie.length; } time = eval(document.cookie.substring(countbegin, countend)); } else { expires = new Date() expires.setDate(expires.getDate()+1); expires.setHours(0, 0, 0); // expires.setMinutes(expires.getMinutes() + 5); console.log("expires: " + expires.toString()); document.cookie = cookieTime + "=0; expires=" + expires.toString(); if (getSession() == 0) { sendVisit(); document.cookie = cookieName + "=1; expires=" + expires.toString(); } } } else { expires = new Date() expires.setDate(expires.getDate()+1); expires.setHours(0, 0, 0); // expires.setMinutes(expires.getMinutes() + 5); console.log("expires: " + expires.toString()); document.cookie = cookieTime + "=0; expires=" + expires.toString(); document.cookie = cookieFullUrl + "=" + newFullUrl + "; expires=" + expires.toString(); if (getSession() == 0) { sendVisit(); document.cookie = cookieName + "=1; expires=" + expires.toString(); } } } return(time); }; var setTime = setInterval(function () { //doCookie(); expires = new Date() expires.setDate(expires.getDate()+1); expires.setHours(0, 0, 0); //expires.setMinutes(expires.getMinutes() + 5); console.log("expires: " + expires.toString()); time = getTime(); time += 60*1000; document.cookie = cookieTime + "=" + time + "; expires=" + expires.toString(); if (time <= 29*60*1000) { if (getSession() == 0) { sendVisit(); document.cookie = cookieName + "=1; expires=" + expires.toString(); } } else if (time > 29*60*1000 && getSession() == 1) { sendVisit(); document.cookie = cookieName + "=2; expires=" + expires.toString(); } else if (cookieTime > 29*60*1000 && getSession() == 2) { document.cookie = cookieName + "=2; expires=" + expires.toString(); } }, 60*1000); function setCookie(cName, cValue, expDays) { var expires = new Date(); expires.setTime(expires.getDate()+expDays); expires.setHours(0, 0, 0); //expires.setMinutes(expires.getMinutes() + 5); console.log("expires: " + expires.toString()); document.cookie = cName + "=" + cValue + "; expires=" + expires.toString(); }; function doCookie() { var expires = new Date() expires.setDate(expires.getDate()+1); expires.setHours(0, 0, 0); //expires.setMinutes(expires.getMinutes() + 5); console.log("expires: " + expires.toString()); if (document.cookie) { indexSession = document.cookie.indexOf(cookieName); indexFullUrl = document.cookie.indexOf(cookieFullUrl); } else { indexSession = -1; indexFullUrl = -1; } if (indexSession == -1 || indexFullUrl == -1) { sendVisit(); document.cookie = cookieName + "=1; expires=" + expires.toString(); document.cookie = cookieTime + "=0; expires=" + expires.toString(); newFullUrl = window.location.protocol + "//" + window.location.hostname + window.location.pathname; document.cookie = cookieFullUrl + "=" + newFullUrl + "; expires=" + expires.toString(); } else { oldFullUrl = getFullUrl(); newFullUrl = window.location.protocol + "//" + window.location.hostname + window.location.pathname; if (newFullUrl.localeCompare(oldFullUrl) == 0) { session = getSession(); if (getTime() > 29*60*1000 && session == 1) { sendVisit(); document.cookie = cookieName + "=2; expires=" + expires.toString(); } } else { sendVisit(); document.cookie = cookieName + "=1; expires=" + expires.toString(); document.cookie = cookieTime + "=0; expires=" + expires.toString(); document.cookie = cookieFullUrl + "=" + newFullUrl + "; expires=" + expires.toString(); } } }; //doCookie();