Counting outgoing clicks. |
[eluser]codelearn[/eluser]
This may not be a directly CI related question, but the community here is smart so I figured this would be a good place to ask. How would I be able to count (using any method, JS/PHP/HTML, whatever) outgoing clicks on links to websites away from my own domain. For instance I have a link to http://www.codeigniter.com on my site and want to see how many people have clicked on it. Is there an elegant way to do this? Thanks!
[eluser]Michael Wales[/eluser]
I would use jQuery (or some other library) to create an AJAX request when a user clicks on an anchor element. That ajax request would call one of your controllers and pass the href of the link as a POST variable, which would then be stored in your database.
[eluser]PauloBr[/eluser]
To store in a database, I think that one of the ways is to make an address that will serve as a "bridge", where you will increment the counter and then the redirect. Like this: Code: http://www.yoursite.com/redirect/www.codeigniter.com/ On redirect controller, you make your count method. Just my opinion. ;-)
[eluser]ELRafael[/eluser]
Gosh @PauloBr! Too many work hum? Why don't you use like Michael told? In prototype you have a function to "observe" an element in HTML. Use in "a" element. If href is to another domain (if (href != $_SERVER[forget_the_key_for_domain])), put in database the link and the href. Hey, Google Analytics do this for you.
[eluser]Michael Wales[/eluser]
@PauloBr That only really works for links to domains, otherwise you have to do a lot of funky segment counting and concatenating Code: // URL is: http://www.domain.com/redirect/http://www.michaelwales.com/2007/10/erkana-codeigniter-authorization-library/
[eluser]codelearn[/eluser]
Is there a way to do it without enormous JS libraries?
[eluser]Michael Wales[/eluser]
Most of the JS libraries aren't that large, but you could always code it up yourself in JavaScript. Personally, I would use a library as it allows you to use CSS/XPath selectors, so it's not in-line JavaScript (which we call obtrusive) as well as handling all of the browser compatibility (like how IE and Firefox handle HTTP Requests differently). |
Welcome Guest, Not a member yet? Register Sign In |