File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes Value tracking code javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Value tracking code javascript" Watch "Value tracking code javascript" New topic
Author

Value tracking code javascript

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 321
Hi,

I am using java and also I am a newbaby in GA. I have the next doubt if I want track logged users and i am using this javascript code:

_gaq.push(["_setCustomVar", 2, "status", "logged_in", 2]);

From where GA takes "logged_in"?, if I can call my variable with any name what way it works


Many Thanks

Cheers!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39537
    
  27
What do you mean by "From where GA takes..."? It's your code that is passing that value to GA. And yes, you can use any string value you want.


Ping & DNS - updated with new look and Ping home screen widget
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 321

I have read all documents I have found about GA but I need clear my ideas I find it a little bit confusing, sorry if I can't explain well what I mean.


Well what I mean is that for example if I have the code:

_gaq.push(["_setCustomVar", 2, "status", "logged_in", 2]) the string "logged_in" is obvious that it means that a user is logged but it is obvious for us, but if I call that variable "Y" instead if "logged in" it is not so obvious for humans. Then in order to pass a value to GA which means that a user is logged, from where the value logged_in comes. For example, if I am working with a *.jsp, I could retrieve the value from the bean using ${bean.variable}. And supposing that that var is logged in. GA recognize it automatically and show me all the log users?

Many Thanks,
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39537
    
  27
if I call that variable "Y" instead if "logged in"

First off, "logged_in" is not the name of a variable, it's the value of the variable "status". Where both name and value come from is entirely your code's responsibility. For GA both are just strings, and GA will happily process whatever correct (from your perspective) or junk values your app passes to it.
GA recognize it automatically and show me all the log users?

GA does not attempt to interpret the data, it just collects and displays whatever your code passes to it.
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 321
Thanks Ulf for the explanation. Then an approach which makes sense could be: create a SQL query which retrieve form DDBB the users who are logged iterate the resultset counting the number of users, send that data to the bean, and create a javascript code dinamically like:

_gaq.push(["_setCustomVar", 2, "status", "${bean.userlogged}", 2])?

Make this sense?

Many Thanks,

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39537
    
  27
I don't really follow the part about SQL and the resultset (it sounds like it does something more complicated than just determining if a user is logged in or not), but yes - the approach for filling in the value seems sound.
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 321
Well I have thougth about using SQL, because I want send to GA all the users who has been logged in my system(I could set a counter in my database in order to store that data). Then I have the same doubt again. If for example I am an user(new one) and I log in my system what way could I get the information(I am logged) and set my var which I will send to GA.

Maybe getting that information from cookies or session(getting an unique id from session and that way know that the user is new) and setting my var with the value extracted from the cookie or session?

Many Thanks,
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39537
    
  27
You mean "bean.userlogged" would be the number of users who have logged in? That's going about it the wrong way. Remember that GA is called for every single user who accesses your site. If you send "logged in"/"not logged in" for each one, GA will neatly tally up the numbers for you - no need to keep track of that in your code.
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 321
Well with " "bean.userlogged" would be the number of users who have logged in?" yes that is what I am trying to do. Then when a user types www.web.com it is a new visit, and if the visitor log in my site. He must send his details(id is a String "logged/notLogged") to the session pressing a button then retrieve the id(which is set in the session if the user is logged) and send it to GA using javascript, if the user is a visitor then he hasnĀ“t set a id value in the session, then I would send a var to GA with a notLoggged value.

I know my explanation is a mess.

Do you think is it correct this kind of approach?

Many Thanks,
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39537
    
  27
I'm confused. If you want GA to keep track of how many logged-in (or not-logged-in) users visit the page, then just send "status", "logged-in" or "status", "not-logged-in". Then GA will tally up the number of visits and show exactly two entries, the number of all logged-in visitors and all not-logged-in visitors. Doing any summing up on your site, and then sending that to GA for one particular user will yield something entirely different that (as far as I can make out) doesn't make sense.
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 321
Sorry for confuse you. Yes I understand that if I send a variable with value "logged-in or not-logged-in" GA would create two differents fields and it will show in different places. But the issue comes with the next question.

How I know who is logged or not logged in order to send the value to the "status" variable. Setting the session when the user is logged(and he press a button) and then that variable is send dinamically to the javascript code?

Example:

public String status= "no-logged";

Then the user decides log in my system and press the button"login". The code here would set status="logged" using the method setUserlogged(String status) obviusly the methos getUserlogged exits too.

_gaq.push(["_setCustomVar", 2, "status", "${bean.userlogged}", 2])

The problem for me is know when a user is logged or not.

Do you think that this makes sense?

Many Thanks




Many Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39537
    
  27
Yes, it makes sense that the status would be based on the existence or non-existence of a session.
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 321
Thanks Ulf, now my ideas are clearer.

Regards,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Value tracking code javascript
 
Similar Threads
urgent help
EJB Lookup problem
instanceof operator
Starting JBoss
JBoss seam example apps