Skip to content

Instantly share code, notes, and snippets.

@brehaut
Created January 26, 2012 22:38
Show Gist options
  • Select an option

  • Save brehaut/1685564 to your computer and use it in GitHub Desktop.

Select an option

Save brehaut/1685564 to your computer and use it in GitHub Desktop.
a middleware to remove utm_… params from query strings
(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