I have one website like* www_demo_com and i was advertised on youtube so how to know users where to come?
I'was tried using this.
location.host()
but this is not perfect for my problem.
I have one website like* www_demo_com and i was advertised on youtube so how to know users where to come?
I'was tried using this.
location.host()
but this is not perfect for my problem.
It is not clear what you are asking here - but I am going to assume you are asking - how do i know if someone came to my website from youtube
1) using document.referrer property - the documentation can be found here - note this will not always work (depends on a bunch of things)
you can do something like:
if (document.referrer && document.referrer != "")
{
if(document.referrer.indexOf("youtube") > -1)
{
//here we know that the referrer value contains youtube - you should execute some logic here
}
}
2) if you have given someone a referral link and told them to use that - you need to look for the unique string you gave them - for instance if you told them to go to www.yoursite.com/?ref=some-refferal-link-identifier you can do something like this:
if(window.location.href.indexOf("some-refferal-link-identifier") > -1)
{
//here we know that the referrer value contains your unique ID - you should execute some logic here
}
All that being said - the best way is probably to use something like google analytics - obviously google built their core business on this stuff, you will be able to use their tools to track this very well.