Forum: Rails Spinoffs (closed, excessive spam) Using both href= and onclick=new Ajax.request to track outgoing links

Posted by Fonziguy (Guest)
on 2008-07-04 15:33
(Received via mailing list)
Hi,

I'm trying to track outgoing links on my site. When the user clicks on
a link, I want them to be taken to the site (href) and I also want a
background script call that records the link (via Ajax).

The script I have worked in development mode but only works
occasionally in production mode.

Is it possible to link to a new site and call an ajax request at the
same time?

Thanks
Posted by Diodeus (Guest)
on 2008-07-04 16:30
(Received via mailing list)
Yup, like this:

<a href="moo.htm" onclick="writeLog('moo');return false">

...where writelog() is a function that does your Ajax call.

Alternately, you can just get Google Analytics to log it:

http://www.google.com/support/analytics/bin/answer...
Posted by Fonziguy (Guest)
on 2008-07-04 18:38
(Received via mailing list)
Thanks for the reply Diodeus.

I see what you're saying, but won't the return false stop the link
from going to the href location?
Posted by Fonziguy (Guest)
on 2008-07-04 18:54
(Received via mailing list)
Thanks for the reply Diodeus.

I see what you're saying, but won't the return false stop the link
from going to the href location?
Posted by Diodeus (Guest)
on 2008-07-04 19:11
(Received via mailing list)
Nope, it does the opposite - it returns control to the link from being
intercepted by Javascript.
Posted by Jarkko Laine (jarkko)
on 2008-07-04 23:01
Attachment: smime.p7s (2,36 KB)
(Received via mailing list)
On 4.7.2008, at 20.11, Diodeus wrote:

>
> Nope, it does the opposite - it returns control to the link from being
> intercepted by Javascript.

Err, no, it doesn't. It stops the link from being followed. I even had
to test this in a browser to make sure I'm not imagining things:

<a href="http://google.com" onclick="console.log('Testing'); return
false;">Test</a>

That certainly doesn't go anywhere. Using true instead does lead to
google.

//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi
Posted by Walter Davis (walterdavis)
on 2008-07-05 18:57
(Received via mailing list)
On Jul 4, 2008, at 5:00 PM, Jarkko Laine wrote:

>
Maybe if your log action returned true, you could do

onclick="return console.log('Testing');"

Walter
Posted by Jarkko Laine (jarkko)
on 2008-07-05 22:03
Attachment: smime.p7s (2,36 KB)
(Received via mailing list)
On 5.7.2008, at 19.56, Walter Lee Davis wrote:

>> Err, no, it doesn't. It stops the link from being followed. I even
>> had to test this in a browser to make sure I'm not imagining things:
>>
>>
>
> Maybe if your log action returned true, you could do
>
> onclick="return console.log('Testing');"

Sure, but that wasn't the point :-) The point was that true let's the
browser to follow the link, false stops it. The log msg was there just
for me to see that the js was executed.

//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi
This topic is locked and can not be replied to.