UTM variables in rails

1.3k views Asked by At

I can get referer by request.referer, my question is how can i get utm variables of the referer?

I have tried params[:utm_source] but it didn't work, request.referer gives me

http://localhost:3001/show/?UTM_Source=newsletter&UTM_Medium=email&UTM_Campaign=unsubscribed

1

There are 1 answers

0
ediblecode On

I mean really you should look at why you are unable to fetch this value using params[:utm_source] because it sounds like your code is not functioning correctly. This means my answer is a workaround and I wouldn't advise it:

You can use URI and CGI to play with the URL:

uri = URI.parse(request.referer)
parameters = CGI.parse(uri.query)

utm_source = parameters['UTM_Source'].first

In reality I think your problem is that you're using params[:utm_source] instead of params[:UTM_Source]. You have to remember that your params hash is case-sensitive