We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Click Tracker

Development and Programming

Vik's avatar
Vik
209 posts
20 years ago
Vik's avatar Vik

It would be cool to have a plugin that would keep track of how many times each of your links has been clicked.

I’ve been looking for comparable things at HotScripts. So far all the things I’ve found there require you to enter the links you want to track in a control panel. Since as bloggers we can add many new links every day, it’s inconvenient to have to enter each new link manually in a control panel. The easiest thing would be a click-tracker that can scan my pages and figure out what links are on them. (There’s a service that does this, http://www.mybloglog.com/, and they’re quite good, but I have the feeling they might be missing a lot of clicks, because like all off-site hit counters, their pageview count is so off.)

One approach might be to use the approach of one of the current plugins that modifies links, (e.g. “NoFollow”) and modify the link so that it calls a script, which logs the click and then sends the user on to that link. I guess the drawback of this is that if people copy and paste your links they won’t get what they’re expecting. Is there a way around this drawback?

How about a module (should I copy this to the modules forum?) that has a button that, when clicked, scans your page for links and enters them in the control panel of a control-panel-driven click tracker? It could work with free click tracker code from HotScripts.

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
20 years ago
Lisa Wess's avatar Lisa Wess

You should not crosspost this anywhere, that includes copying it to another forum.

I think that this would, indeed, be more appropriate for a moduule - however if it’s going to do any scanning it may as well also increment each link’s counter when it’s clicked, rathern than utilizing another script. It’d probably be a failry easy plugin or module, to write however it’s done.

       
Chris Curtis's avatar
Chris Curtis
17 posts
20 years ago
Chris Curtis's avatar Chris Curtis

> One approach might be to use the approach of one of the current plugins that modifies links, (e.g. “NoFollow”) and modify the link so that it calls a script

I think that would probably be the way to go. In fact, I know one of the users around here has implemented something like that already, but darned if I can remember who…

The idea is pretty simple:

  1. Make your links point to something like http://www.example.com/track.php?url=http://www.google.com/.

  2. In the “track.php” script it looks at the incoming URL and takes the value sent in the “url=” variable. It logs that information into some database table for the tracking and then just redirects/forwards the user on to the intended destination.

  3. You’d also, of course, want something that could look in the database at the recorded information and display it to use as useful data.

I don’t think this would be something that “scanned your page and then altered links” actively. Instead, whenever you had a link you wanted tracked then you would simply use the above format. You could even build the format into links within your Templates. You could, I suppose, have a supplemental Plugin like the “NoFollow” one that would alter the links within your entry content.

       
Vik's avatar
Vik
209 posts
20 years ago
Vik's avatar Vik

The way you have designed it seems pretty easy to implement. Would it be a concern that if readers copy and paste the links, they won’t get quite what they are expecting?

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
20 years ago
Robin Sowell's avatar Robin Sowell

Yea, it’s pretty easy. I do a variant on this to count particular links associated with an id. For example, on my links page, I count and display click-thrus. Basically, I just made a custom field for ‘hits’ and I send any links through a script that ads a ‘click’ to that field each time the link is used.

Basic script is:

$id = $_GET[‘id’]; $url = $_GET[‘tb_url’]; global $DB;

$sql = “SELECT entry_id, field_id_75, field_id_76 FROM exp_weblog_data WHERE entry_id=’$id’ LIMIT 0,1”; $query = $DB->query($sql);

    foreach($query->result as $row) {
     $id = $row['entry_id'];
            $count = $row['field_id_75'];
            $mcount = $row['field_id_76'];
            $count2 = $count + 1;
            $mcount2 = $mcount + 1;
            $update = "UPDATE exp_weblog_data SET field_id_75='$count2', field_id_76='$mcount2' WHERE entry_id='$id' ";
            $query = $DB->query($update);

    }

?

</head> <body bgcolor=”#FFFFFF”> <META HTTP-EQUIV=”REFRESH” CONTENT=”0; URL=?php echo $url; ?”>
</body> </html>

?php } ?

Um- fix the php declarations, obviously.

But yea- it does jam up the link if you try to copy/paste it. Also, if you wanted to count a bunch of links inside a single entry, you’d probably want to do it based on url rather than entry_id- which means putting it in its own table. I used to do that, but I prefer my current method for the purposes I’m using it for.

