EN
JavaScript - detect if user entered webpage directly (source: direct)
5
points
In this short article, we would like to show you how using JavaScript (in web browser) detect if user entered webpage directly.
As user who entered webpage directly we understand there wasn't used referral link from other webpage.
Quick solution:
// ONLINE-RUNNER:browser;
const isDirect = () => !document.referrer;
console.log(isDirect());
Note:
It is impossible to be sure if source is direct entrance when
document.referrer
is empty depending on possiblerel="noreferrer"
attribute used in the source link.This is reasone why empty
document.referrer
is marked asDirect / (None)
in different analytics tools, so it may be good to use UTM links to detect source if it is possible.