All Links Not Current Domain

Overview

This custom tag looks for all links that do not belong to the current domain.

Under Variable Summary reports in ObservePoint data, select the Other Domain Links account to see the relevant variables:

  • webpage: Shows the page or audit passing through
  • totalLinks: Shows the total amount of links on the current webpage.
  • totalOtherDomainLinks: Shows the total amount of links on the current webpage.
  • OtherDomainLinks.xx: Shows an array of different domain hrefs. If all hrefs belong to current domain then it displays "no other domain links found".
  • otherDomainLinks.length: Shows the total amount of other domain links on the current webpage.

To capture these details in an audit or web journey, paste the snippet below into an Execute Action:

function opReqGetAsync(paramObject, acct, callback) { 
var baseURL = "https://opreq.observepoint.com/?acct=" + acct; 
var opReq = new XMLHttpRequest(); 
opReq.onreadystatechange = function() { 
if (opReq.readyState == 4 && opReq.status == 200){ 
callback(opReq.responseText); 
} 
} 
opReq.open("POST", baseURL, true); 
opReq.send(JSON.stringify(paramObject)); 
} 
function linkDomainCheck(){ 
var object = new Object(), 
domain = location.host.replace("www.", ""), 
regEx = new RegExp(domain, "g"), 
links = document.querySelectorAll('a[href]'), 
result = Object.keys(links).map(function(key){return links[key]}), 
hrefs = [], 
otherDomain = []; 
//collecting all hrefs 
for (var i = result.length - 1; i >= 0; i--) { 
hrefs.push(result[i].href) 
};//checking if href string contains domain and pushing them to array of results
for (var i = hrefs.length - 1; i >= 0; i--) {
if(hrefs[i].search(regEx) == "-1"){
otherDomain.push(hrefs[i]);
}
};
object.webPage = location.href;
object.totalLinks = hrefs.length;
object.totalOtherDomainLinks = otherDomain.length;
otherDomain.length == 0 ? object.otherDomainLinks = "no other domain links found" : object.otherDomainLinks = otherDomain;
opReqGetAsync(object, "Other Domain Links");
};linkDomainCheck();
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.