Folks:
I have been dealing with this for a while and have a ton of correspondence with the crm team.
Basically the focus for the CRM function is that you manage contacts on the dashboard not on your web page. This is an issue which leads to an API that is difficult to use and has cross dependencies between wix-users and wix-crm that are not managed.
On the issue of the Anonymous User test. This is designed that way because the createContact function is supposed to be used to create contacts on pages were the user is not a member or logged in - basically for mailing lists etc. However the functionality has expanded to include update without thinking about what constitutes an update when you don’t have the key field (‘_id’) of the record (which happens if the user information is added in the dashboard) or, if you do, the key field is ignored by the API.
My proposal to the team is that they need to follow REST API CRUD practises and provide Create, Read, Update and Delete services in the api. These services could be restricted with logged in user privileges where Read, Update and Delete are used (you don’t want random users accessing or changing other people’s records).
Now what this means is that the wix-crm api should really require the user to be a site member before being able to make any changes to their site held information. This would be easy for site admins.
This then raises the question of how wix-users should play with wix-crm.
Well, if a user, who has provided their information for mailing list purposes which was added to the crm using wix-crm.createContact(), decides they want to alter their information then they should become a site member and register. This means that the wix-user API register() or promptLogin(contactInfo, {‘mode’:‘signup’}) functions should look for an existing CRM entry with a corresponding primary email address and allow the the user to register an account against that CRM record. This should be done using email validation and would ensure unique CRM records are managed in the wix-crm.
At the moment if you register a site member using wix-users you will generate at least one duplicate record that is not connected to the original crm contact.
Now when it comes to sending emails to the user this means you may have two contactIds one obtained from the createContact() function and one created from the register() function. Because these ids are from wix-crm you should be able to use either to send email BUT you should choose the correct API based on whether the user is logged in or not.
If the user is logged in then you MUST use the wix-users.emailUser() function to send triggered emails. If you are not logged in then you MUST use the wix-crm.emailContact() function.
Now the last thing is that neither wix-users or wix-crm gives you a way to access the contact record (the CRUD API doesn’t exist). So the only way to do that is to keep contact data in your own data collection and duplicate information in the crm. This isn’t a huge issue unless data you keep data in your data collection is changed in the CRM using the dashboard. Now you are in a situation where you need to manually fix the data collection. This problem aside, there is a benefit in having data managed in the site app, you can and should, manipulate contact data in backend code which is more secure.
So how would I deal with site users at this point in time given these challenges?
I would not use the wix-crm API except for perhaps the wix-crm.emailContact() function.
Since the wix-users api provides for register and login and that API manages user information in the CRM I would use wix-users register() with a dummy password to create an initial crm record and just make the user a site member. They don’t need to know they are a member if all you are doing is capturing email information for mailing list purposes.
Put other member information that you want to track in your own data collection. Now you have a crm id that you can use for triggeredEmails. If the user comes back and wants to change their information then they are presented with the login screen and can use recover password to complete their site membership and access their data.
Steve