Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Venetian/Palazzo referer detection for 'Back to' link
let referrerUrl = document.referrer;
let referrerUrlMatch = referrerUrl.match(/^https?:\/\/www\.(venetian|palazzo)\.com(?!\/meetings(\/|$))/);
let referrerName = referrerUrlMatch ? referrerUrlMatch[1] : null;

At that point, referrerName is either “venetian", "palazzo", or null (if referrer URL was from neither of the two sites, or if the path started with “/meetings/“), and the referrerUrl can be used as needed.

Examples: "https://www.venetian.com/meetings” returns null "https://www.venetian.com/meetings/“ returns null "https://www.venetian.com/meetings/test.html” returns null "https://www.venetian.com/meetings/something/meetings/“ returns null "https://www.venetian.com/meetings.html” returns “venetian” "https://www.palazzo.com/test.html” returns “palazzo” (And palazzo.com/meetings hard-redirects to the venetian.com/meetings anyway) To be tested, of course.

(snippet provided by Silvan)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.