Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
10-02-2012, 03:17 AM #1
- Join Date
- Jun 2012
- South Carolina
- Thanked 0 Times in 0 Posts
Get current page URL and use as variable in another function
What I would like to do is populate the currentPDP portion of the GA snippet with the information being pulled from the variable I made. Do I just need to enclose currentPDP in a $(currentPDP) or something like that? Can anyone help please?
var currentPDP = window.location.pathname;
var _gaq =_gaq || ;
1, // This custom var is set to slot #1. Required parameter.
'currentPDP', // The name acts as a kind of category for the user activity. Required parameter.
'Yes', // This value of the custom variable. Required parameter.
2 // Sets the scope to session-level. Optional parameter.
10-02-2012, 08:03 AM #2
- Join Date
- Jan 2006
- Halle (Saale), Germany
- Thanked 981 Times in 954 Posts
No, at the moment your variable is undefined when it is called, I guess, because the document isn’t completely ready yet when the variable is called. Just remove the
});or put the location.pathname object right where you call the variable at the moment (you don’t need a variable at all, I suppose).
And I hope you aren’t loading that whole jQuery library just for this one reason?