GoogleAds广告点击统计

数据库结构:ID,URL,ClickTime,FromUrl,URLcorp,ClickIP 1、将googleAds文件夹上传至你空间的根目录下 2、修改googleAdCount.js里的网址 3、在需要统计的网页中添加如下代码: <script language=”javascript” src=”http://网址/googleAds/googleAdCount.js”></script> 或者: [GS=JavaScript]<script language=”javascript” > function log() { bug = new Image(); if (window.status.indexOf(‘go to’) == 0) { bug.src = ‘http://mysheji.com/googleAds/AdsClick.asp?action=tongji&url=’ + document.location + ‘&URLcorp=’ + window.status.substring(6); document.cookie = “gcookie=clicked;expires=”+ Then.toGMTString(); } if (window.status.indexOf(‘查看关于’) == 0) { bug.src = ‘http://mysheji.com/googleAds/AdsClick.asp?action=tongji&url=’ + document.location + ‘&URLcorp=查看关于 ‘ + window.status.substring(5); } if (window.status.indexOf(‘键连至’) == 0) { bug.src = ‘http://mysheji.com/googleAds/AdsClick.asp?action=tongji&url=’ + document.location + ‘&URLcorp=’ + window.status.substring(4); } } var elements2; elements2 = document.getElementsByTagName(“iframe”); for (var i = 0; i < elements2.length; i++) { if(elements2[i].src.indexOf(‘googlesyndication.com’) > -1) { elements2[i].onfocus = log; } } </script>[/GS] 4、本统计系统适合统计gb2312编码的网站,如果是统计utf-8的网站,请将AdsClick.asp、 googleAdCount.js用记事本打开后另存为utf-8格式 AdsClick.asp文件内容 [GS=ASP] <%@LANGUAGE=”VBSCRIPT” CODEPAGE=”936″%> <% on error resume next Dim Conn,ConnStr,DBPath DBPath = “googleAds.mdb” ConnStr = “Provider = Microsoft.Jet.OLEDB.4.0;Data Source = ” & Server.MapPath(DBPath) ‘——————————————————————————————— Public Function Checkstr(Str) ‘字符过滤 If Isnull(Str) Then CheckStr = “” Exit Function End If CheckStr = Replace(Str,”‘”,”””) End Function ‘——————————————————————————————- Function OpenDB() ‘打开数据库 On Error Resume Next Set Conn = Server.CreateObject(“ADODB.Connection”) Conn.open ConnStr If Err Then err.Clear Set Conn = Nothing Response.Write “数据库连接错误” Response.End End If End Function ‘——————————————————————————————– Function CloseDB() ‘关闭数据库 Conn.Close Set Conn = Nothing End Function ‘——————————————————————————————– function dangtianCount() ‘统计当日点击次数 dim dangtian dangtian=0 set rs=server.CreateObject(“ADODB.Recordset”) rs.open “Select * from GoogleAds “,conn,1,1 if rs.eof and rs.bof then dangtian=0 else do while not rs.eof if (year(rs(“ClickTime”))&month(rs(“ClickTime”))&day(rs(“ClickTime”)))=(year(now)&month(now)&day(now)) then dangtian=dangtian+1 rs.movenext loop end if rs.close set rs=nothing response.Write(dangtian) end function ‘——————————————————————————————– Dim URL,ClickTime,FromUrl,URLcorp,ClickIP,action ‘插入统计记录 action=trim(request(“action”)) URL=trim(request(“URL”)) ClickTime=now() FromUrl=trim(request.ServerVariables(“HTTP_REFERER”)) URLcorp=trim(request(“URLcorp”)) ClickIP = Request.ServerVariables(“HTTP_X_FORWARDED_FOR”) If ClickIP = “” Then ClickIP = Request.ServerVariables(“REMOTE_ADDR”) if URL=”” then URL=FromUrl if FromUrl=”” and URL=”” then response.End() If action=”tongji” then Call OpenDB set rs=server.CreateObject(“ADODB.Recordset”) rs.open “Select * from GoogleAds”,conn,1,3 rs.addnew rs(“URL”)=trim(URL) rs(“FromURL”)=trim(FromURL) rs(“ClickTime”)=ClickTime rs(“URLcorp”)=Replace(Replace(URLcorp,”https://”,””),”http://”,””) rs(“ClickIP”)=ClickIP rs.update rs.close set rs=nothing Call CloseDB end if ‘——————————————————————————————– ‘因为该系统为gb2312编码,所以需要获取的内容(有些内容为utf-8编码的网页)先转为gb2312 function UTF2GB(UTFStr) ‘utf-8转gb2312编码 for Dig=1 to len(UTFStr) if mid(UTFStr,Dig,1)=”%” then if len(UTFStr) >= Dig+8 then GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9)) Dig=Dig+8 else GBStr=GBStr & mid(UTFStr,Dig,1) end if else GBStr=GBStr & mid(UTFStr,Dig,1) end if next UTF2GB=GBStr end function function ConvChinese(x) A=split(mid(x,2),”%”) i=0 j=0 for i=0 to ubound(A) A(i)=c16to2(A(i)) next for i=0 to ubound(A)-1 DigS=instr(A(i),”0″) Unicode=”” for j=1 to DigS-1 if j=1 then A(i)=right(A(i),len(A(i))-DigS) Unicode=Unicode & A(i) else i=i+1 A(i)=right(A(i),len(A(i))-2) Unicode=Unicode & A(i) end if next if len(c2to16(Unicode))=4 then ConvChinese=ConvChinese & chrw(int(“&H” & c2to16(Unicode))) else ConvChinese=ConvChinese & chr(int(“&H” & c2to16(Unicode))) end if next end function function c2to16(x) i=1 for i=1 to len(x) step 4 c2to16=c2to16 & hex(c2to10(mid(x,i,4))) next end function function c2to10(x) c2to10=0 if x=”0″ then exit function i=0 for i= 0 to len(x) -1 if mid(x,len(x)-i,1)=”1″ then c2to10=c2to10+2^(i) next end function function c16to2(x) i=0 for i=1 to len(trim(x)) tempstr= c10to2(cint(int(“&h” & mid(x,i,1)))) do while len(tempstr)<4 tempstr=”0″ & tempstr loop c16to2=c16to2 & tempstr next end function function c10to2(x) mysign=sgn(x) x=abs(x) DigS=1 do if x<2^DigS then exit do else DigS=DigS+1 end if loop tempnum=x i=0 for i=DigS to 1 step-1 if tempnum>=2^(i-1) then tempnum=tempnum-2^(i-1) c10to2=c10to2 & “1” else c10to2=c10to2 & “0” end if next if mysign=-1 then c10to2=”-” & c10to2 end function ‘——————————————————————————————– function chinese2unicode(Str) ‘gb2312转utf-8编码 dim i dim Str_one dim Str_unicode for i=1 to len(Str) Str_one=Mid(Str,i,1) Str_unicode=Str_unicode&chr(38) Str_unicode=Str_unicode&chr(35) Str_unicode=Str_unicode&chr(120) Str_unicode=Str_unicode& Hex(ascw(Str_one)) Str_unicode=Str_unicode&chr(59) next Response.Write Str_unicode end function ‘——————————————————————————————– function cLeft(str,n) ‘截取规定长度字符 dim str1,str2,alln,Islefted str2 = “” alln = 0 str1 = str Islefted = false if isnull(str) then cleft = “” exit function end if for i_ = 1 to len(str1) nowstr = mid(str1,i_,1) if asc(nowstr)<0 then alln = alln + 2 else alln = alln + 1 end if if (alln<=n) then str2 = str2 & nowstr else Islefted = true exit for end if next if Islefted then str2 = str2 & “…” end if cleft = str2 end function ‘——————————————————————————————– function SafeRequest(ParaName,ParaType) ‘功能:防SQL注入 Dim ParaValue ParaValue=Request(ParaName) If ParaType=1 then If not isNumeric(ParaValue) then Response.write”<script>alert(‘网站出现异常错误:\n参数” & ParaName & “必须为数字型!’);</script>” response.Write”<b><font color=#cc0000>网站出现异常错误:

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部