Using the following code on a page or even site-wide. The referrer always comes back null. Any ideas? I’m trying to get the referrer so I know whether I should redirect to another page or not.
import wixWindow from ‘wix-window’;
let referrer = wixWindow.referrer;
console.log(referrer);
It’s not currently published. I did notice that when I tested in preview mode I did get a referrer. However, whenever I would publish the site and test, the referrer always came back null.
Very strange. I’ve been trying this out myself on some of my sites and everything works fine. Could you explain more about your site: pages, general structure, code, whatever.
I’d love to help but I’m going to need more to go on.
Thanks for your help! Basically what I’m trying to do is add a registration page prior to a user purchasing an item. The process would be like this:
User clicks an add to cart button
If the user hasn’t already filled out the registration form, they would be taken to the form. This form is setup with user input elements and is connected to a dataset. I have code on the cart page that sends the user to the registration form, but I would like to only send them there if they haven’t already filled out the form. I’m using wixLocation.to to send them to the form.
I thought I could just grab the referrer when a user lands on the cart and see if they came from the registration form or not.
That didn’t work so I thought I would set a session variable in the After Insert hook of the dataset connected to the form, but I could never get the variable to pass through to the cart page.
Hi Yisrael,
I have similar use case while having another issue with “referrer”, probably somehow related to the discussed one.
Suppose I have a page www.site.com/pageA. On this page I have a button, whose onClick is as following:
export function some_button_click(event, $w) {
wixLocation.to(baseUrl + ‘/pageB’);
}
Page “pageB” is router page. In routers.js I have the following code:
export function pageB_Router(request)
{
…
let from_url = request.referrer;
…
}
The surprising part is that from_url equals to “www.site.com/pageB”.
While I would expect to see there that I’ve arrived from pageA.
Is it my misunderstanding or it is a bug?