I'm working on a project that requires this module and needs tracking functionality added to it. Much to my delight, the database table already existed but wasn't being used, so the attached patch adds the logging functionality. Step two obviously is creating a page to display it. I'll be working on that over the next few days but wanted to create an issue now in case anyone else wants to contribute to this feature.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

irakli’s picture

Hey Sean,

yeah, I implemented the data-model part, but never got to creating the UI, was kindof hoping somebody like you would help with that :)

If you are interested in contributing your code, that's definitely something this module would benefit from.

thanks

seanr’s picture

I've been working with it and gotten quite a ways, but there's still plenty more to do. I'll try to get an updated patch up tonight. You can see what I've done here:

http://drupal6.webolutionary.com/shorturl

irakli’s picture

Very nice.

I am going to start shorturl_ui submodule, soon and this and other such things could roll into that.

Another thing I want to add, and will work on is a settings page. First two settings:
1. ShortURL domain (e.g. Techcrunch.com uses tcrn.ch as its short URL domain and we need to give users easy way to indicate such domain)
2. A textarea where admin can enter comma-delimited list of reserved keywords.

seanr’s picture

The reserved keyworks issue is already handled by the shorten module. The other one could go as a patch against that too, unless you're looking to give shorturl its own form independent of shorten (and maybe that is worth doing?).

irakli’s picture

Good point.

I think there is still need for settings if you just install shorturl and don't install shorten. Requiring shorten just for the sake of settings sounds like an overkill. I am also not sure how they tell shorturl to nor produce a blocked short url. Knowing shorturl code, I don't think shorten has a way of doing it. I will have to check. In any case, shorturl should work on its own too, I think.

What if we wrote the part of shorturl settings that shorten also has, into the same variables they do - that way whichever interface you change these settings from (if the two are both installed) - the settings will be synced.

I think it would be the safest integration? And would allow shorten to safely let shorturl know which pathes to not register.

seanr’s picture

That's possible. Here's a consideration, though. If you do the check in shorturl, how do you report the error back to shorten if someone submits a bad URL? I guess you'd have to do it as a form alter, at that point. I already did that with my tldrestrict module - something like that could be folded into this one (and maybe we'd make it more like the Access Rules page to accommodate both allow and deny).

irakli’s picture

Not really a problem, unless I am missing something.

Shorturl does not really allow people to suggest URLs (like bit.ly does) it just generates new tokens. If a generated token conflicts with one of the "block URL" ones, it will disregard and re-generate and return the next one. So shorten does not really need to know about it, I think. It will just always get "good" ones and should be happy :)

irakli’s picture

FileSize
42.54 KB

I was not able to find "reserved keywords" setting in the shorten module settings page (please see the attached image) even though I installed the dev release.

Am I missing something?

seanr’s picture

irakli - not seeing it now myself either. Not sure what happened to it.

CarbonPig’s picture

Hi seanr and irakli,

I've been following this module development and really like your ideas. What about using http://drupal.org/project/path_blacklist as a related module to reserve paths?

Just a thought from a novice.

-CarbonPig

seanr’s picture

FileSize
12.52 KB

Updated patch here. Now provides per user tracking and details pages for individual links (still needs work). It also adds a setting to allow duplicate links.

irakli’s picture

Thank you. Will try to review patch as soon as possible.

Many thanks.

seanr’s picture

I'll have an updated patch coming soon. I've done some more work, but there's still a bit more to go.

irakli’s picture

Thank you!

Dave the Brave’s picture

This is looking great, seanr! I've been looking for something that emulates Pretty Links plugin over at Wordpress. Makes sense that we have tracking alongside shortened URLs.

I'll be testing, so looking forward to your next patch.

Update:

On clean install, admin/reports/shorturl -

user warning: Unknown column 'title' in 'field list' query: SELECT lid, orig_url, title, description, keywords, count(aid) as clicks, created, uid FROM shorturl_link sl LEFT JOIN shorturl_access sa ON lid=url_id GROUP BY lid, orig_url ORDER BY clicks DESC LIMIT 0, 50 in /var/www/vhosts/searchenginemarketingspecialists.org/httpdocs/sites/all/modules/shorturl/shorturl.module on line 120.
seanr’s picture

