K
K
KGZVER2021-05-24 09:46:28
JavaScript
KGZVER, 2021-05-24 09:46:28

How to find out where the user came to the site?

I'm working on a project written in Next JS, I need to make a "go back" button, but provided that a person got to the page through our site, if through a third-party it throws them to the main page, this is so as not to lose the user.

I tried to write this code.

const handleUrlFromGoToSite = () => {
      if(!document.referrer.includes('mysait-url')) {
        Router.push('/');
      }
      else Router.back()
  };


But for some reason document.referrer always returns an empty string, no matter where I come from.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nassonov, 2021-05-24
@AndryuhaPro

Come here , it might help.
This is done in PHP, you are unlikely to do it in JS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question