Page 1 of 1
Google Analytics kind
Posted: Fri Feb 27, 2009 1:13 am
by dharprog
Hi
I need to know how to make the analytics ourself to give js code to put in other sites to get the details or track the site where it is being opening?
how this is possible. If there are any tutorials please let me know.
Thanks and regards,
dharprog
Re: Google Analytics kind
Posted: Fri Feb 27, 2009 3:16 am
by mattpointblank
You can't.
Re: Google Analytics kind
Posted: Fri Feb 27, 2009 6:22 am
by Kadanis
That's a bit short and not very helpful.
It totally depends on what you are trying to achieve. If the sites you wish to track are clients/users/customers etc and they allow the script to be embedded on the page then it is relatively easy to do.
If on the other hand you wish to track websites of your choice with no contact with the owners, then you can't really. Although there is a way round it using IFrames, but would mean your users have to surf the web in your site via the IFrame and not actually visit the pages directly. Not very appealing.
Option 1, you would create a JS script that would utilise some form of ajax call to a server side script to update a database with your tracking you would also need to provide some form of ID to enable the tracking to be identified per client.
Option 2, beyond the initial concept outlined here I haven't given it any thought and it may not even be possible. However option 1 is possible as its almost exactly what Google does.
Snippet for customers page (look at google analytics snippets)
Code: Select all
<script src="http://www.mydomain.tld/path/to/tracking.js"></script>
<script>
var myUniqueID = 'UID123456789';
track();
</script>
tracking.js (psuedo-code only)
Code: Select all
function track(){
//create ajax httpxml request object
//pass vars back to it
//include page from calling function and unique id
//send request to server side
}
server side:
Code: Select all
<?php
//get post vars from ajax submit
$userId = $_POST['userid'];
// --- snip ---
//connect to db
$con = new mysqli('localhost','user','pass','dbname');
//generate sql statement
$query = "INSERT INTO analytics SET userID = '".$userid."', timestamp = unix_timestamp(), page = '".$pageID."';";
//execute
$con->query($query);
?>
This is only a loose example and needs some work to fill it out, but that's half the fun with programming. Hope this gets you started.
Re: Google Analytics kind
Posted: Fri Feb 27, 2009 6:33 am
by dharprog
Hi
Thanks for the help done.
That is really correct and i am opting for option1 which is legal..
Thanks for giving me the steps and flow of analytics.
Thanks and regards,
dharprog
Re: Google Analytics kind
Posted: Fri Feb 27, 2009 7:14 am
by mattpointblank
Looks like I misunderstood - I thought you wanted to basically generate Google Analytics code yourself without manually signing up to their site. Apologies.
Re: Google Analytics kind
Posted: Fri Feb 27, 2009 11:22 am
by dharprog
Hi mattpointblank
Its ok and thank you.
Regards,
Dharprog