Redirecting visitors to different landing pages based on referral URLs using Javascript

I have no experience with JavaScript/CSS/HTML, so I hope someone can give me some instructions. I would like to write and integrate a javascript script on a website to group visitors based on their referral URLs (e.g. if partner website or not), then to retarget them to specific contents on the website (landing pages) based on which visitor group they belong to. I only need basic script to illustrate the idea, as part of multidisciplinary project (academic purpose). Many thanks in advance for your reply.

Upvotes: 0

Views: 694

Answers (1)

exception_thrown
exception_thrown

Reputation: 586

Based on the very basic information provided, from a high level you could do it as in a JS file.

let refer = document.referrer;

   if(refer == "www.example.com"){
     window.location.href = "http://www.example.com/index1";
} else if(refer == "www.example2.com"){
     window.location.href = "http://www.example.com/index2";
} else {
     window.location.href = "http://www.example.com/index3";
}

Upvotes: 1

Related Questions