Created
January 26, 2012 22:38
-
-
Save brehaut/1685564 to your computer and use it in GitHub Desktop.
a middleware to remove utm_… params from query strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (require '[clojure.string :as str]) | |
| (use '[ring.util.response :only [redirect]]) | |
| (defn remove-utm-params) | |
| [query-string] | |
| (->> (.split query-string "&") | |
| (filter (fn [^String p] (.startsWith p "utm_"))) | |
| (str/join "&"))) | |
| (defn utm-redirect | |
| "I hate having utm crap uglying up my URLs." | |
| [app] | |
| (fn [req] | |
| (let [qs ^String (or (:query-string req) "")] | |
| (if (.contains qs "utm_") | |
| (let [qs (remove-utm-params qs)] | |
| (redirect (str (:uri req) (when (not= "" qs) (str "?" qs))))) | |
| (app req))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment