Download Links

The Download Links custom tag allows you to capture all the pages where downloadable links are found and the names of the documents.

It finds anchor tags that fit the following pattern:

<a href="file-path/file_name.extension">Link Name</a>
The following items show up in the Variable Summary report under the OP Custom Tag. The account is Download Links.
  • linksFound: Shows the pages where links were not found.
  • linksFound.0-xx: Shows the pages where download links were found and their filenames.
  • linksFound.length: Shows the number of links found by page.
  • name: Shows the link name and extension.
  • page: Shows the display URL and the actual URL of the pages where the download links were found.

Download Links detects the following types of files, corresponding to the red code in the snippet below:

  • txt
  • csv
  • ppt
  • pdf
  • doc
  • docx
  • xls
  • xlsx

These document types can be modified if you understand regular expressions: Find the red list of document types in the code below and remove, edit, or add to it. Be sure there is a pipe (|) symbol between each of the document extensions. Warning: modifying the snippet can cause it to break, in which case you'll have to copy the original snippet again.

To capture these details in an audit or web journey, paste the snippet below into an Execute Action. Text that can be edited is red:

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 downloadLinkFinder(){var object = new Object(), 
regEx = /([a-z0-9\_\-\.])+\.+( txt|csv|ppt|pdf|doc|docx|xls|xlsx|xlt|pptx)+\"?$/gi, 
results = [], 
page = location.href, 
name = "Download links"; 
links = document.querySelectorAll('a[href]');for(var i = 0; i < links.length; i++){ 
var href = links[i].href; 
if(!!href.match(regEx)){ 
results.push(href.match(regEx)+ "") 
} 
} 
//setting info in object 
object.name = name; 
object.page = page; 
//checking if there is no result 
results.length == 0 ? object.linksFound = "no download links found" : object.linksFound = results ;//sending info to OP 
opReqGetAsync(object, " Download Links");
};
downloadLinkFinder();
	
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.