Looks like the install file needs a field. I'll fix that this weekend. I should actually get most of the remaining functionality done tomorrow, so I'll have another patch either way. BTW, that domain name kinda misses the point of a URL shortener. :-P

EgonO’s picture

subscribe

gsgchoi’s picture

Title: Imeplementing tracking and metrics » query failed
Category: feature » bug
Priority: Normal » Critical

Hi, I am trying to use this module but I am getting below error message. It looks like that it fails to create shorturl_link table. Can you please let me know what's the issue here.

# user warning: query: CREATE TABLE shorturl_link ( lid serial CHECK (lid >= 0)(22), orig_url varchar(255) NOT NULL default '', created int NOT NULL default 0, remote_ip varchar(20) default '', PRIMARY KEY (lid) ) in /var/www/webserver.wordstream.com/includes/database.inc on line 517.
# warning: pg_query() [function.pg-query]: Query failed: ERROR: relation "shorturl_link" does not exist in /var/www/webserver.wordstream.com/includes/database.pgsql.inc on line 139.

gsgchoi’s picture

This is the full error message.

# warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "(" at character 58 in /var/www/webserver.wordstream.com/includes/database.pgsql.inc on line 139.
# user warning: query: CREATE TABLE shorturl_link ( lid serial CHECK (lid >= 0)(22), orig_url varchar(255) NOT NULL default '', created int NOT NULL default 0, remote_ip varchar(20) default '', PRIMARY KEY (lid) ) in /var/www/webserver.wordstream.com/includes/database.inc on line 517.
# warning: pg_query() [function.pg-query]: Query failed: ERROR: relation "shorturl_link" does not exist in /var/www/webserver.wordstream.com/includes/database.pgsql.inc on line 139.

irakli’s picture

Title: query failed » Imeplementing tracking and metrics

ggschol - please don't rename issues that are about another thing. Just open a new issue. Your query error has nothing to do with implementing metrics, which the original issue was about.

Now regarding your problem (but do open a new issue if you want to continue discussing it):

Looks like you are installing it on PostgreSQL. Module is not tested with Postgres and I would highly advise against using it with postgres. Postgres may have some benefits, but it's definitely way slower than MySQL. MySQL is much more appropriate if you need t use this module and set up a URL Shortener.

That said - if somebody has time to test it with Postgres and provide patch - i would be open to integrating it.

irakli’s picture

---

seanr’s picture

Priority: Critical » Normal
FileSize
26.62 KB

Here's a final patch. I'd like to add some caching to it, but the functionality is 100% working at this point. If we can get this patch reviewed and committed soon, that'd be helpful, as I've had several people asking about it. It's currently live at http://go.usa.gov and http://drupa.ly.

seanr’s picture

FileSize
27.88 KB

OK, final patch with all the improvements we talked about at the meetup.

seanr’s picture

Status: Needs work » Needs review
rj’s picture

The patch worked but there are a few concernd. When a link has zero clicks, instead of "details for XXX" node, it says "view all 2 links to this page", which only returns one result. See "agile approach" on this page here: http://cmd.to.

The "view own statistics" permission does not work as it should. Users without this permission can still view shorturl/user/uid and shorturl/link/lid, even though they cannot view shorturl/list/lid.

Finally, the All users menu tab is missing and I havent figured out why.

I'll hack away at this later. Thanks for the work, this is great.

rj’s picture

and another weird thing it's doing is creating 200+ links whenever I click on menu link to a node.

edit: I deleted all the created records (973) but can't get it to repeat. I'll submit as a bug next time.

edit: I'll submit this next question as a feature request, too

This may be off-topic, but have you considered implementing short URL as a content type + CCK fields? This would allow integration with views for tracking and metrics....

seanr’s picture

Regarding links with zero clicks - I cannot reproduce that. I also don't see Agile Approach anywhere on the site you linked to. I couldn't reproduce the menu issue either. I'll look into the permissions issue.

rj’s picture