The neatest way I’ve seen to do this is the new wordpress plugin Count My Clicks. It uses javascript (and XMLHTTPRequest, I think) to automatically redirect links through the ‘counting’ script- without altering the url. Neat idea. I think there are plans to expand it to count internal clicks as well (it already can, but is set not to by default- for good reason).

Um- anyway, I’m keeping an eye on it- thought of playing around with it for EE, but for my purposes, my approach works well. Also, I know someone’s already well into a ‘link’ module for EE, so no point in duplicating effort. This sort of thing should probably be integrated into that.

Anyway- javascript approach is nifty because it’s transparent, both to the admin and the end user. Of course, I assume it won’t track clicks for those with javascript disabled. On the other hand, links should look and work fine regardless.

Eh- rambling. I’d wait for I think it’s Yoshi’s module to come out- but if you want to implement it yourself, it wouldn’t be hard.

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
20 years ago
Robin Sowell's avatar Robin Sowell

Oh- and if you need code that will automatically add a new record without you having to add the link by hand, it looks more like:

global $DB;

$sql = “SELECT id, count, mcount FROM hits WHERE id=’$id’”; $query = $DB->query($sql);

    if ($query->num_rows == 0) {

$sql = “INSERT INTO hits (id,count,mcount) VALUES (‘$id’,’1’,’1’)”; $query = $DB->query($sql); } else { foreach($query->result as $row) { $id = $row[‘id’]; $count = $row[‘count’]; $mcount = $row[‘mcount’]; $count2 = $count + 1; $mcount2 = $mcount + 1; $update = “UPDATE hits SET count=’$count2’, mcount=’$mcount2’ WHERE id=’$id’ “; $query = $DB->query($update);

    }

}

Since my ‘clicks’ are inherently tied to posts, by definition a record will exist for a link, thus the way I do it, there’s no need to worry with that possibility. But the above will work, it’s what I used to use before I went to putting the hit count in a custom field.

       
Vik's avatar
Vik
209 posts
20 years ago
Vik's avatar Vik

Thanks for the info, Rob1. I’ll take a look at “Count My Clicks” too. Is it likely to be difficult to port a Wordpress plugin like this to EE?

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
20 years ago
Robin Sowell's avatar Robin Sowell

Depends on the plugin, but from my brief look at that one, I think it would be pretty easy to do. Since I want to tie things to the entry_id, for me it would require more changes. But to simply port it, I think it would be easy.

       
Vik's avatar
Vik
209 posts
20 years ago
Vik's avatar Vik

Cool. Are there any Plugin Wizards here who would like to port “Count My Clicks” to EE?

       
OfficeGeek's avatar
OfficeGeek
1 posts
about 20 years ago
OfficeGeek's avatar OfficeGeek

If anyone is available to port Count My Clicks, I would be very interested. Please contact me!

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
about 20 years ago
Lisa Wess's avatar Lisa Wess

King of Fools recently mentioned that he’s available for projects, you could contact him. He posted his credentials on the wiki. =)

       
EE lover's avatar
EE lover
50 posts
about 20 years ago
EE lover's avatar EE lover

I’ve got all most every thing I wanted from EE and a click counter (especially for external links) is my next EE wish!

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
about 20 years ago
Robin Sowell's avatar Robin Sowell

Well, it was pretty easy to mock up a beta, but I need some folks to go click around a bit so I can work out any kinks. It’s got a spam check that prevents me from racking up the legit clicks.

Anyway- anyone wanders by interested in it, keep on wandering to the test page - just click on the first couple of links so I can test things out with different IPs, as I’m not sure how things are incrementing for legit clicks.

The very super basic tag is on http://media-cow.net/weblog/test2 - all it currently does is show number of legit clicks, title as defined in the link title, and the link url. I’m also passing along the article id, so urls can be tied to their specific articles (and articles can be tied to multiple urls).

Seems to work in IE and FF and I’ll tweak things out a bit before putting up a true beta version. Anyone got requests for things they want, now’s the time to ask. Crossing fingers that things are incrementing properly….

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
about 20 years ago
Lisa Wess's avatar Lisa Wess

the test page is blank for me. I’d want some way of nesting the linklist in this, and viewing the hits on the control panel, NOT publicly. Or does it just track any link in the site?

       
EE lover's avatar
EE lover
50 posts
about 20 years ago
EE lover's avatar EE lover

blank for me too!

       
1 2 3 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.