Dynamic URL of button

Hi Wix Community and friends,

I want to change the URL button. If users are from Google, the URL should be website.com?track=ABC. If users are from Facebook, the URL should be website.com?track=XYZ.

How can I do this?

Product:
Which editor or feature is your question most relevant to?
Wix Editor.

How do you check where the users are from before setting the button?

I can do it based on using javascript and gettting document.referrer.

Then assuming you save the referrer, let’s say to a variable named ‘referrer’

$w.onReady(() => {
    $w('#button').link = 'website.com?track=' + referrer
})
2 Likes

You can actually retrieve the referrer using the Velo Wix Frontend API https://dev.wix.com/docs/velo/api-reference/wix-window-frontend/referrer

So the code would look like:

import wixWindowFrontend from “wix-window-frontend”;

let referrer = wixWindowFrontend.referrer;

$w.onReady(() => {
$w(‘#button’).link = ‘website.com?track=’ + referrer
})

1 Like