Get current login user info in javascript code

Hi All,
I’m trying to implement a referral program (referralmagic) in my website, as per their instruction, i need to trigger the below javascript code once after user has signed up successfully.

but my problem now is :

  1. how can i get the current signed up user info from the javascript code (i know there is API to get current user info from wix code) ?
  2. My above code should be triggered after the signed up action successfully returned. i understand there is dataset onAfterSave API. how can i call the javascript code from the page code?

$w(“#myDataset”).onAfterSave( () => { console.log(“After save”); } );

Appreciate your advice on this issue.

anyone got any thoughts on this? thanks

Hi,

to get user information you can use Wix Users API:
https://www.wix.com/code/reference/wix-users.html

However, your second point is a bit more complicated. Referring to window.rfmgc looks to me like it may not work with Wix Code. You should check out the API integration option.

With Wix Code you usually need a way to integrate without having the full browser context available, as the code runs in a an isolated environment. So, in these cases you should look for direct integration options, where you call the endpoint with the tracking information. For that see Wix Fetch API:

I hope this puts you on the right track. Feel free to continue the discussion if you need any further assistance.

Hi Giedrius,

Thanks for your suggestion. I’m using a third party referral program, the way they work it that : they provide a piece of javascript code to embed to your website, once user registered from your website, you’ll need to trigger that code, the code will save user’s email address in a website tag, so that their program will scan your website and retrieve that info.

so it is not that i need to call some external API from wix. it’s another way round.

I was trying to put my javascript code in the html component and use the postmessage to trigger it once the button is clicked, but it did not work. because the referral program only scan the code directly under body tag, the html component is actually a iframe tag.

Is there a way that i can put a

or something directly under the body, and i can use postmessage to send message to it ?

Hi i have this problem solved to 60-70% i just need help with retrieving the unique URLs with the contain() or get() functions from their respective database collection in a query, then displaying the number of referrals in a number box. Any help or sample code where I can plug in some values?

Replying to christoph.zaknun
Please open your own post and describe your issue in detail.

You can link this post to your own.

Unfortunately I can’t the server in velo forum doesn’t allow me to submit one. Thank you for your advice I’m currently working with someone else right now