I’ve created a welcome email that I send when the user registers on my site.
I would like to use the welcome also as confirmation that the email address is valid. As such I added a confirmation link that will open the confirmation page, which should receive the user id as parameter to mark the contact as verified. I’ve tried to set the link address as https://www.pelukids.info/pelukids-club?confirm=${id} , but the variable replacement is not being done on the link.
Is there a way to set this up?
Thanks
Hi Ido:
Then this is a real problem because your documentation suggests that you can
I was trying to figure this out myself.
If you go to this page that discusses wix-users-backend:
https://www.wix.com/code/reference/wix-users-backend.html#RegistrationResult
You will see an example that shows how to do this:
Note: wixUsers.emailUser() is showing the use of a ’ verifyLink ’ with a URL.
The implication being (unless there is a generic wix ‘verify-registration’ triggered email already coded to accept a “verifyLink” property) that you can indeed use URLs ;-).
In addition this example seems a little broken because it doesn’t correctly show where the approvalToken in the URL is pulled from the results object (it could be one of sessionToken or approvalToken per the RegistrationResult documentation - see below) the rest of the code implies that it should be a sessionToken but the naming of the email variable name uses approvalToken.
Now I have tried to use this variable in buttons and text links without much success.
My last attempt was to try to use the +Add Variable button in the text field edit dialogue for a text link. It ended up freezing the screen and had to close the browser window to restart my triggered email editing session…
Is there any chance I am misreading the documentation on this???
Wix team please provide more accurate and working examples. Thanks
Steve
I used this workaround to send a triggered email to new members with a link confirmation, but with the old way, I don’t know if it can help:
wixUsers.emailUser(“xxxxxxxCODE”, userId, { variables: {“CONFERMA”: " https://www.google.it "}} );
It returns a clickable link !
Of course now instead of www.google.it you have to form and place the correct dynamic_user_link
For now it works !
So the trick is writing the url as text and letting the email client figure out that it is an url and then make it magically clickable.
Thanks guys but the link I want to send is the token for verifying email during registration. Most end users would expect a button or simple " click here to validate " link.
Given that the resulting email is essentially a web page - I don’t understand why a button cannot have a link bound to a button. After all the button can be linked to a url per the dialogue shown above.
While this is a work around i’ll play with. /it seems to me that its not the asthetic Wix is promoting.
Cheers.
Hi Steve, what could you suggest ?
Try this:
You select the text or element that you want to bind a URL to and get the standard dialogue box as shown below.
Then you click on the Add Link icon giving the URL dialogue. With the focus on this you either type in a variable you already have ${validationLink} or click on the + Add Variable button, add a new variable which is then populated in the link box. When you execute the send function it substitutes the variable value in the link that will already be being added for the element if you manually used a URL like www.google.com (e.g. validationLink = ‘www.google.com’)
Sorry, but that doesn’t work. No replacement is done in the URL
Hi Ariel - I understand that. I thought Mauro was asking what I would propose Wix should provide in the API. Sorry for the confusion.
Not at all, you are welcome, but the workaround I proposed seems the only way in this moment. Any ideas or suggestions ?
Mauro I haven’t tried it yet but the problem for me is that this means my user will see a text link that looks like this:
Yes you are in right, and if waiting the Wix new features, could you try to short it ? ( like goo.gl )
Yes I thought about using a database to store the longer token and send a smaller id that I resolve in the database to get the token. I think this will be more secure. The main problem I am dealing with at the moment is getting the triggeredEmail to send.
Hi Steve, i have the same problem with sending the triggerd email with the confirmation link. Everything works fine, but the mail to the pending member is not going out. Do you have a solution?
Hi Ahabeck -
yes I managed to get it to work but it is not straight forwards as you need to use both the wix-crm and the wix-users apis together in the correct order. The main thing to understand is that the wix-crm emailContact() api can be used on a page visited by an anonymous site user, a Visitor. The wix-users.emailUser() api needs the page user to be logged in so role = Admin or Member.
The other problem I found it that you cannot use the wix-crm record that you get in wix-crm.createContact() with wix-users.register(). The result is that you end up managing two records in the crm each with a different _id. So when sending triggered emails you need to use the correct _id and context. So the flow goes like this:
create contactObject with firstName, lastName, email, …
wix-createContact(contactObject) => contactId [REMEMBER This For your Triggered email}
then
wix-register(email, password) => User record (with a different userId) + ApprovalCode with status Pending
then
wix-crm.emailContact('triggeredEmailName", contactId [from createContact]) with url to verification page containing ApprovalCode
then
user launches the url including the approval code → pass to back end function and call wix-users-backend.approveByToken() => return sessionToken to verification page.
This all seems to work BUT doesn’t actually log the user in with the session token. They still need to login after this sadly.
Hope this helps.
Thanks, I have done it with sendGrid implementation. Works for me and user logs in automatically after verification. Why are they giving us code that does not work and lots of errors in it. I’m getting crazy about this!!
hello Ariel,
Im having the same problem. if you solved it, please tell me how.
thank you
Nimrod
I used this workaround to send a triggered email to new members with a link confirmation, but with the old way, I don’t know if it can help:
wixUsers.emailUser(“xxxxxxxCODE”, userId, { variables: {“CONFERMA”: " https://www.google.it "}} );
It returns a clickable link !
Of course now instead of www.google.it you have to form and place the correct dynamic_user_link
For now it works !
https://www.wix.com/code/home/forum/wix-tips-and-updates/triggered-emails%3Fpage%3D2
Here’s my workaround:
export function doRegistration(email, password, firstName, lastName) {
return wixUsers.register(email, password, {
"contactInfo": {
"firstName": firstName,
"lastName": lastName
}
} )
.then( (results) => {
wixUsers.emailUser('RQVmcWk', results.user.id, {
"variables": {
"name": firstName,
"token":results.approvalToken, //This is the new line.
"verifyLink": `https://www.domain.com/post-register?token=${results.approvalToken}` //You don't need this variable anymore.
}
} );
} );
}
Then, on your triggered email insert the link with the fixed baseURL and the token as a variable like this: https://www.domain.com/post-register?token=${token}
And that should do the trick.
Enjoy
Hi Felipe!
I’ve the same need : send triggered email with link to confirm registration of a member on my site.
Email trigger it’s send ok, received by the user with the link.
But link contained into mail doesn’t work. This because variable " approvalToken " is not set correctly : ( ?token= )
I think I haven’t set path correctly into the email trigger template.
Could you please give me help about link set into the mail trigger ?
You use URL path +AddVariable ? How to setup it correctly ?
I put below my code that I use into my application :
"/*******************************
* backend code - register.jsw *
*******************************/
import wixUsersBackend from 'wix-users-backend';
export function doRegistration(email, password, firstName, lastName) {
// register the user
return wixUsersBackend.register(email, password, {
"contactInfo": {
"firstName": firstName,
"lastName": lastName
}
} )
.then( (results) => {
// user is now registered and pending approval
// send a registration verification email
wixUsersBackend.emailUser('verifyRegistration', results.user.id, {
"variables": {
"name": firstName,
"verifyLink": `https://mywebsite.com/verification?token=${results.approvalToken}`
}
} );
} );
}
export function doApproval(token) {
// approve the user
return wixUsersBackend.approveByToken(token)
// user is now active, but not logged in
// return the session token to log in the user client-side
.then( (sessionToken) => {
return {sessionToken, "approved": true};
} )
.catch( (error) => {
return {"approved": false, "reason": error};
} );
}
/*********************************
* client-side registration code *
*********************************/
import wixUsersBackend from 'wix-users';
import {doRegistration} from 'backend/register';
export function button7_click_1(event) {
let firstName = $w("#input12").value // My input values
let lastName = $w("#input11").value
let email = $w("#input10").value
let password = $w("#input9").value
doRegistration(email, password)
.then( () => {
console.log("Confirmation email sent.");
} );
}
/**************************************
* client-side post-registration code *
**************************************/
import wixLocation from 'wix-location';
import wixUsersBackend from 'wix-users';
import {doApproval} from 'backend/register';
$w.onReady( () => {
// get the token from the URL
let token = wixLocation.query.token;
doApproval(token)
.then( (result) => {
if (result.approved){
// log the user in
wixUsersBackend.applySessionToken(result.sessionToken);
console.log("Approved");
}
else {
console.log("Not approved!");
}
} );
} );
And this is how i’ve set up link into email trigger :
Thanks a lot for the help !
Mattia