简体   繁体   English

制作Google AdSense广告,以便在点击时执行此功能

[英]Making a Google AdSense ad to do a function when clicked

Okay, I'm trying to put tags around a Google AdSense ad that will call a function when someone clicks the ad. 好的,我正试图在Google AdSense广告周围添加标签,以便在有人点击广告时调用该功能。

I've tried to put tags around it but for some reason it's only taking effect for what's around the ad, not the ad text/picture itself. 我试图在它周围添加标签,但出于某种原因,它只对广告周围的内容生效,而不是广告文字/图片本身。

This has nothing to do with gaining more clicks or what ever, it's just gonna simply log in a text file how many people have clicked it. 这与获得更多点击或任何事情无关,它只是简单地登录一个文本文件,有多少人点击了它。

Here's what I've tried so far, and it only takes effect for the space around the ad. 这是我到目前为止所尝试的内容,它只对广告周围的空间生效。

        <div id="ad" onClick="return alert('Hello');">
<script type="text/javascript">
google_ad_client = "ca-pub-0000000000000";
google_ad_slot = "000000000000";
google_ad_width = 250;
google_ad_height = 250;
</script>

<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

Can someone help me or is this even possible? 有人可以帮助我,还是这可能?

AdSense ads are loaded in an iFrame. AdSense广告已加载到iFrame中。 You can't capture clicks from them by bubbling, due to sandbox security issues. 由于沙箱安全问题,您无法通过冒泡捕获来自它们的点击。 Nor can you trigger clicks on an ad via JavaScript. 您也无法通过JavaScript触发广告点击。

What you can do, though, is track page focus to determine whether someone has clicked off and "guess" if they clicked the ad. 但是,你可以做的是跟踪页面焦点,以确定是否有人点击了“猜测”是否他们点击了广告。

I've done this before with pretty darn good results, using this tutorial: 我之前使用本教程完成了非常好的结果:

http://www.bennadel.com/blog/1752-Tracking-Google-AdSense-Clicks-With-jQuery-And-ColdFusion.htm http://www.bennadel.com/blog/1752-Tracking-Google-AdSense-Clicks-With-jQuery-And-ColdFusion.htm

It's not 100% accurate, but it's the best you can do. 它不是100%准确,但它是你能做的最好的。 Basically, when you mouseover the iFrame, it sets a state to watch for loss of focus to your main window. 基本上,当您将鼠标移到iFrame上时,它会设置一个状态来监视主窗口失去焦点。 If that happens, it assumes the document lost focus because the user clicked on the iFrame. 如果发生这种情况,它会假定文档失去焦点,因为用户点击了iFrame。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM