How do I trigger a lightbox in URL that contain utm query parameter?

Hi,
I want to tigger specific lightbox on url that contain utm_source=facebook for example.
i’m using this code:

import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
$w.onReady(function () {
let url = wixLocation.url;
if (String(url).indexof("utm_source=facebook") !== -1)
{wixWindow.openLightbox("LightboxName");}
})

But it’s not working.
Anyone know why?

A couple of observations:

indexof should be indexOf

The url is already a string so you don’t need String(url). You should be able to use url.indexOf()

If the string you are looking for is a query string of the URL, then you might consider using the query property.

Thank you Yisrael!
So if I understood correctly this is how the code should look like?

import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
$w.onReady(function () {
let query = wixLocation.query;
if (query.indexOf("utm_source=facebook") !== -1)
{wixWindow.openLightbox("LightboxName");}
})

Because unfortunately it still does not work properly :frowning:

Someone?

Keep in mind that wixLocation.query returns an Object . The code you want is something like this:

    let query = wixLocation.query;
    console.log('query', query); // inspect the returned query Object
    if(query.utm === 'facebook') {
        wixWindow.openLightbox("LightboxName");
    }
    else {
        // something else if utm is not "facebook"
    }

Thank you Yisrael!
It still doesn’t work for me

I’m not a programmer :slight_smile:

I just want the pop up trigger in case the URL contains “utm_source=facebook” for users that coming from a certain campaign.
I thought it would be a lot less difficult to execute

The code I posted will work, although I admit that for a non-programmer it might be a bit of a challenge.

If you want to learn how to use Velo, you can read the following introductory materials: