I am trying to write some JavaScript where I can pass the path of the current page URL to another function ; specifically would like to add it as a a value in a custom variable for Google Analytics. However, since I don't know JavaScript, I thought it would be best to see if I can pass the variable to a simple alert. Alas, I can not. I have checked out several posts on this site and can't get this to work. Some of the threads I've checked are:
need to pass variable to function
How to pass this variable to this function?
Pass variable to external javascript?
I've also tried Google and some JavaScript tutorials, and playing around with single, double quotes, brackets, etc...nothing works. Can anyone help please? Thank you.
<script type="text/javascript">
$(document).ready(function() {
var pdpURL = window.location.pathname;
});
function popup() {
alert('pdpURL');
}
</script>
The pop up appears but it just says pdpURL in it rather than the URL.