![]() ![]() |
Star Member![]() ![]() Group: 1000 Post Club
Joined: 15-August 04
Posts: 1,071
|
Feb 24 2006, 07:11 AM |
|
|
QUOTE "One of the more interesting aspects of Ajax is the ability to track a user’s interaction within the browser. I wanted to investigate navigation patterns, so I have written an Ajax based link tracker. If you press the “Ctrl” and "X" keys you will be presented with an overlay which displays links usage by percentage. This functionality was created with JavaScript and a very simple API." Check out - Ajax Link Tracker Be sure to press the "Ctrl + X" keys after the page has loaded. Definitely useful for web designers / copywriters. (Yes, many analytics do offer this. It's the method used here to implment something similar that's really interesting.) |
||
| Offline | ![]() |
Hall of Fame![]() Group: Members
Joined: 27-July 04
Posts: 937
From: Seattle, WA
|
Feb 24 2006, 12:22 PM |
|
|
Thanks whitemark - I just blogged on this and I appreciate the reference.
|
||
| Offline | ![]() |
Membership Admin & Moderator![]() ![]() Group: Membership Admin & Moderator
Joined: 30-September 05
Posts: 3,266
From: Some round-ish rock floating in a vacuum.
|
Feb 28 2006, 04:03 PM |
|
|
Finally got it to work. Did I ever mention that JS and XML are a pain in the posterior?
Full details can be found here. Hope you like it Pierre PS - For future reference: if anyone is sending XML for AJAX stuff like this, check your line endings. I noticed that if the PHP sends XML lines ending with \n, the AJAX breaks. Without any line breaks, it works a treat. |
||
| Offline | ![]() |
Star Member![]() ![]() Group: 1000 Post Club
Joined: 15-August 04
Posts: 1,071
|
Mar 1 2006, 04:32 AM |
|
|
Cool!
To track Adsense ads, I am guessing additional modification will need to be made. I am trying to make an adsense tracker too, and these are the javascript codes that I've so far discovered on the net to do it: (P.S: The JS code below isn't enough to track adsense clicks, you need a script on the sever too) : adsense_clicklogger.js HTML <script type="text/javascript"> <!-- // THIS CODE MUST BE **AFTER** THE ADSENSE CODE function adsense_log_click() { if(window.status.indexOf('go to') == 0) { adsense_log_url_image = new Image(); adsense_log_url_image.src = '/adsense_clicklogger.php?R=' + escape(document.location) + '&U=' + escape(window.status.substring(6)); } } var elements; if(document.getElementsByTagName) { elements = document.body.getElementsByTagName("IFRAME"); } else if (document.body.all) { elements = document.body.all.tags("IFRAME"); } else { elements = Array(); } for(var i = 0; i < elements.length; i++) { if(elements[i].src.indexOf('googlesyndication.com') > -1) { elements[i].onfocus = adsense_log_click; } } //--> </script> Corresponding server side PHP code for use with above JS script (adsense_clicklogger.php): CODE <?php /* ADSENSE CLICK LOGGER VIEWER AND RECORDER SCRIPT IN PHP VERSION 1.0, March 20, 2004 To view your stats, open adsense_clicklogger.php in your browser. SETUP: 1. create the table using the mysql create table command below. 2. enter the site database definitions 3. enter the clicklogger javascript code in your web pages 4. make sure that javascript code points to this script */ // These are the parameters for connecting to the database. define ("SITE_DATABASE_HOSTNAME", "localhost"); define ("SITE_DATABASE_PASSWORD", "password"); define ("SITE_DATABASE_USERNAME", "username"); define ("SITE_DATABASE_DATABASE", "database"); /* CREATE TABLE tblAdsenseClicks ( AdsenseClickID INT PRIMARY KEY AUTO_INCREMENT, ClickDate DATETIME, DestinationPage VARCHAR(255), SourcePage VARCHAR(255), RemoteAddress VARCHAR(255), RemoteHost VARCHAR(255) ) */ if(isset($_GET['U'])) { $DestinationPage = mysql_escape_string(substr(trim($_GET['U']),0,255)); } else { $DestinationPage = ""; } if(isset($_GET['R'])) { $SourcePage = mysql_escape_string(substr(trim($_GET['R']),0,255)); } else { $SourcePage = ""; } if($DestinationPage != "" && $SourcePage != "") { $RemoteAddress = mysql_escape_string(substr(trim($_SERVER['REMOTE_ADDR']),0,255)); $RemoteHost = mysql_escape_string(substr(trim($_SERVER['REMOTE_HOST']),0,255)); $query = "INSERT INTO tblAdsenseClicks ". " (ClickDate,DestinationPage,SourcePage,RemoteAddress,RemoteHost) ". " VALUES (". " '".date("Y-m-d H:i:s")."',". " '".$DestinationPage."',". " '".$SourcePage."',". " '".$RemoteAddress."',". " '".$RemoteHost."')"; run_query($query); exit(); } // Show the statistics page if the U and R variables are not given ?> <html><head><title>Adsense click stats</title> <style type="text/css"> table.clickstats { border-collapse: collapse; } table.clickstats th { color: white; background-color: #000080; border: 1px solid #999999; padding: 3px; } table.clickstats td { border: 1px solid #999999; text-align: center; } </style> </head> <body><?php $query = "SELECT ClickDate,DestinationPage,SourcePage,RemoteAddress,RemoteHost ". " FROM tblAdsenseClicks ORDER BY ClickDate "; print_query($query,"clickstats"); print "</body></html>"; // Connects to the site defined database and returns the connection handle. // Uses a persistent connection and does error checking. function connect_to_site_database() { // Connect to the mysql server $link = mysql_pconnect(constant("SITE_DATABASE_HOSTNAME"), constant("SITE_DATABASE_USERNAME"), constant("SITE_DATABASE_PASSWORD")) or die("Unable to connect to site database!"); // Select the database mysql_select_db(constant("SITE_DATABASE_DATABASE")) or die("Unable to select database: ".constant("SITE_DATABASE_DATABASE")); return $link; } // Standard function to run a query, with error checking. // Returns the resultset. function run_query($query) { // Connect to the database connect_to_site_database(); // Run the query $result = mysql_query ($query) or die ("Invalid query: $query"); // Return the result set return $result; } // prints the query results in a table with the given table style class function print_query($query, $table_class) { connect_to_site_database(); // Select all the records from the addressbook and store them in $result $result = mysql_query ($query) or die ("Invalid query: $query"); // Get the number of columns (or fields) in the results $num_fields = mysql_num_fields ($result); // Get the number of rows in the results $num_rows = mysql_num_rows ($result); // Start printing the table to show all the records echo "<table class=\"$table_class\">\n"; echo "<tr>"; // Print out all the field names as the first row table header $i=0; while ($i < $num_fields) { // Get the field name from the result $fname = mysql_field_name ($result, $i); echo "<th>".$fname."</th>"; $i=$i+1; } echo "</tr>\n"; // Now print out all the data while ($row = mysql_fetch_row ($result)) { echo "<tr>"; $k=0; while ($k < $num_fields) { echo "<td>".$row[$k]."</td>\n"; $k=$k+1; } echo "</tr>\n"; } echo "</table>\n"; // Do a little clean up mysql_free_result($result); } ?> I didn't code this, but found it on the net. Sorry can't remember who wrote it ... One problem I heard someone mention is that it doesn't track adsense clicks in Firefox. It doesn't look like it violates any Google Adsense TOS, but use it at your own risk. This JS script coded by Jim Rutherford can track adsense clicks on Firefox too. (You CANNOT use this with the above PHP script without modifying it): HTML // incredibly funky onload add-event scripting, for all browsers if(typeof window.addEventListener != 'undefined') { //.. gecko, safari, konqueror and standard window.addEventListener('load', adsense_init, false); } else if(typeof document.addEventListener != 'undefined') { //.. opera 7 document.addEventListener('load', adsense_init, false); } else if(typeof window.attachEvent != 'undefined') { //.. win/ie window.attachEvent('onload', adsense_init); } //** remove this condition to degrade older browsers else { //.. mac/ie5 and anything else that gets this far //if there's an existing onload function if(typeof window.onload == 'function') { //store it var existing = onload; //add new onload handler window.onload = function() { //call existing onload function existing(); //call adsense_init onload function adsense_init(); }; } else { //setup onload function window.onload = adsense_init; } } function adsense_init () { if (document.all) { //ie var el = document.getElementsByTagName("iframe"); for(var i = 0; i < el.length; i++) { if(el[i].src.indexOf('googlesyndication.com') > -1) { adUnit = i+1; browser = "IE"; adunitsize = el[i].width + "x" + el[i].height; el[i].onfocus = trackAdsense; } } } else { // firefox window.addEventListener('beforeunload', doPageExit, false); window.addEventListener('mousemove', getMouse, true); } } //for firefox var px; var py; var adUnit = ""; var browser = ""; var adunitsize = ""; function getMouse(e) { px=e.pageX; py=e.clientY; } function findY(obj) { var y = 0; while (obj) { y += obj.offsetTop; obj = obj.offsetParent; } return(y); } function findX(obj) { var x = 0; while (obj) { x += obj.offsetLeft; obj = obj.offsetParent; } return(x); } function doPageExit(e) { ad = document.getElementsByTagName("iframe"); for (i=0; i<ad.length; i++) { var adLeft = findX(ad[i]); var adTop = findY(ad[i]); var inFrameX = (px > (adLeft - 10) && px < (parseInt(adLeft) + parseInt(ad[i].width) + 15)); var inFrameY = (py > (adTop - 10) && py < (parseInt(adTop) + parseInt(ad[i].height) + 10)); if (inFrameY && inFrameX) { adUnit = i+1; browser = "Firefox"; adunitsize = ad[i].width + "x" + ad[i].height; trackAdsense(); } } } //end for firefox function trackAdsense() { var path = '<?php echo $Mint->cfg['install_dir'] . "pepper/" . $this->info['src'] . "data.php"; ?>'; // can't use encodeURIComponent everywhere. escape() should work for this scenario path += "?from_title="+escape(document.title); path += "&from="+escape(self.location); path += "&unit="+escape(adUnit); path += "&browser="+escape(browser); path += "&adunitsize="+escape(adunitsize); var data = false; /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { data = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { data = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { data = false; } } @end @*/ if (!data && typeof XMLHttpRequest!='undefined') data = new XMLHttpRequest(); if (data) data.open("GET", path, false); data.send(null); } I am sure eKstreme won't have any probs in integrating this with his script ... |
||
| Offline | ![]() |
Star Member![]() ![]() Group: 1000 Post Club
Joined: 15-August 04
Posts: 1,071
|
Mar 4 2006, 10:25 AM |
|
|
First, Adsense Advisor (a Google representative) has said that that Google doesn't have any problems with such trackers. (The tracker shouldn't employ redirects or change or meddle with the adsense URL in anyway).
Second, testing is a bit hard. QUOTE I guess I could install it on my sites and come back to it a few days later ...Would others be willing to try it out? No mine. Please come and click on the ads on my blog to test it out. Hehe. More than the tracker, that would surely get you kicked out of Adsense - for soliciting clicks. There is an easy way to test this without violating the Adsense TOS you agreed to - create a User JavaScript for Opera with your tracker javascript. Attach it to 2 or 3 sites having adsense (not yours), and click on their ads ... (ah you are going to make some webmasters real happy This post has been edited by whitemark: Mar 4 2006, 06:17 PM |
||
| Offline | ![]() |
|
|
2 Pages 1 2 >
|
|
| Lo-Fi Version | Time is now: 9th February 2010 - 04:19 PM |
| Meet our Moderators: | cre8pc : projectphp : sanity : Black Phoenix : bwelford : EGOL : Ruud : rustybrick : AbleReach : swainzy : joedolson: eKstreme: dazzlindonna : SEOigloo: iamlost : RisaBB |