How to get the referral source url when calling javascript?

I take am on a site called domain1.com and go to another domain2.com site, where I call an external js call.

The problem is that the referrer of the js call is set to domain2.com , but I need the original referrer, i.e. domain1.com . I see that the Google analytics request, I see that the utmr request parameter contains the referrer url. example - utmr

Any idea how to get the same as in GA?

+4
source share
2 answers

I got a solution, it's simple. The added document.referrer in the external script works fine and provides the referrer URL of the current page.

Thanks. Balaji

+3
source

Some questions:

  • Do you have control over domain2.com ?
  • Do you have control over the external js that you are calling?
  • If not, is there a way to pass another referent through a parameter?

You cannot change the reference page to call the service you are doing, to another service. However, the source code for domain2.com containing an external js call will have access to its own referrer domain1.com , and it needs to pass it as a parameter, providing a remote JS interface that allows passing the referencing parameter. This is available using the server code language that you are using. For example, here it is in PHP :

 <script type="text/javascript"> var referer = "<?php echo $HTTP_REFERER; ?>"; doRemoteCall("theRemotePage?referer=" + referer); </script> 
0
source

All Articles