Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove Google tracking parameters (UTM) from an URL?

I have a bunch of URLs which I would like to clean. They all contain UTM parameters, which are not necessary, or rather harmful in this case. Example:

http://houseofbuttons.tumblr.com/post/22326009438?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+HouseOfButtons+%28House+of+Buttons%29

All potential parameters begin with utm_. How can I remove them easily with a ruby script / structure without destroying other potentialy "good" URL parameters?

like image 410
myhd Avatar asked Oct 10 '12 14:10

myhd


1 Answers

You can apply a regex to the urls to clean them up. Something like this should do the trick:

url = 'http://houseofbuttons.tumblr.com/post/22326009438?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+HouseOfButtons+%28House+of+Buttons%29&normal_param=1'
url.gsub(/&?utm_.+?(&|$)/, '') => "http://houseofbuttons.tumblr.com/post/22326009438?normal_param=1"
like image 112
Bozhidar Batsov Avatar answered Dec 26 '22 14:12

Bozhidar Batsov