The spam check is the simplest one- the whole thing only uses a single table. Basically, it looks like:
UPDATE exp_clicks SET link_clicks = (link_clicks + (ip <> ‘$request_ip’)) , link_m_clicks = (link_m_clicks + (ip <> ‘$request_ip’)) ,link_spam_clicks = (link_spam_clicks + (ip = ‘$request_ip’)) , ip = ‘$request_ip’ WHERE link_url=’$url’ AND article_id=’$art_id’
Which is straight off of Skeltoac original code. All it does is enter the ip of the last click to the link. Then, if the same ip clicks the link again, it counts it as spam instead of a click. Now, if a different ip is clicked and then someone comes back and clicks it again, it will increment as a legit click.
So, it’s really not a massively secure check on spam. I did have an early version that kept the ip’s in a seperate table- and pretty much saved them forever. BUT that table would get very large very quickly and it personally didn’t seem like enough of an issue to make it worth adding the overhead.
Now Skeltoac suggested:
“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.”
I’m not familiar with crc32, but the logic’s straightforward so I could do it easily enough. Think I’d do it by link id rather than url, though. For me, the same ulr COULD be counted twice if they were linked in different articles (which happens with me). I like to be able to use the article as the unit of analysis rather than the url. (Hence I added “AND article_id=’$art_id’” to the original code- the urls are not necessarily unique the way I did it- and I didn’t want them to be. Someone wants a summary measure based on url, it’s easy enough to do, but if you only collected data for the url, you couldn’t then break it out by article if the same url was associated with more than one article- which is the case on my site.)
Um…. Long way of saying, if the more secure spam check is really important to folks, chime in and I’ll add it. It’s not hard, but it does add a bit more overhead and I just didn’t think it would be enough of an issue to warrant it.
Rob, The first method is very easy to implement. Adding just one extra IP column reduces the chances of repeat clicks by MORE THAN HALF. The queries don’t take much longer and if you’re storing the IPs as 32-bit INTs instead of TEXT columns, the table size suffers very little. The PHP function to convert IPs to integers is ip2long(). Andy
Hi Rob,
I’m looking forward to getting it working, and I’m happy to be a beta tester for it.
I installed the latest version, clicked a link, and ran the report page. I got this message:
<br />
<b>Notice</b>: ob_end_clean(): failed to delete buffer. No buffer to delete. in
<b>/home/bigpi2/public_html/exp/system/core/core.template.php</b> on line
<b>1322</b><br />
How can I fix this?
Hey Vic, thanks for checking the newest version. I need to deinstall and the re-up everything that was in the latest zip to see if I can replicate the error. At the moment, I can’t.
The obflush should only occur if you access the hit template directly, rather than having it called via a link. I can’t replicate it otherwise.
As to the display…. Like I say, I’ll need to reinstall everything and replicate the problem. Are the numbers being added to the database and the tags simply not displaying them? Or is nothing getting added, so there’s nothing to display?
Also, some changes to the parameters and to variable names. For example, if you set a weblog in the parameter, only entires for which an id is entered will be shown. Also, double check you changed the variable names.
The below seems to be working fine for me:
<table border=”1”><tr> <td>entry_id</td> <td>link_title</td> <td>link_url</td> <td>link_clicks</td> <td>link_m_clicks</td> <td>link_spam_clicks</td> <td>article_title</td> <td>weblog</td> <td>comment_auto_path</td> <td>date</td> <td>permalink</td> <td>comment_entry_id_auto_path</td> <td>comment_url_title_auto_path</td> <td>percent</td> </tr>
{exp:clickport:clickport limit="50" sort="desc" orderby="link_clicks" weblog="all" percent="yes"} {exp:clickport:linkconvert entry_id="{entry_id}”} <tr> <td>{if entry_id == "0"}No article{/if}{if entry_id != "0"}{entry_id}{/if}</td> <td>{if link_title}{link_title}{/if}{if link_title == ""}No title{/if}</td> <td><a href=”{link_url}”>link</a></td> <td>{link_clicks}</td> <td>{link_m_clicks}</td> <td>{link_spam_clicks}</td> <td>{article_title}</td> <td>{weblog}</td> <td>{comment_auto_path}</td> <td>{date format="%Y %m %d %a"}</td> <td> {permalink="weblog/blah"}</td> <td>{comment_entry_id_auto_path}</td> <td>{comment_url_title_auto_path}</td> <td>{percent}</td> </tr> {/exp:clickport:linkconvert} {/exp:clickport:clickport} </table>
But I’ll take a look at it with fresh eyes tomorrow. Maybe I uploaded an old file in the zip by accident!
It may just be a miscommunication about how to install it. I had he previous version working, so the javascript must be getting called correctly. Here’s what I have in my Click_Report template:
<table>
{exp:clickport:clickport limit="50" sort="desc" orderby="link_clicks" weblog="all" percent="yes"}
{exp:clickport:linkconvert entry_id="{entry_id}"}
<tr>
<td>{if entry_id == "0"}No article{/if}{if entry_id != "0"}{entry_id}{/if}</td>
<td>{if link_title}{link_title}{/if}{if link_title == ""}No title{/if}</td>
<td><a href="{link_url}">link</a></td>
<td>{link_clicks}</td>
<td>{link_m_clicks}</td>
<td>{link_spam_clicks}</td>
<td>{article_title}</td>
<td>{weblog}</td>
<td>{comment_auto_path}</td>
<td>{date format="%Y %m %d %a"}</td>
<td>{comment_entry_id_auto_path}</td>
<td>{comment_url_title_auto_path}</td>
<td>{percent}</td>
</tr>
{/exp:clickport:linkconvert}
{/exp:clickport:clickport}
</table>
Currently I have tried calling the template directly via a URL; it results in an sql error. I tried calling the template via a link on my home page, and also got the sql error.
Do I have the correct code in the Click_Report template? Is there a different way I should be installing it?
It’s working! It’s really great. Way to go. Rob!
I notice it even captures clicks to links that aren’t inside of {exp:weblog:entries} tag pairs, for example, my blogroll, which is great.
I think if you access the click report before anybody has actually clicked a link, you get an sql error.
Here’s my Click Report template in case others may find it useful:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel='stylesheet' type='text/css' media='all' href='{stylesheet=weblog/weblog_css}' />
<style type='text/css' media='screen'>@import "{stylesheet=weblog/weblog_css}"
;</style>
<title>Click Report</title>
</head>
<body>
<table border="1">
<tr>
<td><center><b>Entry ID</center></b></td>
<td><center><b>Clicks</center></b></td>
<td><center><b>Article Title</center></b></td>
<td><center><b>Link </center></b></td>
<td><center><b>Date</center></b></td>
<td><center><b>%</center></b></td>
</tr>
{exp:clickport:clickport limit="50" sort="desc" orderby="link_clicks" weblog="all" percent="yes"}
{exp:clickport:linkconvert entry_id="{entry_id}"}
<tr>
<td>{if entry_id == "0"}<center>--</center>{/if}{if entry_id != "0"}{entry_id}
{/if}</td>
<td>{link_clicks}</td>
<td>{if entry_id == "0"}<center>--</center>{/if}{if entry_id != "0"}
<a href="{comment_entry_id_auto_path}">{article_title}</a>{/if}</td>
<td><a href="{link_url}">{link_url}</a></td>
<td>{date format="%Y %m %d %a"}</td>
<td>{percent}</td>
</tr>
{/exp:clickport:linkconvert}
{/exp:clickport:clickport}
</table>
</body>
</html>
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.