External Link Click Coutner
Moderator: General Moderators
External Link Click Coutner
Hi all.
Just set up a website and need to create an external click counter to find out who is clicking on my advertisers and more importantly how often.
I was told I will need a PHP script for this. I have a VERY BASIC knowledge of HTML and know nothing about PHP.
My website is http://www.iwantafreehouse.com
Can someone give me an example of a basic webpage with a link and this type of counter and tell me how I actually get the results??
Thanks all!!
Shane
Just set up a website and need to create an external click counter to find out who is clicking on my advertisers and more importantly how often.
I was told I will need a PHP script for this. I have a VERY BASIC knowledge of HTML and know nothing about PHP.
My website is http://www.iwantafreehouse.com
Can someone give me an example of a basic webpage with a link and this type of counter and tell me how I actually get the results??
Thanks all!!
Shane
Hey Shane,
There are some PHP based click trackers here:
http://www.hotscripts.com/PHP/Scripts_and_Programs/Click_Tracking/index.html
If you have a look through this list there are some that you could use.
I hope that helps.
There are some PHP based click trackers here:
http://www.hotscripts.com/PHP/Scripts_and_Programs/Click_Tracking/index.html
If you have a look through this list there are some that you could use.
I hope that helps.
Ok! A php click-thru is still needed to take records but for SEO reasons the remote URL should be used for the links in the document. Two ways to rewrite the links... one is to rewrite all external links:Or you could just rewrite the URLs that are ina particular element:Just put that in an external .js file. The php script might look something like this:
feyd | to avoid some confusion, I've adjusted a few of the blocks from
Code: Select all
function parse_links()
{
new_url = 'http://www.mydomain.com/click-thru.php?url='
for(i = 0; i < document.links.length; i++)
{
if(document.links[i].hostname != document.location.hostname)
{
document.links[i].href = new_url + document.links[i].href
}
}
}
onload = parse_linksCode: Select all
function parse_links(element)
{
new_url = '/clickThru.php?url='
LINKS = document.getElementById(element).getElementsByTagName('a')
for(i = 0; i < LINKS.length; i++)
{
if(LINKS[i].hostname != document.location.hostname)
{
LINKS[i].href = new_url + LINKS[i].href
}
}
}
onload = function(){ parse_links('rightcolumn') } Code: Select all
if((!empty($_GET['url'])) and (preg_match('/^(?:f|ht)tps?:\/\/[^\/]+\.[^\/]+(\/[^\'"]*|)$/i', $_GET['url'])))
{
connect();
$query = "INSERT INTO `clickthrus` (`url`, `clicks`) VALUES ('".
clean($url = preg_replace('/^http:\/\/(www\.)?([^\/]+).*$/i', '\2', $_GET['url'])).
"', 1)";
if(!mysql_query($query))
{
if(1062 === mysql_errno()) // this script was used on MySQL 3.23 so this replaces ON DUPLICATE KEY UPDATE
{
$query = "UPDATE `clickthrus` SET `clicks` = (`clicks` + 1) WHERE `url` = '".clean($url)."'";
mysql_query($query);
}
}
header('Location: '.$_GET['url']);
}Code: Select all
to [sytnax="javascript"].[/color]-
jabbaonthedais
- Forum Contributor
- Posts: 127
- Joined: Wed Aug 18, 2004 12:08 pm
So you're saying linking to:bokehman wrote:Using php as a click counter is a bad thing because it means no real link exists in the document (bad for SEO). A better way would be to use Javascript to rewrite the links.
http://www.mydomain.com/click-thru.php? ... oogle.com/
is better than just:
http://www.mydomain.com/click-thru.php?id=12
I was under the impression search engines didn't like either. I'm very interested though, because I would like to use something to track outgoing hits myself. Couldn't you set up something server-side that tracked outgoing hits but displayed actual urls (http://www.google.com)? I have seen it done, but not sure how complicated that would be to set up.
No he is saying to link to the site as normal. For examplejabbaonthedais wrote:So you're saying linking to:bokehman wrote:Using php as a click counter is a bad thing because it means no real link exists in the document (bad for SEO). A better way would be to use Javascript to rewrite the links.
http://www.mydomain.com/click-thru.php? ... oogle.com/
is better than just:
http://www.mydomain.com/click-thru.php?id=12
<a href="http://example.com">sponsor</a>
Then include some javascript that modifies all the off site urls on the page like so the above link would become.
<a href="http://www.mydomain.com/click-thru.php? ... sponsor</a>
Search engine spiders don't evaluate javascript so the links appear normal to them. Most web browsers do evaluate javascript so the links will be tracked when clicked.
-
jabbaonthedais
- Forum Contributor
- Posts: 127
- Joined: Wed Aug 18, 2004 12:08 pm