Javascript to Identify Landing Page

In web analytics implementation, we often need to implement some special tracking code for the landing pages. For example, firing adserver tags, applying some logics to the campaign code, etc. I just created this piece of Javascript code that can detect the referral URL hostname, and compare it against the current page hostname to check whether the referral URL is on the same website. If they are different, then I consider it is a landing page view because the traffic is from outside of the current website.

Here is the code:

if(location.hostname != document.referrer.match(/\/\/([^\/]*)\//)[1]){
	console.log('this is a landing page');
	console.log('not a landing page');

To test the code, you can copy and paste it in the browser console and execute it.

Share this Story

About chaoming.li

Technology entrepreneur, web analytics specialist, Internet enthusiasts. I also like movies, computer games, history and other interesting stuff. I was born in Guangzhou China and I live in Sydney Australia now.

Leave a Reply

Your email address will not be published. Required fields are marked *


© Copyright 2014, All Rights Reserved