Results 1 to 1 of 1
Threaded View
-
10th Apr 2012, 06:20 PM #1OP
google adsense ad clicks count [help]
hello
KWWHs
please help me
i want to count google adsense ad click count is that when a visitor click on google ad it count and save to my mysql database.but it wouldn't work for google ad insted it work for another hyper link like <a href="#">hello</a>
please help me here all of script
1.this is the page where ad shows is example_page.html
PHP Code:<html>
<head>
<title>Some page</title>
</head>
<body>
<!--The gStats must by within body tag-->
<script>
var userID = 1; /*Some id, to make diference for subdomains. it must be numberic*/
var trackURL='example_track.php'; /* This is the page that store the information about the visitor. */
</script>
<script src="gStats.js"></script>
<!--end of gStats-->
This page will record information about the user. From there the user come, where he/she's going(where he/she clicks). Also it will be provide information when a user click on Google-Ads
<script type="text/javascript"><!--
google_ad_client = "ca-pub-9812312120808535";
/* News Pluss - Banner Bottom */
google_ad_slot = "1484559686";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<a href="#">hello</a>/*this is working*/
</body>
</html>
PHP Code:<!--
/*
** Cesar D. Rodas
** gStats could be downloaded freely from
** http://cesars.users.phpclasses.org/gstats
*/
if(typeof(trackURL) == 'undefined')
var trackURL = "example_track.php";
if(typeof(userID) == 'undefined')
var userID = "noid";
function gStats_sleep(numberMillis){
var now=new Date();
var exitTime=now.getTime()+numberMillis;
while(true){
now=new Date();
if(now.getTime()>exitTime) break;
}
}
function isTag(tag,elem){
return elem.nodeName.toUpperCase()==tag.toUpperCase();
}
/*
** This function call other page and pass values by get.
** also sleep a few of time
*/
function gStats_callPage(url,sleep) {
var elem= document.createElement('IMG');
elem.src=url;
if (sleep) gStats_sleep(900);
}
/*
** Google-Ads and Yahoo! Ads tracker
**
*/
function isGoogleAdsIframe(iframe) {
return iframe.src.indexOf('googlesyndication.com') > -1;
}
function isYahooAdsIframe(iframe) {
return iframe.src.indexOf('ypn-js.overture.com') > -1;
}
var iAds = Array();
var isIE = is_ie=document.all?true:false;
var MouseX, MouseY;
function mouse_info(elem) {
if(!elem) elem = window.event;
if (elem.pageX || elem.pageY) {
MouseX = elem.pageX;
MouseY = elem.pageY;
} else if ( elem.clientX || elem.clientY) {
xbody = document.body;
MouseX = elem.clientX + xbody.scrollLeft + document.documentElement.scrollLeft;
MouseX = elem.clientY + xbody.scrollTop + document.documentElement.scrollTop;
}
}
function getIframePos(elem) {
var left, top;
if (elem.offsetParent) {
left = elem.offsetLeft;
top = elem.offsetTop;
while (elem=elem.offsetParent) {
left += elem.offsetLeft;
top += elem.offsetTop;
}
}
return [left,top];
}
function mozilla_adsTrack() {
try {
var mousepos = new Array(MouseX, MouseY);
for(i=0; i < iAds.length; i++) {
ads = iAds[i];
adspos = getIframePos( ads[0] );
valid = true;
for (e=0; e < 2; e++) {
if (e==0)
suma = parseInt(adspos[e]) + parseInt(ads[0].width) +15;
else
suma = parseInt(adspos[e]) + parseInt(ads[0].height) +15;
valid = valid && ( mousepos[e] > (adspos[e]-10) && mousepos[e] < suma );
}
if (valid) {
adsTrackIt(ads[0]);
break;
}
}
} catch (err) { }
}
function adsTrackIt(ads) {
try {
if (!ads && window.event.srcElement)
var ads = window.event.srcElement;
for(i=0; i < iAds.length; i++) {
if (iAds[i][0] == ads) {
var now=new Date();
var url = escape(document.location.href);
var adsSize = iAds[i][0].width +'x' + iAds[i][0].height;
var newURL= trackURL +'?url=' + url + '&ads=' + escape(iAds[i][2]) + '&adsize=' + adsSize +'&no_cache=' + now.valueOf() + '&usrId=' + userID;
gStats_callPage(newURL, true);
break;
}
}
} catch (err) {}
}
function adsTracker() {
var ads=document.getElementsByTagName('iframe');
/* now nav al_l the ads*/
for(var i=0;i<ads.length;i++) {
if( isGoogleAdsIframe(ads[i]) ) {
iAds[iAds.length] = new Array(ads[i], 'http://pagead2.googlesyndication.com', 'Google AdSense');
if (isIE) ads[i].onfocus= adsTrackIt;
} else if ( isYahooAdsIframe(ads[i]) ) {
iAds[iAds.length] = new Array(ads[i], 'http://ypn-js.overture.com', 'Yahoo! Ads');
if (isIE) ads[i].onfocus= adsTrackIt;
}
}
if(iAds.length>0 && !isIE){
gStats_RegisterEvent(window, 'beforeunload', mozilla_adsTrack);
gStats_RegisterEvent(document, 'mousemove', mouse_info);
}
}
/*
** The following two functions register and unregister
** events callback functions.
*/
function gStats_RegisterEvent(obj, event, action) {
if(window.addEventListener){
obj.addEventListener(event, action, false);
} else if(window.Event){
obj.attachEvent('on'+event, action);
}
}
function gStats_RegisterUnEvent(obj, event, action) {
if(window.addEventListener){
obj.removeEventListener(event, action, false);
} else if(window.attachEvent){
obj.detachEvent('on'+event, action);
}
}
/*
** This function create a IMG html element that send for get the
** parameters to the track collector
*/
function gStats_trackIt(url,text){
try{
var now=new Date();
var url = escape(url);
var text = escape(text);
var from = escape(document.location.href);
var newURL= trackURL +'?url='+url+'&text='+text+'&from='+from +'&no_cache='+now.valueOf() + '&usrId=' + userID;
gStats_callPage(newURL,true);
}catch(err){}
}
/*
**
**
*/
function searchClickedTag(obj, flag){
for(var j=0;j<=5;j++){
if(flag==1){
if(obj&&obj.nodeName.toUpperCase()=='A'){
return obj;
}
}
if(flag==2){
if(obj&&obj.nodeName.toUpperCase()!='BODY'&&obj.onclick){
return obj;
}
}
if(!obj.parentNode) {
return null;
}
obj=obj.parentNode;
}
return null;
}
function getInfo(elem) {
var url=null, text=null;
if(elem){
elemInfo=searchClickedTag(elem, 1);
if ( elemInfo && !isTag('A', elem) )
elem = elemInfo;
if( isTag('A', elem) ){
url = elemInfo.href;
if(elem.innerHTML) text=elem.innerHTML;
else if(elem.innerText) text=elem.innerText;
else if(elem.text) text=elem.text;
}
if (url || text)
gStats_trackIt(url,text);
}
}
/*
** Sends information to the server about the page-referer
*/
function gStats_sendRefererInfo() {
try{
var now = new Date();
var url = escape(document.location.href);
var referer = document.referrer;
var useragent = escape(navigator.userAgent.toLowerCase());
if(referer !='' ){
var referer = '&referer='+escape(referer);
}else{
var referer='&referer=direct';
}
var newURL = trackURL +'?'+ referer + '&url=' + url +'&no_cache='+now.valueOf()+ '&browser=' + useragent + '&usrId=' + userID;
gStats_callPage(newURL,false);
}catch(err){ }
}
/*
** Tracks every click.
** Useful for know where user click and where he/she go
*/
function onClick_Tracker(elemtClicked) {
gStats_Tracking(elemtClicked,true);
}
function Context_Tracker(elemtClicked) {
gStats_Tracking(elemtClicked,false);
}
function gStats_Tracking(elemt) {
var elem=null;
if(elemt){
elem=elemt.target;
} else {
elem=window.event.srcElement;
}
getInfo(elem);
}
function gStats_init() {
if (document.body)
elem = document.body;
else if (document)
elem = document;
elem.onclick = onClick_Tracker;
elem.oncontextmenu = Context_Tracker;
gStats_sendRefererInfo();
gStats_RegisterEvent(window, 'load', adsTracker);
}
/*
** Start tracking :)
*/
gStats_init();
-->
PHP Code:<?php
class gStats {
var $visitorID;
var $mysql;
var $siteId;
function gStats($mysql) {
@session_start(); /* every visitor if know as be unique */
$this->mysql = $mysql;
$this->getVisitorId();
$this->siteId = $this->getvalue('usrId');
if ( $this->isReferer() )
$this->saveReferer();
else if ($this->isAds())
$this->saveAds();
else if ( $this->isOutlinkInfo() )
$this->saveOutLink();
}
function getVisitorId() {
if (!isset($_SESSION['visitorId'])) {
$sql = "insert into gstats_unique_visitors(cookieId,IP,startTime,`user-agent`) values ";
$sql .= "('".session_id()."','".$this->getip()."',now(),'".$this->user_agent()."')";
mysql_query($sql,$this->mysql) or die(mysql_error($this->mysql));
$_SESSION['visitorId'] = mysql_insert_id();
}
}
function isAds() {
return isset($_GET['ads']);
}
function saveAds() {
$url = $this->getvalue('url');
$to = $this->getvalue('ads');
$size = $this->getvalue('adsize');
$url = $this->cleanURL($url);
$sql = "insert into gstats_ads_click values('".$this->siteId."','".$_SESSION['visitorId']."','${url}','${to}','${size}',now())";
mysql_query($sql,$this->mysql) or $this->mysql_error(__LINE__);
return true;
}
/*
** Saving outlink information
*/
function isOutlinkInfo() {
return true;
}
function saveOutLink() {
$url = $this->getvalue('from');
$to = $this->getvalue('url');
$text = $this->getvalue('text');
if ($url === false || $to === false || $text === false)
return false;
$url = $this->cleanURL($url);
$to = $this->cleanURL($to);
$sql = "insert into gstats_out_clicks values('".$this->siteId."','".$_SESSION['visitorId']."',now(),now(),'${url}','${to}','${text}')";
@mysql_query($sql,$this->mysql) or $this->mysql_error(__LINE__);
return true;
}
/*
** Saving referer information
*/
function isReferer() {
return isset($_GET['referer']);
}
function saveReferer() {
$referer = $this->getvalue('referer');
$url = $this->getvalue('url');
if ($url === false || $referer === false)
return false;
$url = $this->cleanURL($url);
$sql = "insert into gstats_referer_info values('".$this->siteId."','".$_SESSION['visitorId']."',now(),now(),'${url}','${referer}')";
@mysql_query($sql,$this->mysql) or $this->mysql_error(__LINE__);
return true;
}
/*
**
*/
function mysql_error($line) {
$f = fopen("mysql.log","a");
fwrite($f,$line.":".mysql_error($this->mysql)."\r\n\r\n\r\n");
fclose($f);
}
function getvalue($var) {
return isset($_GET[$var]) ? addslashes($_GET[$var]) : false;
}
function user_agent() {
return $this->getvalue('browser');
}
/*
** Common functions
*/
function getip() {
return $_SERVER['REMOTE_ADDR'];
}
function cleanURL($url) {
$tmp = explode("#",$url,2);
return $tmp[0];
}
}
?>
PHP Code:<?php
/*
** gStats.
** What this example do is to show how to gather information,
** sended by javascript.
*/
include("gStats.php"); #including the class
#Opening the Database
#set $host, $user, $pass, $db for it can works.
$mysql = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("google clicks",$mysql) or die(mysql_error($mysql));
#Starting the tracking, passing as argument a valid MySQL connection
$stats = new gStats($mysql);
?>
PHP Code:DROP TABLE IF EXISTS `gstats_out_clicks`;
CREATE TABLE `gstats_ads_click` (
`userId` int(11) NOT NULL,
`visitor` int(11) NOT NULL,
`page` varchar(250) NOT NULL,
`ads` varchar(50) NOT NULL,
`size` varchar(10) NOT NULL,
`dtime` datetime NOT NULL
);
DROP TABLE IF EXISTS `gstats_out_clicks`;
CREATE TABLE `gstats_out_clicks` (
`usrId` int(11) NOT NULL,
`visitorId` int(11) NOT NULL,
`date` date NOT NULL,
`time` time NOT NULL,
`url` varchar(250) NOT NULL,
`goto` varchar(250) NOT NULL,
`text` text NOT NULL,
KEY `usrId` (`usrId`,`date`)
) ;
DROP TABLE IF EXISTS `gstats_referer_info`;
CREATE TABLE `gstats_referer_info` (
`usrId` int(11) NOT NULL,
`visitorId` int(11) NOT NULL,
`date` date NOT NULL,
`time` time NOT NULL,
`url` varchar(250) NOT NULL,
`referer` varchar(250) NOT NULL,
PRIMARY KEY (`usrId`,`visitorId`,`url`),
KEY `usrId` (`usrId`,`date`)
) ;
DROP TABLE IF EXISTS `gstats_unique_visitors`;
CREATE TABLE `gstats_unique_visitors` (
`visitorId` int(11) NOT NULL auto_increment,
`cookieId` varchar(32) NOT NULL,
`IP` varchar(15) NOT NULL,
`startTime` datetime NOT NULL,
`user-agent` varchar(100) NOT NULL,
PRIMARY KEY (`visitorId`)
) ;
DROP TABLE IF EXISTS `gstats_users`;
CREATE TABLE `gstats_users` (
`usrId` int(11) NOT NULL auto_increment,
`usrEmail` varchar(50) NOT NULL,
`usrPass` varchar(50) NOT NULL,
`usrSite` varchar(50) NOT NULL,
PRIMARY KEY (`usrId`),
KEY `usrEmail` (`usrEmail`)
) ;
shakac Reviewed by shakac on . google adsense ad clicks count [help] hello KWWHs please help me i want to count google adsense ad click count is that when a visitor click on google ad it count and save to my mysql database.but it wouldn't work for google ad insted it work for another hyper link like <a href="#">hello</a> please help me here all of script 1.this is the page where ad shows is example_page.html <html> <head> <title>Some page</title> Rating: 5
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
many impressions and few clicks (google webmaster)
By ctoveloz in forum Webmaster DiscussionReplies: 9Last Post: 16th Aug 2011, 06:59 AM -
[Selling] Make your own Automated News Empire, 4 Designs, First time on KWWH, Count $$ Adsense $$
By intensecool in forum Completed TransactionsReplies: 0Last Post: 22nd Jul 2011, 05:36 AM -
Warning about buying Google +1 clicks
By Mr Happy in forum Webmaster DiscussionReplies: 11Last Post: 20th Jul 2011, 09:15 PM -
adsense clicks-Help
By toothmaniac in forum Technical Help Desk SupportReplies: 6Last Post: 7th May 2011, 03:33 AM
themaPoster - post to forums and...
Version 5.35 released. Open older version (or...