Forum Moderators: open

Message Too Old, No Replies

Counting clicks on a link to an external site.

Is this a good way to do it?

         

Purple Martin

10:55 pm on Mar 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does this sound like a good way to count the number of clicks on a link that goes to another site?

1. Make the link go to a blank page in my domain.
2. My blank page then auto-redirects to the page on the other site.
3. Get the number of hits on the blank page from the logs.

eman

12:14 am on Mar 17, 2004 (gmt 0)

10+ Year Member



That's exactly what I do (and is visible) on the links page of my site, www.lookitsmysite.com . BTW, my site languages are PHP and mySQL. I pass the linkID and destination URL to the redirect page, increment whatever is necessary, and then redirect to the new site. THE KEY IS... you have to use <?php header("Location: $someUrl");?> as the first line of your redirect page. Then it's completely blind to the user, they don't see your blank page, just the destination. Once you put in the header command, you can run all the PHP and mySQL commands you want, your server will execute them, and once it's done, it will send the user to the new page.

Take a look at my site, roll over the links, I don't use blind links so you will be able to see the entire URL and arguments that are passed to the redirect page. Click one of the links, and then go back and refresh, you will see that the number of clicks has been auto-updated. If you need any more help, feel free to ask.

-EMAN

Purple Martin

12:26 am on Mar 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, that's great.

Now for the bad news: server-side scripting is not an option (because it's a government site and the host is security-insane). So would it be OK to use a meta-refresh? I know this means it's not quite blind to the user, but if that's the price I have to pay then so be it.

eman

12:49 am on Mar 17, 2004 (gmt 0)

10+ Year Member



yeah, if you can't go server side, then that might be your only option.

Birdman

1:04 am on Mar 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you don't need EXACT counts, you could use a javascript solution similar to the Adsense tracking script. Your solution will work fine too.

function click(site){

img = new Image();

img.src = 'ht*p://www.another_site_with_serverside.com/tracker.php?site=' + escape(site) + '&referrer=' + escape(document.location);

}

<a href="some_url" onclick="click(this.href)">Link</a>

ps. Not sure if this.href works, but I believe it does.