I am working on an app which is a essentially an aggregator of links to other websites. However, instead of linking directly to websites, the links on my app point to an endpoint on my app -- /redirect/:uuid, which in turn performs a 301 redirect to the respective sites:
- User visits my app -- https://www.myapp.com
- User clicks on link https://www.myapp.com/redirect/123
- That results in a 301 redirect to http(s)://external-site.com/?ref=myapp
The issue I am having is that for some reason Google analytics (running on external-site.com) is not attributing the traffic my app is sending to the external-site to my app. It just marks it as direct traffic.
My app is a Rails app, hosted on Heroku. In order to do the redirect I am doing
redirect_to "http://external-site.com/?ref=myapp", status: :moved_permanently
I noticed that if just point my browser to https://www.myapp.com/redirect/123 and then get the 301 redirect to http://external-site.com/?ref=myapp
document.referrer is blank. Which I found weird. Shouldn't the browser still send the HTTP Referer header in the case of a 301 redirect?
Would appreciate some help.