Show pop up after sign up

How do I show a pop up to a user, immediately after they sign up from anywhere on the site? (when he becomes a new member)
I use the Default Member Signup form, so I can’t set a trigger from there.

Attempts 1) Wix automations doesn’t have an ‘action’ option to show a pop up, though they have the ‘trigger’ (visitor signs up)

2 ) masterPage.js code by GPT

import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
import { currentMember } from 'wix-members';
import { session } from 'wix-storage';

$w.onReady(function () {
    wixUsers.onLogin(async () => {
          // Prevent repeat popup in same session
          const popupShown = session.getItem("signupPopupShown");

          if (popupShown) {
              return;
          }
          // Get current member
          const member = await currentMember.getMember();

          if (!member) {
              return;
          }
          // Account creation date
          const createdDate = new Date(member._createdDate);

          // Current time
          const now = new Date();

          // Difference in seconds
          const secondsSinceSignup =
              (now.getTime() - createdDate.getTime()) / 1000;

          //If account was created within last 30 seconds,treat as a brand-new signup
          if (secondsSinceSignup <= 30) {
              // Save session flag
              session.setItem("signupPopupShown", "true");
              // Open popup
              wixWindow.openLightbox("lightbox1");
          }
    });
});

Working in Wix Editor

It seems ChatGPT provided some out of date code :sweat_smile:

There’s a few things that need changing:

  • Velo is deprecated, and generally encouraged to use SDKs now
  • wix-users is deprecated, and has been for a number of years, you’d want to replace it with the @wix/site-members
  • Similarly for wix-storage and wix-window you’ll want to replace with the SDK equivalent - @wix/site-window, @wix/site-storage

You’re right to put it in masterpage.js, although will need to change the code to be up to date and complete what you need.

Are you expecting it to be only shown once? session storage doesn’t persist across browser sessions, so will show every time they open the browser

(post deleted by author)

Thank Noah. Yes I want it to show only once.

So far as AI help, I’ve used; GPT ChatGPT - W Epic Solutions, & the assistants under dev.wix.com (API Reference Docs). As the assistants under dev.wix.com aren’t for reiterated prompts I normally use that GPT for more complex solving.

After your tips, instead of the Velo Assistant in dev.wix.com, I tried that SDK assistant & Developer Assistant (under REST/API Reference tab). Their code were pretty basic, didn’t help much after reiterated prompts (final examples shown below).
When I asked that velo GPT to use sdk/rest, it lied while using velo.

Do you know any good GPTs/other AIs that give latest SDK/REST code, that I can reiteratively prompt?

Attempts
Attempted same prompts as below with SDK Assistant from dev.wix.com. Here’s an example from Developer Assistant:
Prompt: Show a pop up to a user, immediately only after they sign up from anywhere on the site. Not after login. Use masterpage.js. Don’t use velo. Use SDK or REST. I use the default member signup form so don’t have access to the signup button

import { authentication } from '@wix/site-members';
import { members } from '@wix/members';
import { window } from '@wix/site-window';

// This runs on every page of the site
$w.onReady(function () {
    // Register the callback for when a user signs up or logs in
    authentication.onLogin(async () => {
        try {
            // Retrieve the current member's identity details
            const { member } = await members.getCurrentMember();

            if (member) {
                const createdDate = new Date(member._createdDate).getTime();
                const lastLoginDate = new Date(member.lastLoginDate).getTime();

                // If the difference between creation and login is less than 10 seconds,
                // it is considered a fresh signup rather than a returning login.
                const isNewSignup = Math.abs(lastLoginDate - createdDate) < 10000;

                if (isNewSignup) {
                    // Open the popup by its name defined in the Editor
                    // Ensure "Automatically display popup on pages" is set to "No" in the Editor
                    await window.openLightbox("YourPopupName");
                }
            }
        } catch (error) {
            console.error("Error detecting signup status:", error);
        }
    });
});

In the docs, you have the option to copy the content of the area of docs you’re on to take to your own LLM. It’s usually best to copy each of the SDKs that you need and then ask your question to your LLM of choice.


Looking at your code, 2 things I think need changing:

  • I’d stop with the current createdDate/lastLoginDate and either:
    • Use a CMS to track who’s seen it - this will give persistance of data across browsers, sessions etc.
    • Or go back to using storage, but change to .local() which will persist across sessions, but will be removed if a user clears cache, meaning they’ll see it again on next login.
  • The other thing that needs changing is that you need to change your "YourPopupName” with the actual name of your Popup