I have a website and I am user of several Affiliate Programs.
How can I track which ones of the banners are being clicked by my visitors?
My website has basically two types of advertisement:
- Images with links
- Banners provided by the affiliate programs (usually it is an empty div, with a JavaScript code to retrieve the banner on demand on the Affiliate Program’s server)
So I had the idea to put every advertisement block of my website inside DIVs that have a given class, so every time the user clicks on one of the children, I can make a request to acknowledge this click on my Database (Note that this part is not explicit on the code). But this is not working. Probably due to a false jQuery selector usage.
Out of curiosity: Is there any plug-in for this usage?
CODE
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$(".ad").children().live("click", function(event) {
var id = $(this).attr("id");
alert(id); //should alert ad-1 or ad-2
});
$(".ad-affiliate").children().live("click", function(event) {
var container = $(this).find(".affiliate-container");
var id = container.attr("id");
alert(id); //should alert affiliate-1
});
});
</script>
</head>
<body>
<div class="ad">
<a target="_blank" href="#">
<img id="ad-1" src="src1.png"/>
</a>
<a target="_blank" href="#">
<img id="ad-1" src="src1.png"/>
</a>
</div>
<div class="ad-affiliate">
<div id="affiliate-1" class="affiliate-container">
<!-- THIS CONTENT IS GIVEN BY THE CODE PROVIDED BY THE AFFILIATE PROGRAM -->
<!-- It is usually a div with a JavaScript code that populates the div with the content -->
</div>
</div>
</body>
</html>
Try this:
Example here: http://jsfiddle.net/eLUQd/2/