Simple Machines Community Forum

General Community => Scripting Help => Topic started by: OzzyMozzy on April 27, 2012, 09:27:24 PM

Title: Click counter on HTML Image?
Post by: OzzyMozzy on April 27, 2012, 09:27:24 PM
Hi, I'm using SMF 2.0.2 with SimplePortal. I have a left block Custom HTML that is an image members can click on to take them to a web page.

I want to be able to count how often the image is clicked on, can this be done? I would also like it if only i could see the count.
Title: Re: Click counter on HTML Image?
Post by: Matthew K. on April 27, 2012, 09:30:28 PM
It'd have to be a custom PHP block, and you'd have to integrate it with $modSettings, or a database table of some sort.
Title: Re: Click counter on HTML Image?
Post by: ApplianceJunk on April 27, 2012, 09:30:52 PM
One way would be to use https://bitly.com/.

Create a shorten link with https://bitly.com/ and use it in place of the regular link.
https://bitly.com/ will track the stats for you.
Title: Re: Click counter on HTML Image?
Post by: TheListener on April 27, 2012, 09:31:00 PM
Hi OzzyMozzy

As this is a portal themed question you should ask in the mods support topic or on www.simpleportal.net

I myself am not sure if or how this could be done however I know someone at the above link will be in a better position to help.
Title: Re: Click counter on HTML Image?
Post by: ApplianceJunk on April 27, 2012, 09:34:50 PM
I see no reason why https://bitly.com/ won't work for them.
Title: Re: Click counter on HTML Image?
Post by: OzzyMozzy on April 27, 2012, 09:53:40 PM
Thanks for that link, i signed up to have a look. It talks about shortening the link but how does it work to track the clicks on my image?
Title: Re: Click counter on HTML Image?
Post by: ApplianceJunk on April 27, 2012, 10:03:54 PM
A image link would look something like this...

<a href="http://website.com"><img src="http://YourImageURL.com"></a>

You would use https://bitly.com/ to create a new shorten link for http://YourImageURL.com

Then replace http://YourImageURL.com with the new shorten link bitly.com gives you.

Go back to bitly.com to view the clicks and other stats on the new shorten link you are using.
Title: Re: Click counter on HTML Image?
Post by: OzzyMozzy on April 27, 2012, 10:09:41 PM
Ah i get it now and just tried it out, thanks heaps for that.

Will it count it if the same link was somewhere else? or does it only count it from my web site?
Title: Re: Click counter on HTML Image?
Post by: ApplianceJunk on April 27, 2012, 10:18:55 PM
Quote from: OzzyMozzy on April 27, 2012, 10:09:41 PM
Ah i get it now and just tried it out, thanks heaps for that.

Will it count it if the same link was somewhere else? or does it only count it from my web site?

I believe it will count the shorten link it creates from anyplace it's clicked on.

I use them in emails and they get tracked.
Title: Re: Click counter on HTML Image?
Post by: OzzyMozzy on April 27, 2012, 10:28:45 PM
So it will only click the shorten link and not count the long link that will be on other web sites?
Title: Re: Click counter on HTML Image?
Post by: ApplianceJunk on April 27, 2012, 10:34:49 PM
It only tracks the new shorten link you created.
Title: Re: Click counter on HTML Image?
Post by: OzzyMozzy on April 27, 2012, 10:42:12 PM
Sweet, thought so i just wanted to confirm, im new to all this. Thanks heaps again it's working and it's perfect...
Title: Re: Click counter on HTML Image?
Post by: ApplianceJunk on April 27, 2012, 10:43:21 PM
I'm no expert with it, so this may help answer a lot of your questions better then I can.

https://bitly.com/pages/help
Title: Re: Click counter on HTML Image?
Post by: ApplianceJunk on April 27, 2012, 10:44:20 PM
Quote from: OzzyMozzy on April 27, 2012, 10:42:12 PM
Sweet, thought so i just wanted to confirm, im new to all this. Thanks heaps again it's working and it's perfect...

Glad I could help. :)
Title: Re: Click counter on HTML Image?
Post by: OzzyMozzy on May 01, 2012, 08:00:45 AM
I have noticed the click count on bitly is way over the top and found that the links are getting hit by bots. I was watching them and each one of the 4 i have each got a click counted all at the same time.

So yes this bitly works but it gives a false reading in my case as i don't want to count bots just real clicks..
Title: Re: Click counter on HTML Image?
Post by: Colin on May 01, 2012, 11:26:13 PM
Yes, that is going to require some PHP if you want to filter out bots and some you won't be able to.
Title: Re: Click counter on HTML Image?
Post by: OzzyMozzy on May 01, 2012, 11:51:13 PM
I have now tried a couple that replace my image link with their own URL to count which is fine but they don't filter bots.

Isn't there any programs out there that is simple and easy to use that will do the job?
Title: Re: Click counter on HTML Image?
Post by: MrPhil on May 02, 2012, 11:03:21 AM
If you want guests' clicks to count too, and not just logged-in members, you're going to have to look at the user agent ($_SERVER['HTTP_USER_AGENT']) and weed out anything that sounds like a bot or not a known browser. This could be after the click, or simply displaying an image instead of a link. Keep in mind that it's not foolproof, as some bots pretend to be well-known browsers (to prevent just this sort of action). If you want to ignore guests (as well as bots), you could add code to only display the link for members.