Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francescostella/c0bcd542d64aa12191a5724a45302527 to your computer and use it in GitHub Desktop.
Save francescostella/c0bcd542d64aa12191a5724a45302527 to your computer and use it in GitHub Desktop.
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