Jump to content

[SOLVED] code to count how many times a link has been clicked :: suggestions?


RyanSF07

Recommended Posts

Hi Guys,

 

I've been looking for a tutorial on how to write a script to count how many times a link has been clicked.. without having to redirect or modify the actual url. Seems like AJAX + PHP is the best way to do it.

 

Any examples you've seen that you could suggest here?

 

Thanks in advance ~

Link to comment
Share on other sites

You could use MySQL or a flatfile..

this really isn't the place to request "where can I find XYZ",

 

When you say a link as been clicked, do you mean a link TO your site or a link ON your site, also how are the links being generated,

 

also why not have a redirect or something added to the URL..

Link to comment
Share on other sites

thank you -- I realize not the place for posting this kind of help and won't keep this thread goings.

Was just wondering if you knew of a good tutorial for developing one -- a tutorial that's not from 2005 :)

 

I'd like to track clicks of links on the site to external urls.

 

I'll keep looking ~ Cheers,

Ryan

Link to comment
Share on other sites

In that case, the only way you are going to be able to do that is with javascript.  The easiest way to implement that is by putting something in the link's onclick.  Is there a reason why this isn't an option?  If it is really not an option, you could setup an event listener to capture it on page exit, but that's still a javascript thing.

Link to comment
Share on other sites

Also just thought I'd throw this out there... is there a specific way you were wanting to track this? Like, does this data need to be in your own system?  Because you can setup a free google analytics account at

 

http://www.google.com/analytics/

 

throw the global, generic tracking code on the bottom of your page(s), and it will automatically track all kinds of stuff for you, including exit link clicks (in other words, it already does what I mentioned in the previous post, as far as event listeners)

Link to comment
Share on other sites

As for a quick simple php solution you could create the links like this

 

<a href="http://www.mydomain.com/redirect.php?link=http://blar.com">http://www.blar.com</a>

<?php
//write log to text file or SQL
header(Location: $_GET['link']);
?>

 

 

 

He did say he didn't want to modify the url :\

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.