Extracting JavaScript OnClick to Google Tag Manager
This Google Tag Manager custom JavaScript takes an onclick event for a button which opens link as a document.location and extracts the contents e.g. the filename from onclick=”document.location=’https://example.com/download/filetype’”
function() {
var field = .getAttribute('onclick');
var myRegexp = /'(.*)'/;
var result = field.match(myRegexp);
return result ? result[1] : null;
}
Hopefully this is useful to you!