I try to pass the parameter _trackPageview to Google Analytics.
I now use
_gaq.push(['_trackPageview', <%=AntiXss.JavaScriptEncode(Url.RequestContext.HttpContext.Request.Path ) %> ])
The resulting Hml for "/Home/Index" is:
_gaq.push(['_trackPageview', '\x2fHome\x2fIndex' ]);
How should I handle the forward slash? Will "\x2" be displayed ok in Google Analytics? Or Is it save to replace \x2 with forward slash?
_gaq.push(['_trackPageview', <%=AntiXss.JavaScriptEncode(Url.RequestContext.HttpContext.Request.Path).Replace("\x2","/") %> ])
EDIT:
I cant use _gaq.push(['_trackPageview']); without the path parameter because the original path contains the language which I dont want to track ( /de/home/index needs to get tracked as /home/index )
You don't actually need the 2nd argument for _trackPageview. By default it will record the current url (including query params). That url, on any given page is assembled/taken from document.location.
replace solution you already mentioned is actually good enough.document.location or document.location.pathname? I'd guess the query or hash part of the URL is the only thing you'd need worry about for an XSS attack.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With