I had a problem where I needed to preserve a parameter from a referring URL, throughout the site, but only if it existed.
After a bit of trial and error, I figured out a solution which utilised mod_rewrite:
By using the QSA flag, this rewrite rule also preserves any existing arguments:
Current URL: www.example.com/my-ad-campaign?gclid=1234
Requested URL: www.example.com/articles/sunrise?type=foo
Delivered URL: www.example.com/articles/sunrise?type=foo&gclid=1234