Storing skin-quiz answers on the profile to personalize a beauty store
We run a skin-type quiz on our Hydrogen store and want the answers to drive routine recommendations across the storefront. This is the payload I want on the profile when the quiz completes:
{ "skinType": "combination", "concerns": ["redness", "dryness"], "spfDaily": true}Two questions. How do I write this to the Croct profile from the quiz completion handler, and is there a naming convention I should follow so these attributes are usable in audience conditions later
1 answer
Custom attributes are written through the user patch API. From your quiz completion handler:
croct.user.edit() .set('custom.skinType', 'combination') .set('custom.concerns', ['redness', 'dryness']) .set('custom.spfDaily', true) .save();The one quirk to know: attributes are written with the custom. prefix but queried without it in CQL. So the audience condition is:
user's skinType is "combination"not user's custom.skinType. That trips almost everyone once.
On naming, camelCase like you have it is the usual convention and keeps the CQL readable.
Also worth knowing for your use case: audiences evaluate in real time, so the personalization reacts in the same session the quiz is completed. The shopper finishes the quiz, and the routine recommendation slot can already serve the combination-skin variant on the very next page.
Confirmed working, and the same-session part is exactly what we wanted. The prefix quirk would have cost me an afternoon, thanks for flagging it.