Track Google Adsense Clicks with JavaScript

What I'm trying to do is track how a user clicks on Google Adsense. Two types of ads are created, including the Google Adsense script tag.

  • Imagebanner (one click on the banner redirects the user to the ad)
  • Banner with one or more links (the user must click the link to get a redirect)

I have problems with the second type of banner.
A link has two frames. It is very easy to track a click if the user mouse is on an external iframe. But in fact, I canโ€™t access the second iframe to track the click if the user clicks the link (tag). Therefore, if the user clicks on a space in the banner, my function also considers it a click. The reason is quite obvious: Google denies this.
I donโ€™t want to manipulate Google code, I just want to track click.

+6
source share
2 answers

Iโ€™m not quite sure if this is allowed by AdSense, since you can abuse the system by tracking clicks on ads (for example, blocking content). In addition, you will come across different cases of edges - like the one you asked - why I usually recommend you the following:

What you probably want to do is connect Google Analytics to AdSense (it's as simple as 1-2 clicks) so you can easily go to the publisher โ†’ AdSense in the Google Analytics toolbar to see impressions, clicks, and more AdSense data. You can always create your own reports that can access this data.

If you really want to track clicks, you can check out this iframe tracker that uses event blurring to determine which element / iframe the mouse cursor is currently hovering over.

+1
source

Assuming the banner has a .banner class, you can track as follows:

 $('.banner').on('click', function(e) { ga('send','event',{eventCategory:'BannerClick', eventAction:e }); }); 
0
source

Source: https://habr.com/ru/post/981019/


All Articles