I want to create a user profile named My points. Every user can get a share link or share code. When others signing up to my website and paste the link, they can get some rewards points.I want to know how to implement it. Thanks!
-
On the user profile page display a link that’s composed of the site url (or if you have a certain registration page - use it’s url + th user id as query parameter. Something like : [u]***Home
-
Put a copy link button on the member profile aloow them to copy the shareable link.
-
Add a text element with “copied” message to the page and make it collapsed on load.
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
const link =`${wixLocation.baseUrl}?recid=${wixUsers.currentUser.id}`;//it the registration is not on the home page put the path before the query pram.
$w.onReady(() => {
$w('#copyBtn').onClick(() => {
wixWindow.copyToClipboard(link)
.then(() => {
$w('#copiedMsg').expand();
setTimeout($w('#copiedMsg').collapse, 3000);
})
})
})
Now, on the page where the new visitor gets registered, get the query parameter with the recommender ID (recid) from the url query parameter and save it to your collection with the corresponding points
Hi @yingduo-liu ,
For no code solutions, please learn more about Wix Loyalty Program . Most of your needs are covered in the app.
Thank you very much. Is there a way I can get the input from the registration page to determine the parameters of the user link, and how do I get the parameters in the URL? I’m now using wixMembers_onMemberCreated in event.js to get the user-specific information, but I can’t seem to get the parameters here.
@yingduo-liu as far as I know, you cannot do it with wixMembers_onMemberCreated. You should capture the id on the frontend.
import wixLocation from 'wix-location';
const recommenderId = wixLocation.query?.recid;
Now, if you’re using custom registration it’s pretty easy, run the registration function and when it’s got returned save the value to your collection.
If you’re not using a custom registration, you should write some code, so onLogin if there’s recommenderId check the Members/PrivateMembersData collection if the _createdDate of this member is equal to the lastLogin value (which means this login event is also the registration event) and then save the recommenderId to your collection (the collection where you manage the score).
See also:
@jonatandor35 Thank you so much! It helps me a lot! I have created a custom registration and gotten the id. But a confirmation email is now sent when the user registers, and the “authentication.register” seems not be working. How can I solve it.
Thank you for your answer, but it doesn’t quite meet my needs
@yingduo-liu I don’t know. There’s not enough info here. Does it log any error 9use the site monitoring/logs tool).
import { authentication } from ‘wix-members’ ;
import wixLocation from ‘wix-location’ ;
import { doRegistration } from ‘backend/register.jsw’ ;
import { myApproveByEmailFunction } from “backend/register.jsw”
let emails = ;
$w . onReady ( function () {
$w ( ‘#register’ ). onClick (() => {
const password = $w ( ‘#password’ ). value ;
const email = $w ( ‘#email’ ). value ;
emails . push ( email );
const recommenderId = wixLocation . query ?. recid ;
let options = {
contactInfo : {
firstName : $w ( '#firstName' ). value ,
lastName : $w ( '#lastName' ). value ,
emails : emails ,
},
privacyStatus : 'PUBLIC'
}
authentication . register ( email , password , options )
. then (( registrationResult ) => {
const status = registrationResult . status ;
console . log ( recommenderId , "recommenderId" );
// When the site is configured for automatic approval, status is "ACTIVE" and the member is approved and logged in.
console . log ( 'Member registered and logged in:' , registrationResult );
})
. catch (( error ) => {
console . error ( error );
});
});
});
Here is my code. when I use email to register. It will get a page like this.
but the recommenderId is not in my log.Thanks.
@yingduo-liu I don’t see a problem with your registration code. But be aware that if you require email approval, the member is not returned to the front end (and if you need to get the member to the front end, you’ll have to do it through a backend function (in a jsw file).
@jonatandor35 Thanks! It does need to write some backend function and get the id from other ways!
The number of copies of my product they buy - THAT needs to be added into their loyalty points tally.
So if its 4 tee shirts - their Loyalty tally increases by 4 points.
How do I achieve this ?
Currently the loyalty program only allows me to give points for every $1 spent and every store order. I tried the automation also - but that too is only restricted to the store order.