Tracking users and gathering analytics on a second party site
I've got a Python/Django powered site that offers a service to clients. All the clients who use my service simply need to include a "single" JS tag in their page. All works fine but I need to some tracking on the client side. Clients could be using their own tracking system e.g. GA or something.
I need to gather the following metrics and post it back my Django app. Each client would have an unique key so I know which client, the metrics are coming from. Is it possible to collect the following metrics:
- IP-address
- Browser Information
- OS Information
- Page URL
- Referrer URL
- Language
- etc.
These are very similar to the ones on Support Details and seem to be pretty easy to handle.
I would like to also check the following metrics but I'm little lost with how to go about this as JS has never been my forte.
- New or Returning Visitor
- Number of Visits
- How long stayed on the page
- When was the last time they visited the page
Are there scripts that accomplish this? if so, could someone point me to one?
Is it possible to do what I've asked above through the script that the client would embed on their page. Are there any l开发者_运维技巧imitations due to XSS and cross-domain requests?
Thank you.
You can even use your own GA if you want to.
Just have the client make a _POST or a _GET request to your site via AJAX on every page view.
Edit:
User is redirected from your site (mysite.com) to another site (externalsite.com) and you send the user to this particular page: http://externalsite.com/page/21.html#ui=12345, the thing to retain here is the #ui=12345
.
Now the external site runs a snippet of Javascript (jQuery) that does this:
var hash = window.location.hash;
var data = '<script src="http://mysite.com/stats?ui='+hash+'"></script>';
$('body').append(data);
This is overcome your XSS problems and you can then have your stats
page record into a database the user's UI + Agent + IP + Time and do all sort of math with it.
精彩评论