As pointed in HTTP_REFERER blank, need alternative and $_SERVER["HTTP_REFERER"] is not working on Mozilla, PHP's $_SERVER["HTTP_REFERER"]
and Javascript's document.referer
can be null, above all in the case of HTTPS request.
For example, traffic coming https://github.com/ gives me a blank string with both the PHP and JS method.
How do Google Analytics (or other analytics tool) do to log the referer accurately, for example in the case of https://github.com referer?
Note: this is not a duplicate question of the previously mentioned questions, the question here is to study how analytics tool (such as Google Analytics) do it (probably in a very clever way).
To put you in context,in Google Analytics (the universal JS) is setted by the following function:
As you can see, the only resource used is the document.referrer. So this comes empty there is nothing to do. That is one of the reasons to use UTM parameter when you can edit the link (to determine the source manually)
Now HTTPs due a security reason will not pass the reference, so maybe use parameter in the URL looks the best solution (replicate the UTM by you)