Targeting window.location.pathname
问题 I have a url similiar to this: www.mysite.com/products/ I was using this to test against the pathname: if (/\/products\//.test(window.location)) { _gaq.push(['_trackPageview', '/products/landing']); } But the problem I was running into was the above would execute for sub-folders as well, which I do not want: www.mysite.com/products/sub-folder/ I'm thinking window.location.pathname will help me out more than the above jQuery. But I'm unsure how to target only the top-level directory, and not