In Google Tag Manager, a variable called {{Click URL}}
retrieves the full name of the link clicked (http://www.example.com/path/path/file.pdf)
I'm trying to create a variable that will retrieve everything after the last /
(file.pdf). I guess I need to create a Custom Javascript variable, but all my attempts so far have failed.
Amongst other things, I tried this solution: Last segment of URL
Code looked something like this:
function () {
var href = $(this).attr("href");
window.alert(href.substr(href.lastIndexOf('/') + 1));
return href;
}
Also tried this: http://www.apasters.com/blog/google-tag-manager-custom-javascript-variable-examples/
Code looked like this:
function () {
var value={{Click URL}}.split("/");
return value[1];
}