The patch is no longer live on the site, I reverted back to the original module w/no stats. The site started creating exactly 200 menu links again for every non-shortened link. It's very intermittent; I would delete the excess links but they would re-appear after 24-48 hours. I can't get it to reproduce, I'll keep you posted if I do, any suggestions on testing would be appreciated. Thanks.

Matt V.’s picture

It took me a while to realize why the patch from comment #23 wasn't applying, which was due to the fact that it's based on the DRUPAL-6--1 branch, instead of 6.x-1.0-beta, which is the version mentioned here in the issue. Once I figured that out, the patch applied cleanly.

I think the patch is a worthy addition, as is. I'll report back if I notice any problems.

My main initial feedback would be to suggest using Views for generating the reports. That would provide a lot of flexibility in how the reports could be output.

youkho’s picture

subscribe

seanr’s picture

Version: 6.x-1.0-beta1 » 6.x-1.x-dev

FWIW, this patch has been running on http://go.usa.gov for a couple months now under heavy traffic with no issues (try a search for it on Twitter, BTW). I've also been running it at http://drupa.ly without issue. I haven't been able to reproduce the menu bug at all. Is there anything blocking this from being committed?

youkho’s picture

Can't patch the module so please if someone can upload a patched version.

seanburlington’s picture

It looks like the module has been developed without use of this patch - and the patch no longer applied to the latest version.

This is a real shame as the patch looks very useful - and the hosted module also has useful developments

I'm currently evaluating this for my current client - right now I just want to document how to apply it

To get a copy of the module that does accept the patch

cvs -d :pserver:anonymous@cvs.drupal.org:/cvs/drupal-contrib login
cvs -d:pserver:anonymous@cvs.drupal.org:/cvs/drupal-contrib co contributions/modules/shorturl
cd contributions/modules/shorturl/ 
cvs update -D 2009-12-01 

patch -p0 < shorturl_1.patch
youkho’s picture

thanks Sean but i couldn't get this to work :/

seanburlington’s picture

hmm.. I'm so unfamiliar with CVS these days that I'd actually imported to git in order to figure out what code I wanted and then tried to write what I thought where the CVS commands

I've redone and tested the following (NB password for CVS is "anonynous" )

cvs -d :pserver:anonymous@cvs.drupal.org:/cvs/drupal-contrib login
cvs -d:pserver:anonymous@cvs.drupal.org:/cvs/drupal-contrib co contributions/modules/shorturl
cd contributions/modules/shorturl/
cvs update -r DRUPAL-6--1  -D 2009-12-01
wget http://drupal.org/files/issues/shorturl_1.patch
patch -p0 < shorturl_1.patch

I've uploaded a copy of the patched module here (NB it doesn't contain the latest development changes - which include bugfixes)
http://www.practicalweb.co.uk/blog/10/02/22/drupal-url-shortener

seanburlington’s picture

I've re-rolled the patch and also incorporated the critical bugfix #627668: Wrong database schema (totally breaks -dev version)

This now applies against the latest development version

I'll update this page in a moment

http://www.practicalweb.co.uk/blog/10/02/22/drupal-url-shortener

and add an updated download

designerbrent’s picture

I got this to work fine with the patch in 36 and would love to see this committed.

However there is a related issue that rj raises in #25: When a link has been created but has no click throughs, the summary report says "view all 2 links to this page" but while for ones that have been clicked on, it says "details for lql". And that doesn't matter how many clicks it's had or how many links are on that page. Something just doesn't seem right about that. I looked at the code and found on line 205 it creates that $links variable but it appears to be backwards. My guess is that should be the other way. However, I couldn't exactly figure out the intent of the developer on this so I didn't try to fix it.

irakli’s picture

Status: Needs work » Needs review

Thanks to everybody who has contributed.

There're several issues with the patch:

  • It assembles insert/update SQL manually, instead of using db_write_record()
  • Permission names: 'view own statistics', 'view all statistics', 'view link details', 'export all statistics', 'export own statistics' are ambiguous. ShortURL should not be defining a permission called "view own statistic". "Own statistics" can mean too many things in Drupal. We should at least add "shorturl" to the names of each one of those.
  • All the statistics pages are rendered from PHP code without any use of templates.
  • Most of the code is crammed inside .module file and is begging for better organization.

