views:

158

answers:

4

I want to register user clicked on ads and save users info to database without change ads operation.

<div>
<a>ads link</a>  // without modify ads
<a>ads link</a>
<a>ads link</a>
<a>ads link</a>
</div>

how to update user info to database before load link ads.

Please help.

+3  A: 

You can do it in the callback of the click method:

$('a.special').click( function(){
    $.post( '/someUrl.php', { data: userID});    
});

a.special will only get the links with class='special'

Elzo Valugi
Will this work for users who middle-click on the ads, to open them in new browser tabs ?
Pascal MARTIN
A JQuery click should register only a default click (i.e. Left click). Maybe a mouse-down+up combination might work for any form of clicks?
o.k.w
tnx. This solution catching any links on mysite. I want to catch only ads links.This may seprated div tag.Sorry for my english and asking basic questions.
@kani check the updates / you just have to add a class to your designated links
Elzo Valugi
+1  A: 

what about a script which registers what the user clicked?

<a href="register_script.php?advertise_id=7">Nike - the new shoe</a>

with the GET parameter you can load & save all you want in the register_script about your advertise, user etc pp.!

Of course your database must saved the adress of your advertise... like that: * SELECT link_adress FROM advertise_manager WHERE id='add_slashes($_GET['advertise_id'])'

At the end the script heads your user to the target site with:

headers("Location: http//www.thisIsMyAdvertise.com");
Sounds like the OP doesn't want to fiddle around with the ads and the links already on the page and is looking for a way to detect without having to change any of the current links.
random
A: 

Elzo's idea would be a possibility but keep in mind in that case a click on any link (even it isn't a Ad would be registered).

Two questions: What do you intend with "without change ads operation"? Can you touch the links in your ads and redirect them? Or no e.g. if it is Google AdSense?

Is it Enough to know if a user clicked on a Ad or do you need to know also on which Ad the user clicked?

Maybe, you can add CLASS-Tags to the advertising links and using Elzo's idea but using the "AdLink", insted of "a".

Something like:

<div>
<a class="AdLink">ads link</a>  // without modify ads
<a class="AdLink">ads link</a>
<a class="AdLink">ads link</a>
<a class="AdLink">ads link</a>
</div>

and:

$('AdLink').click( function(){
    $.post( '/someUrl.php', { data: userID});    
});

This is untested but in my opinion it should work.

If you need to know on which link the user clicked, you can add ID-Tags to the advertising links and using Elzo's idea but using the jQuery Selector based on ID's (#) instead of classes ($).

This woul be something like:

<div>
<a Id="AdLink1">ads link</a>  // without modify ads
<a Id="AdLink2">ads link</a>
<a Id="AdLink2">ads link</a>
<a Id="AdLink3">ads link</a>
</div>

and:

$('AdLink').click( function(){
    $.post( '/someUrl.php', { data: userID});    
});

In this case you need also to foreward the Id which AdLink has been clicked.

john84
+1  A: 

You can use Google Analytics for tracking clicks on outbound links. To do that in a single link you should add the following onclick attribute on the link's tag:

<a href="http://www.example.com" onClick="javascript: pageTracker._trackPageview('/outgoing/example.com');">

If you have severals link's tag you can add the onclick attribute on all '<a../>' using the following javascript:

<script type="text/javascript">
    labels = document.getElementsByTagName("a");
    for( var i = 0; i < labels.length; i++ ) {
     labels[i].onclick = function(){
      pageTracker._trackPageview("/outgoing/"+this.href.replace("http://","").replace("https://",""));
     };
    }
</script>
Carlos Mayo
Carlos, where did you find this page tracker code? I imagine this is on analytics somewhere. I can't find it.
Anthony