Hm- massively odd. It was blank for me when I checked from a non-logged in browser- and I can’t spot why.
But http://media-cow.net/weblog/newtest/ worked for me when not logged in, so give it a try.
Basically, this is a REALLY simple mod- all the work goes on in the javascript from the WP plugin. What it does is invisibly alter the url of all off site url’s on any page with the javascript- you can see the javascript- a bit in the head and another bit at the bottom.
Anyway, basically it ‘posts’ the url to the counting script, and I added in a bit so that variables for the link title and the ‘rev’ (where I stuff the article id) are also passed along to the counting script. It dumps all of that plus the last ip to click the link on to the database.
From there, you can pretty much do whatever you want with it. So far, I’ve just worked up a really simple little tag that lets you display that data- sort it, order it, limit it- the usual. Looks like:
{exp:clickport limit="10" orderby="clicks"}
{clicks} legit, {click_spam} spam, <a href=”{url}”>{title}</a> = from article id={article_id}<br> {/exp:clickport}
Might want to add some stuff for percent and percentil numbers- then you could add bar grafts or whatever. Maybe do some tags for average clicks. For folks with cron, it’s easy enough to keep monthly data as well- with a little alteration of the script.
And yea- it should really be rolled into Yoshi’s mod- it makes sense. I personally will roll it into my links, which I’ve just been using a weblog for. Anyway, that will take some modification, but none of it’s hard.
So really - this just gets the data into the database and I’ll add whatever kinds of tags and sorting ability folks can think of. To fully integrate with either Yoshi’s mod or the regular weblog mod is easy, but will require some hacking and some alterations to the database on the part of those mods. Basically, I’ve been sticking my clicks into a custom weblog field and I’ll continue to do so, as it’s the easiest way to display as a part of the article. Of course, since multiple outside links can be in a given article- THAT would get trickier to integrate!
But basically- it’s flexible. It just gets the data in there and folks can do whatever they want with it from there.
The js just modifies the link- so where it looks like:
http://some_off_site_link.com/
The js is transforming it into a query string a la:
http://mysite.com/php_clicktracker?url=http://some_off_site_link.com/|nothervariable|another variable
So basically, you then need the tracker script, and you need a EE mod to create the tables the tracker script inserts the variables into, and then might as well add some basic tags so folks can pull the data back out without using queries.
So it’s simple, but you still have to put stuff into the database- hence it’s a module.
And it looks like this script is inserting a row for each ip/url combo, which is a bit excessive imo, so I’m going to go back to tweaking it a bit. The main decision it whether to keep it to one table and just record the last ip to click, or break it into two tables and keep all the ips.
…. I’ll dink with it some more!
Yea, it could use some testing out. Here’s a zip for anyone fearless enough to play with it in the current state. I rather stink at directions, but hopefully it’s clear enough to get it working.
It’s really very simple, and it doesn’t look like the js is working for me when I tested it with Opera. Fresh eyes testing it out wouldn’t be a bad thing.
I tried the beta out, and it’s working on many browsers. Cool! Of the ones I could test, here are the ones it’s working on so far:
MAC Working on Safari and Firefox. Not yet working on IE5 and Opera.
WINDOWS Working on IE6. Not yet working on Netscape 7.1.
So far the name of the link is just showing up as “unknown,” for example:
unknown - 2 legit clicks, 2 ligit monthly clicks, 0 total spam clicks, from article id=0 unknown - 1 legit clicks, 1 ligit monthly clicks, 0 total spam clicks, from article id=0 unknown - 1 legit clicks, 1 ligit monthly clicks, 1 total spam clicks, from article id=0
However, if I point at the word, “unknown”, I can see it links to the actual link that was clicked.
Please keep up the good work. It’s already starting to show me actual links clicked by visitors. This will be great!
Hi folks, Rob1 sent me. I’m the [proud] author of Count My Clicks. It’s been so long since I looked at that code, I forgot how I did it! Anyway, I’m glad to see it’s coming in handy.
The only original lines of code here are the three-event click sensor code and the database update query, adding the numeric value of booleans to the click/spam counts, and some WordPress-specific stuff about dual-purpose plugin files and the plugin dependency model. Beyond that, I did a lot of borrowing and modification.
I had planned a few changes to CMC that I never got around to because I dove into Blogs Of The Day (BOTD) and I haven’t yet surfaced. One important mod would be to have the JS remove the events from the clicked anchor after sending the HTTP Request. This would cut down on repeat clicks, saving some bandwidth and a lot of PHP overhead on the server.
As for cross-browser support, the main difficulty I had was with the XMLHTTPRequest. When I got it working for WinIE and WinFF, I stopped developing that portion of the code because that accounted for 95% of most folks’ traffic.
Another possibility is that the browser isn’t letting the script update the HREF properties. I never found a way to browse the DOM post-JS, even in FF’s DOM browser, so I added alert(’whatever’) commands to the JS to see where it was breaking in development. You might try that.
As a side note, I never intended to count invalid clicks. The ‘spam’ column was born out of a need to reduce the number of queries. I might have done it differently with what I now know about MySQL, but it works out nicely for anyone who wants to count repeated clicks.
I can also tell you that I experimented with stricter click/spam counts and came up with two models: first, you can store many IPs (IP0, IP1, IP2, IP3 etc.) and test against each one (hits=hits+((IP0<>$ip) AND (IP1<>$ip) AND (IP2<>$ip) AND (IP3<>$ip)), spam=spam+((IP0=$ip) OR (IP1=$ip) OR (IP2=$ip) OR (IP3=$ip))) then shift the values (IP3=IP2, IP2=IP1, IP1=IP0, IP0=$ip) all in the same UPDATE query. I tried it with up to 16 IPs and it worked fine.
This first model should be used on high-traffic sites because the click sensor will send HTTP notification every time you right-click the link, regardless of whether you click anything in the context menu.
Second, you can store each unique click in a table. This gets unweildy with lots of traffic but it ensures that no URL is counted twice for the same IP. The trick to doing this efficiently is to hash the URL and IP together with CRC32 ($HURLIP=crc32($URL.$IP);), storing that value in a column HURLIP INT NOT NULL UNIQUE. The UPDATEs are superfast and the table is quite compact if it’s just HURLIP and HURL ($HURL=crc32($URL);) and keep the URLs in a separate table. JOINs using HURL are fast because it’s an INT. This method does not track invalid clicks.
Do you think this post should be any longer? Geez. You can email me with questions: skeltoac at nobody’s favorite free email domain, hotmail.com.
Thanks for coming over, Skeltoac! And I’ve been looking at BOTD, which is a very nifty idea as well!
The js is simply over my head, and as it works in the important browsers and degrades gracefully in the others, I’m not liable to worry with it over much. I may try to work in an option for folks who are anal so they can directly calling the counting script. But yea- that’s just ugly (it’s what I’d been doing).
I’ll upload a new zip tonight that fixes the ‘unknown’ issue, and I’m working up a plugin to automatically add the entry_id to the link.
Basically, the script works based on this logic:
a href=”http://mysite.com” title=”My Site” rev=”123”
Three variables are being passed- url, title and rev (aka the article id)- if title or article id are missing, it should insert a blank. Right now, it’s inserting ‘unkown’ and ‘0’, which is why the conditionals aren’t working as they should. Easy fix.
Um- anyway, point being I want a plugin that will automatically add the correct entry id, because there’s no way for folks to do it to in-text links and for my own puproses, clicks really need to be associated with articles and not just urls. So once I’ve got that squared, I’ll upload the package and do another test run.
OK, got the new beta up here. IF you’ve got the earlier beta installed, you’ll need to uninstall via the CP, replace all the files (except the language file and the js), then reinstall- there were some database changes.
Added some stats, new variables and parameters, fixed the conditionals, and added a function to automatically include the entry_id for links inside weblog tags. It’s a simple string replace- use it like:
{exp:weblog:entries weblog="links" limit="50"} {exp:clickport:linkconvert entry_id="{entry_id}”} {title}{body}{yadayada} {/exp:clickport:linkconvert} {/exp:weblog:entries}
Being able to tie urls to entry_id’s allows you to link to the articles associated with the id’s via permalinks, etc. (the code for which I just pulled from the weblog mod).
The code needs a LOT of cleaning up, and I think I’d like to add some other options to the linkconvert function (a la the click counter plugin for WP).
But, the database structure is pretty solid. Still a beta version though, and with more options, there are more sources for error. Spot anything goofy, let me know. Once it’s cleaned up enough to not be pathetic, I’ll submit it to EE and it will no doubt need more cleaning up to make the grade.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.