戴尔 - 台式机

戴尔 - 笔记本

Google广告统计点击次数的方法

注册中国移动飞信

象Google的广告,展示啥内容,都是由Google自己控制的,使用普通的页面提交连接的方式,我们是无法统计我们页面上的Google广告被点击了多少次,被谁点击了。因为这些页面都不受我们控制。下面介绍一个可以统计Google那样广告点击次数的方法。

下面代码中,我们在点击、移动等事件中,判断用户点击的是不是某个需要的范围内。然后进行计数,如果我们需要额外的记录,可以在这些事件函数中,向 一个我们可控的页面进行提交。为了不影响页面的展示,这个页面被提交的页面,是在一个隐含的IFrame中实现的,具体看上述代码就明白了。

通过以上的方法,我们就可以实现不论点本网站的自己广告,还是Google广告,每点击一次,增加多少可用分这类的逻辑了。(当然这个逻辑可以更复杂)

代码:

<html>

<head>

<title>点击计数</title>

<script language="javascript">

<!--

function keyDown(e)

{

if (event.srcElement.tagName=='IFRAME'

&& event.clientX==-1

&& event.clientY==-1

&& event.fromElement=='[object]'){

// 如果需要向其他页面提交

//document.adform.submit();

var num = parseInt(shownum.innerHTML);

shownum.innerHTML = num 1;

}

return false;

}

document.onmousemove=keyDown;

document.onmouseover=keyDown ;

document.onmouseout=keyDown ;

document.onblur=keyDown;

//-->

</script>

</head>

<body>

<!-- 如果需要向另外一个页面传递参数,可以用下面的方式//-->

<form name="adform" method="post" action="ad_click.php" target='ad_click'>

<input name="uid" value='1922' type="hidden" id="uid">

<input name="keyid" type="hidden"

value='1119342517' id="keyid">

<input name="aid" type="hidden" id="aid">

</form>

<iframe name='ad_click' marginwidth="0"

marginheight="0" frameborder="0" scrolling="no"

src="http://www.adsenser.cn/adsense-news/about:blank" width="0" height="0">

</iframe>

<!--页面提交代码结束//-->

点击IFrame中的次数:<div id="shownum">

0</div>

<iframe name='ad_click' marginwidth="0"

marginheight="0" frameborder="0" scrolling="no"

src="http://www.csdn.net/" width="100"

height="100" style="width: 616px; height: 171px">

</iframe>

<br />

<br />

<a "http://key.admin5.com/" target="_blank">本页其它连接</a>

</body>

</html>


【注册Google adsense帐号】


编辑:Adsense 来源:Google adsense 时间:2007-03-23
|打印

站内搜索

栏目推荐:

本栏目热门: