Google analytics not registering my app as a source of traffic to other sites

74 views Asked by At

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:

  1. User visits my app -- https://www.myapp.com
  2. User clicks on link https://www.myapp.com/redirect/123
  3. 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.

1

There are 1 answers

2
bukk530 On BEST ANSWER

RFC does not specify a behavior for the Referrer header after a 301, however your problem is about protocols, you are being redirect from a secure HTTPS connection. The browser will not send any referrer because this could harm the client security exposing informations about the previous request. A simple solution would be using utm parameters https://support.google.com/analytics/answer/1033867?hl=en