Google Analytics Auto-Login to deeper pages with Javascript  | Member | | Join Date: Nov 2007 Location: South Texas
Posts: 32
| |
Hi guys and gals,
I am using javascript to autologin to my google analytics account via a hyperlink.
This is what the text looks like this -
<?xml version="1.0" encoding="utf-8"?>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
-
<script src="/autologin.js" type="text/javascript"></script>
-
<p><a class="aaButton FL" href="javascript:gi('googleanalyticslogin').submit();">Sign in to Analytics Account</a></p>
-
<form style="display:none;" id="googleanalyticslogin" action="https://www.google.com/accounts/ServiceLoginBoxAuth" method="post">
-
<input type="text" name="Email" class="gaia le val" id="Email" size="18" value="**********" />
-
<input type="password" name="Passwd" class="gaia le val" id="Passwd" size="18" value="***********" />
-
<input type="checkbox" name="PersistentCookie" value="yes" />
-
<input type="hidden" name="rmShown" value="1" >
-
<input type="hidden" name="continue" value="http://www.google.com/analytics/home/?et=reset&hl=en-US" />
-
<input type="hidden" name="service" value="analytics">
-
<input type="hidden" name="nui" value="1" />
-
<input type="hidden" name="hl" value="en-US">
-
<input type="hidden" name="GA3T" value="oCGYxISAGUE" />
-
</form>
-
</div>
-
</body>
-
</html>
-
I got this script from askapache and I thank them for it.
This all works just fine for me. My problem is that I want to access pages deeper in the google analytics site, like Unique visitors, or Pageviews. When I try to swap the url above with the one for the deeper pages I want, I get the login page, where as the script above takes me to the profiles page that you see immediately after login. I know the problem is with the cookies google puts once you login. If I use the script above, I get the cookies from googlle, and the login works. If I delete those cookies and try to run the script with the url of the deeper pages, it goes to the login page again. However, if I do not delete the cookies and run the script with the url of the deeper page then it goes to the page I want with out a hitch. I have tried to use java to recreate the same cookies and deposit them on the computer of the person using the script before it runs, but that did not work. I also tried using a redirect but that flopped as well. I am at my wits end.
If anyone would give me some advice, help or consolation, I would really appreciate it.
Thanks
Victor
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Google Analytics Auto-Login to deeper pages with Javascript
Welcome to TSDN! Quote:
Originally Posted by victorduwon When I try to swap the url above with the one for the deeper pages I want, I get the login page, where as the script above takes me to the profiles page that you see immediately after login. I know the problem is with the cookies google puts once you login. If I use the script above, I get the cookies from googlle, and the login works. If I delete those cookies and try to run the script with the url of the deeper pages, it goes to the login page again. However, if I do not delete the cookies and run the script with the url of the deeper page then it goes to the page I want with out a hitch. I have tried to use java to recreate the same cookies and deposit them on the computer of the person using the script before it runs, but that did not work. Cookies only work for the same domain. You could try submitting to an iframe and then going to the deeper page. That way, the cookies are set and you reach the page in "one click".
|  | Expert | | Join Date: Nov 2007 Location: Slovakia
Posts: 101
| | | re: Google Analytics Auto-Login to deeper pages with Javascript
It's easy to explain such a behavior.
The login page you are calling (the first one that works always) is doing this:
- take you login form information and check them
- if they are right, server creates session for you (tagged as logged in), creates new cookies that identify you with that newly created session and send them to your client
- so from this point, whenever you make request to server with this new cookie, server can assign your request to your session -> you are logged in
So if:
1) you call loggin page first -> it creates session + cookies
- when you try to call deeper site now, it will work, becasue server you already has the sesion and can assign it with your cookie you are always sending in request.
- when you delete your cookies, server can not assign your request with his session anymore, so whatever you request for, you are redirected to login page
2) you call deeper site first (without calling login page before)
- you dont have cookie in your client that you are sending to server, nor server has session for you. So he is always redirecting you to login page.
I know what you want to achieve here. But it seems that google is processing your login form just in the first page, and in all others just check if you are already logged in. If not ... redirecting you to login page.
I can see just iframe solution:
1) call your login page into hidden iframe
2) and after that redirect to deeper site
But it's quite ghetto solution, because you have to wait till your iframe page is loaded, to continue ... so you maybe need 2 clicks, not one :)
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Google Analytics Auto-Login to deeper pages with Javascript Quote:
Originally Posted by Dasty I can see just iframe solution:
1) call your login page into hidden iframe
2) and after that redirect to deeper site
But it's quite ghetto solution, because you have to wait till your iframe page is loaded, to continue ... so you maybe need 2 clicks, not one :) Good explanation.
You could show a loading image or div until the iframe page has loaded.
|  | Member | | Join Date: Nov 2007 Location: South Texas
Posts: 32
| | | re: Google Analytics Auto-Login to deeper pages with Javascript
Thanks guys, your explanation has helped me a lot.
As far as the iframe solution, that sounds doable. I even like the idea of placing a load image in it. My goal is to make all of this happen in one click.
Could someone tell me how to create the hidden iframe and use it to load my page? I am very new to Javascript, and all of my exp comes from this project.
thanks again.
|  | Member | | Join Date: Nov 2007 Location: South Texas
Posts: 32
| | | re: Google Analytics Auto-Login to deeper pages with Javascript
I made a post last night about a problem I was having with an autologin script. I want my users to be able to log into google analytics with only one click from another site. But I want them to not got to the landing page, (the one after login) but to pages deeper in the analytics suite, like PageViews, or Unique Views.
The advice I was given was to use an iframe to run my autologin script let google deposit its cookies, and then redirect it to the pages deeper in the site.
I have been researching this all morning, but I am new to Javascript and am not lost and confused. Would someone point me in the right direction of give me some assistance in this?
Thanks
Vic
|  | Member | | Join Date: Nov 2007 Location: South Texas
Posts: 32
| | | re: Google Analytics Auto-Login to deeper pages with Javascript
Is there any way using Javascript that I can cause this page to load, accept cookies, but not to show? This way when the user clicked on the link it would automatically take them to the pages I want them to see in one click, because the cookies would have already been loaded when the first page was.
|  | Member | | Join Date: Nov 2007 Location: South Texas
Posts: 32
| | | re: Google Analytics Auto-Login to deeper pages with Javascript
Hi guys and gals,
I am using javascript to autologin to my google analytics account via a hyperlink.
This is what the text looks like this -
-
-
<?xml version="1.0" encoding="utf-8"?>
-
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
-
-
<script src="/autologin.js" type="text/javascript"></script>
-
-
<p><a class="aaButton FL" href="javascript:gi('googleanalyticslogin').submit();">Sign in to Analytics Account</a></p>
-
-
<form style="display:none;" id="googleanalyticslogin" action="https://www.google.com/accounts/ServiceLoginBoxAuth" method="post">
-
-
<input type="text" name="Email" class="gaia le val" id="Email" size="18" value="**********" />
-
-
<input type="password" name="Passwd" class="gaia le val" id="Passwd" size="18" value="***********" />
-
-
<input type="checkbox" name="PersistentCookie" value="yes" />
-
-
<input type="hidden" name="rmShown" value="1" >
-
-
<input type="hidden" name="continue" value="http://www.google.com/analytics/home/?et=reset&hl=en-US" />
-
-
<input type="hidden" name="service" value="analytics">
-
-
<input type="hidden" name="nui" value="1" />
-
-
<input type="hidden" name="hl" value="en-US">
-
-
<input type="hidden" name="GA3T" value="oCGYxISAGUE" />
-
-
</form>
-
-
</div>
-
-
</body>
-
-
</html>
-
-
-
I got this script from askapache and I thank them for it.
The problem I had is mentioned in another post. I believe that my solution is in getting this script to run when the page loads, but to not show the google analytics page. This will allow the clients machine to accept the cookies, and when they click on links to go deeper in to the google analytics site the cookies will already be in their browser.
How do I do this? Any help or redirection will be greatly appreciated.
vic
| | Member | | Join Date: Sep 2007
Posts: 77
| | | re: Google Analytics Auto-Login to deeper pages with Javascript
script cannot work cross-domain.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Google Analytics Auto-Login to deeper pages with Javascript Quote:
Originally Posted by victorduwon As far as the iframe solution, that sounds doable. I even like the idea of placing a load image in it. My goal is to make all of this happen in one click.
Could someone tell me how to create the hidden iframe and use it to load my page? Set the height and width to 0. Put the code for the form submit in the iframe.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Google Analytics Auto-Login to deeper pages with Javascript Quote:
Originally Posted by victorduwon Is there any way using Javascript that I can cause this page to load, accept cookies, but not to show? This way when the user clicked on the link it would automatically take them to the pages I want them to see in one click, because the cookies would have already been loaded when the first page was. Try running the form submit code onload rather than on clicking a link.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Google Analytics Auto-Login to deeper pages with Javascript
I've merged your threads. Please don't double post and keep all posts on the same problem in one thread - see posting guidelines.
|  | Expert | | Join Date: Nov 2007 Location: Slovakia
Posts: 101
| | | re: Google Analytics Auto-Login to deeper pages with Javascript
As I said, it's not really nice solution, but it works for one click and I tried to make it simple to understand:
[HTML]
<html>
<head>
<script language="javascript">
var redirect_me = false;
function myload()
{
if (redirect_me) self.location = 'http://idontknow.com/deeper/depper.php';
}
</script>
</head>
<body>
<form action="http://idontknow.com/login.php" target="myiframe" onsubmit="redirect_me=true;">
<input type=hidden name="name" value="myname">
<input type=hidden name="pass" value="mypass">
<input type=submit>
</form>
<iframe name="myiframe" onload="myload();" style="display:none;"></iframe>
</body>
</html>[/HTML]
There is no valiadtions that login was successful, but I think you can tweak it up :) The whole point of this solution is to redirect form submit target to my own iframe. And as you can see you can set "onload" event on iframe element. (you dont have any other solution to check if other site loaded in iframe, because it is from different domain (dont have access to it's document DOM tree) ... but I think you can read its innerHTML or so. So making a loop and checking for iframe's innerHTML can be a solution as well)
Hope that helps ...
PS: Thanks for PM, but feel free to ask your questions here in this thread, so other members that have similar problems can read them here (and see answers)
|  | Member | | Join Date: Nov 2007 Location: South Texas
Posts: 32
| | | re: Google Analytics Auto-Login to deeper pages with Javascript
Thanks everyone. I did work with this script and got things to work to my satisfaction. I did not get the 'one-click' solution, but I am happy. Thanks
vic
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Google Analytics Auto-Login to deeper pages with Javascript
Well, at least you're happy! Post again if you have any more questions.
|  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,531 network members.
|