Overall, while this is a wonderful functionality, code itself needs significant work.

I realize it's important and don't want to hold back applying changes, but It's no small patch so it can not be done unless we address major concerns listed above, first.

irakli’s picture

Status: Needs review » Needs work
seanburlington’s picture

Status: Needs review » Needs work

@designerbrent - glad you found it useful

@irakli - I'm continuing to develop a version of this module it's getting to be really quite different from the one in CVS

Many of my changes are not suitable for general purpose use - I've gone for an optimised solution with stats collated by parsing logfiles instead of using hook_init and various other tweaks that require root access - so even if I address the issue above I no longer have code that you're likely to want.

I may be able to release the final work as a seperate module - but this depends on my client.

irakli’s picture

Sean,

that's fine. Can you write your module so that it is re-using code in this module rather than forking it, though? That would be important for not allowing code duplication.

Let me know if you need this module to implement any hooks to allow you do that.

seanburlington’s picture

Hi Irakali,
I tried really hard to avoid forking - that's why I started by posting the patch to try and get metrics into the main codebase.

I think in effect the code forked when seanr's code wasn't integrated into the main branch before further development.

I've been posting issues for several weeks - but without response I just had to carry on coding - refactoring where needed.

If you want to include the patch above that would be great - and increases the chances that the further work I've done will be compatible.

But I understand if you don't want to do this.

seanburlington’s picture

oops - posted twice

irakli’s picture

I apologize for not following up to Seanr's patch in a more timely manner, but I maintain a lot of modules and it's not easy.

That said, it's perfectly fine to create a module which provides additional functionality to an existing module. Allowing such things easily is why most of us love Drupal, in the first place. So there's nothing wrong with you writing a separate module that provides statistics to shorturl and maintaining that module yourself, as far as you don't just copy/paste entire code of an existing module.

Instead, a more elegant and maintainable solution would be, if you keep writing your module, but let me know what hooks you need me to create, so I can call your code when appropriate and you can remove code already existing in this module from your module.

Makes sense?

seanburlington’s picture

Hey - no problem - we all get busy

However it is too late now for the approach you suggest.

sillygwailo’s picture

Title: Imeplementing tracking and metrics » Implementing tracking and metrics
ddorian’s picture

any update on this?

Danny Englander’s picture

subscribing

Fidelix’s picture

subscribing.

I am in need of something like this, it would be an excelent feature.

irakli’s picture

Category: bug » feature

Need to do more research, but I think this is now handled by shorten, in which case, there is little sense in re-implementing the same here.

In any case, this is not a bug so changing to "Feature Request".

AtomicStudios’s picture

FileSize
509 bytes

I found a bug in this patch where the user object wasn't being called in the get_token hook. Simple fix attached.

STINGER_LP’s picture

I'm looking forward for this feature! Any specific time frame when it will be implemented in module release?
Is it safe to use patch in comment #51 for production sites?

MrAdamJohn’s picture

What are next steps to get'r done? Willing and able to help out - contact me via d.o contact form any time.

mgifford’s picture

Ok, so if you want metrics you start with #36 & then apply #51 and voila you've got basic metrics.

So what is stopping this from getting into the module?

trick is that #patch #36 hasn't kept up with version = "6.x-1.1" & datestamp = "1277261409"

patching file shorturl.install
Hunk #1 FAILED at 12.
Hunk #2 FAILED at 64.
2 out of 2 hunks FAILED -- saving rejects to file shorturl.install.rej

utvikl’s picture

FileSize
25.91 KB

It's a pity that it needs to be this way, but here is a patch that should apply cleanly to 6--1 (patch 36+51).

Has anyone any information regarding progress with metrics and shorten? Couldn't find any traces in the code nor info on the project.

SEE: 56 for correct patch

utvikl’s picture

FileSize
25.91 KB

Was a small error there with size of orig_url. Fixed here.