I am making a Google Analytics like project for my school assignment. I have two questions primarily:
1) Exactly when does Google store the data to the database? When it does it use XHR with some server side scripting language to store it to the database or is there a way to do it using plain javascript?
2) How do I get the IP address of a user from Javascript? How does Google do for Analytics??
Thanks for all the help.
Pranz
The Google Analytics JS code doesn't talk directly to the server - it adds an image to the page, and appends all the info to send back as URL parameters on the image - check out a page with Google Analytics running with the Firebug Net panel running and you'll see what's happening. So the JS code doesn't need to work out the IP - that's going to come through to the GA recording servers as part of the image request.
The best official description of what happens is in the Google BigTable paper - there's a few paragraphs which give a sort of hint as to what happens behind the scenes.
It might also be worth following this Stack Overflow question on structuring the database which records & reports on the activity.
regards
1) Yes. The JavaScript on the user-side sends a request to the server, which processes it using its own application (you can use PHP or any language your server is set up to call).
2) You might find it simplest to grab the IP address using $_SERVER['REMOTE_ADDR'].
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