Plugin Request: Capture and store url query items added to a shortlink #2116

stevenmcastano opened this Issue Jun 30, 2016 · 4 comments


None yet

2 participants


Technical details

  • YOURLS version: 1.7.1
  • PHP version: 5.5.9
  • OS: Ubuntu 14.04

Feature Request:

I wasn't sure where else to post this, I might try posting it with the plugins list page as well, but basically here's what I'm looking for:

When I use social marketing tools l like Buffer, Hootsuite, or even email marketing tools like or MailChimp, they add marketing campaign info to the end of the URL and it would be great to be able to capture and count that. For instance:

I have a short link to an event website info page that I'm organizing that is something like https:\\\eventinfo and when I use a tool like the ones mentioned above that add things to the url link to keep track of the marketing campaign and where the link was posted, so the links end up getting posted like these:


This gives me the ability to tie together the exact places where links were originally posted, from what marketing tool, and were part of which "campaign", and for I frequently include the date and time in the compaign name like inviteround001_2016_06_30_1pm. It would be VERY helpfully to me, and I think to a lot of other people as well if YOURLS had a way to capture each query item added to the end of a shortlink and store it in a DB table maybe in rows or something that have row values of "shortlink", "query_parameter", "value", and "count", this way each and every one of those that comes in could be kept track of individually so I could always see how many people a particular campaign has reached, or what source is really leading in reachability. Especially because a lot of the times the referrer/traffic source info comes in as multiple locations even when they're from the same place, even worse with twitter where the shorten everything again with their service and you get things like this: 190 (details)
  * 131
  * 49
  * 4
  * 3
  * 1 137 (details)
  * 21
  * 103
  * 1
  * 9 (details)
  * 7
  * 2

What do you guys think? Anyone up for the challenge? I'd write this myself if I was better in PHP, but to be honest I'm a terrible coder and the only thing I can really write anything in is python.


This is turning out to be a little LESS challenging than I though... I don't know much about PHP, so I'm learning as I got, but I'm writing the plugin myself. Right now it's in my privately hosted gitlab repo, but as soon as I get something mildly functional, I'll put it up here on github and if anyone would like to check my code and make it better where possible, and I'm sure it will be possible, that would be awesome!

So for I have an ACTION hook on "pre_redirect" that's grabbing the REQUEST_URI, splitting it up into pieces to I can see the shortcode and each query parameter and it's value, as well as check to see if there are any query items at all, and if not, just stop processing through the plugin completely.

Next thing I need to do is figure out how to get it to store a count in the DB, check to see if theres a row for that shortcode and that query parameter, if so, increase the count field by 1, if not insert that row.

Then on the plugin management page, but able to select every unique shortcode in the database and show under each one, all the query parameters sent through and their counts. I'm not exactly sure how to do all of that yet.... but I'm learning!


How would I add a plugin specific table or tables to the MySQL DB being used by YOURLS?

ozh commented Jul 5, 2016

This plugin might be a good example to look into:

Generally speaking, lots of plugins can give you hints about how to do this or that


Yeah, I have been grabbing code from other plugins while creating my own as well... this one does have some great examples in it too, thanks for the heads up! I had found another way to do it, but this one is much better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment