views:

237

answers:

3

On some pages in Google Analytics, there is a variable shown in the URL. The default value is 10. The URL always looks something like this:
...&trows=10&...
is there a way to change that to trows=100, so that the number of rows displayed by default is 100? Thanks

A: 

Yes. You can modify links to the page, reload the page (with a modified parameter) when the "wrong" parameter is in the URL, or both. For the former, XPath is very useful (but not necessary) for finding links. For the latter, you can modify window.location.search.

Matthew Flaschen
+1  A: 
if (/trows=10(?!\d)/.test(location.href)) 
    location.href=location.href.replace("trows=10","trows=100");

Edit: If you want to use back button to go back to trows=10 page, use .assign method, instead of .replace, but since you want 100 as default, you might not need it.

location.assign(location.href.replace("trows=10","trows=100"));
S.Mark
if you use location.href=.. then the back button won't work any longer.
Erik Vold
@Erik, Thanks for commenting for downvote, but he is trying to replace `trows=10` to `trows=100`, apparently, he don't need to go back to `trows=10` page, so it does not matter.
S.Mark
"he don't need to go back to trows=10 page, so it does not matter."If he is at pg A, then goes to pg B (which contains `trows=10`) then your code kicks in and he is sent to pg C, then if he hit the back button he would go to pg B, which would redirect him to pg C, and thus the back button will not work with your code (he cannot get to pg A without hitting back twice).
Erik Vold
+1  A: 
if (/[\?&]trows=10[^\d]/i.test(document.location.href)) 
    document.location.replace(document.location.href.replace("trows=10","trows=100"));

Use document.location.replace() so that the back button still works.

Erik Vold
You've downvoted my answer, but you, yourself also using `location.replace()`, have you **really** read your document that you are pointing to?
S.Mark
"have you really read your document that you are pointing to?"Yes I have, have you?Be sure that you are aware there are two different replace methods being used in my code before you answer please, one is a String.prototype.replace and the other is a window.location.replace, very different methods.
Erik Vold
@S.Mark you're not understanding what you are reading then, since I see you have read it.. Let me spell it out for you I guess.. If I go to page A, then page B and I've written userscript to redirect me to page C from page B with your method, then when I press back I will go to page B and the userscript will kick in again and send me to page C. So the history looks like A->B->C, and when I press back on page C I end up at page C, that is a bad ux. With my method the history will look like A->C, then when I press back I will end up at page A as desired. Is this getting through to you yet?
Erik Vold
@Eric, I understand that, but the one you are saying that **cannot use back button** is quite confusing as you can see same wording *cannot use Back button* in the document. You need to say that, the history should not be save, so when you use Back button, it will completely ignored trows=10 page.
S.Mark
@Fool please learn to use your brain a little bit, and spell people's names, then try to be more polite. "I understand that" what a clown.
Erik Vold
ok, I stand corrected @Erik for spelling wrong, but I don't think I am not polite here. I don't called anyone, Fool or stupid. Anyway, nothing more to say that.
S.Mark
asking "have really read your document that you are pointing to?" is a pretty insulting question ask when you haven't thought it through yourself yet, it shows a inclination to insult at least, then you follow it up by spelling my name wrong after you got it right twice, what else should one assume?
Erik Vold
"stupid" you said that not me.
Erik Vold
I didn't mean to insult you, sorry if my words offend you. let me take my words back. OP didn't mentioned the situations related to Back buttons so, I just thought you are saying different thing. Let me apologize for that.
S.Mark
apology accepted, please be more careful in the future, it makes the world a better place to be in.
Erik Vold
Thank you, I will.
S.Mark