The importance of Referrer
There is a referer header in the HTTP request, which indicates the source of the current traffic. For example, clicking a link on /sports/ to reach the home page, then referrer is /sports/. In Javascript, we can get the same information through. Through this information, we can know what channel the visitors come to the current page. This is very important for Web Analytics. This can tell us the distribution of traffic brought by different channels, as well as the keywords searched by users, etc., which are all obtained by analyzing this referrer information.
However, for various reasons, sometimes the referrer read in Javascript is an empty string. Let’s summarize what circumstances will referrer be lost.
Modify Location object for page navigation
The Location object is a very practical object for page navigation. Because he allows you to change only part of the Url. For example, switch from the cn domain name to the com domain name, other parts remain unchanged:
= "";
However, modifying the method of page navigation by page navigation will result in the loss of Referrer under IE.
Return empty string under IE5.5+
Chrome 3.0+, Firefox 3.5, Opera9.6, Safari 3.2.2 all return to the source web page normally
Open a new window
Example:
<a href="#" onclick="('')">Access Google</a>
Clicking this link will open the Google website in a new window. We enter the following js code in the address bar to see the sent referrer.
javascript:alert()
Test results:
Return empty string under IE5.5+
Chrome 3.0+, Firefox 3.5, Opera9.6, Safari 3.2.2 all return to the source web page normally
If it is redirected in this way under the same domain name, then we can access the object to obtain the lost referrer information. The code is as follows:
<script type="text/javascript">
var referrer = ;
if (!referrer) {
try {
if () {
// If cross-domain is used under IE, a permission exception will be thrown
// There are no properties under Safari and Chrome
referrer = ;
}
}
catch (e) {}
}
</script>
If you cross the domain, you will be helpless~
Drag the mouse to open a new window
Mouse drag and drop is a very popular user habit nowadays. Many browsers are built-in or can support mouse drag and drop browsing through plug-ins. However, the pages opened in this way basically all referrer is lost. Moreover, in this case, it is impossible to obtain the lost referrer in a method.
Tested:
Maxthon 2.5.2, FireGesture plugin for Firefox, Chrome 3.0+, Opera 9.6, Safari 3.2.
Click on the internal link of Flash
When you click on Flash to reach another website, the situation of Referrer is more messy.
Under IE, the value read through the client Javascript is empty, but if you use traffic monitoring software to look at it, you will find that in fact, the Referer message header in the HTTP request has a value, which may be a bug implemented by IE. At the same time, this value points to the address of the Flash file, not the address of the source web page.
After clicking Flash under Chrome 4.0 to reach a new window, Referrer also points to the address of the Flash file, not the address of the source web page.
Chrome 3.0 and Safari 3.2 are the same, and both will lose Referrer information.
Opera, like Firefox, the value of Referrer is the address of the source web page.
HTTPS jump to HTTP
When jumping from an HTTPS website to an HTTP website, the browser will not send a referrer. The behavior of these major browsers is the same.
For example, when we use Google Reader or Gmail under HTTPS, we click on a link to go to another website. Technically, there is no difference between such access and users directly typing the URL.
The impact of Referrer loss on advertising traffic monitoring
If Referrer is lost, Web Analytics will lose a very important part of the information, especially for advertising traffic, it is impossible to know the actual source. At present, many websites in China that use Google Adsense advertising use the method to open ad links, so the Referrer will be lost under IE. We know that IE is currently the browser with the largest market share, so its impact is great. Many traffic statistics tools will therefore classify this part of traffic as "direct traffic", which is equivalent to users typing the URL directly.
In this case, it is necessary to allow the ad plagiar to add specific tracking parameters to the Url of the landing page when serving the ad.
For example, the URL that arrives after clicking is /. In order to monitor which channel this traffic comes from, we can modify the landing URL served to /?src=sina, similar to this method, and then use Javascript code to extract this src parameter in the landing page, so that the advertisement source information can be obtained.
When serving Google Adwords, the background system has an "auto tag" option. When this option is enabled, when Google generates the landing page URL of all ads, it will automatically add a gclid parameter. This parameter can integrate the data of the Google Analytics backend and Adwords ad background. This way you can know which campaign the ad traffic corresponds to, which ad source and ad keywords and other information. It is actually similar to the idea mentioned above. It's just that Google has automatically made Url modifications for you.
Solution to empty referer under IE
If you jump in IE, the referer value is empty. And if the referer jumps in the tag, the referer will not be empty. So, the following code can solve this IE problem
function gotoUrl(url){
if(){
var gotoLink = ('a');
gotoLink .href = url;
(gotoLink);
gotoLink .click();
}else{
= url;
}
}
Forbid browsers to not bring referer when accessing links
When we click on a link from one website to enter another page, the browser will add a Referer value to the header to identify the source page of this visit. But this kind of logo may leak user privacy. Sometimes I don’t want others to know where I clicked in. Is there any way to make the browser not send a referer?
•Use the newly added html5 solution, use rel="noreferrer" to declare the connection attribute as noreferrer. Currently, only Chrome4+ supports it.
•Use an intermediate page, but actually send a referrer, such as using Google's connection steering.
• Use the javascript protocol to link to transfer, see the instructions below.
A new window is equivalent to target="_blank":
function open_window(link){
var arg = '\u003cscript\("'+link+'")\u003c/script\u003e';
('javascript:;', arg);
}
</CODE>
Turning to a connection is equivalent to target="_self":
function redirect(link){
var arg ='\u003cscript\("'+link+'")\u003c/script\u003e';
var iframe = ('iframe');
='javascript:;';
=arg;
(iframe);
}
</CODE>