Storing at Member’s metadata from the registration form Answered

Post author
Marc Hudson

Does anyone know how to store something in a Member’s metadata from the registration form? I need to store the email campaign’s name (that resulted in a certain onboarding journey) as metadata on the member.

Trouble I’m finding:

  • Metadata is only set with JS, not with attributes.
  • I don’t see how you can set it via JS because they haven’t submitting the register form to create an account at this point.
  • Custom fields don’t feel like the right place for this info.

Comments

5 comments

  • Comment author
    Tyler Bell

    cc Julian Galluzzo do we have any member scripts for this?

    0
  • Comment author
    Chukwudi Onyekwere

    cc Julian Galluzzo If you're creating a Memberscipt for this, please keep in mind that Metadata is read-only via the frontend and can only be updated from the backend.

    0
  • Comment author
    Marc Hudson

    Yep Chukwudi-Onyekwere, I realised after writing, that you can’t update Metadata from JS. I then saw that you can set Custom Fields that don’t exist in the UI and, therefore, they won’t appear in the UI. So I’m looking at that route now. Although, I’m having to use a cookie and updateMember() on the subsequent page load. Not the cleanest approach but it’ll work. Perhaps the ability to set custom fields (which don’t exist in the UI) using attributes on the register form would be a useful addition? I don’t see any mechanism atm for storing meta on a user from registration.

    Also, it seems you can’t delete a custom field’s value by setting the value to null . For example: $memberstackDom.updateMember({'customFields': {'campaign': null}}).then(({ data: member }) => { // … }); I haven’t found a value that works at deleting a non-UI field yet. This would be useful for housekeeping. Thanks

    That doesn’t work either since the Make “Watch new Members” trigger fires before I can update the Member’s custom field with a value. Still looking for a hero 🤞

    0
  • Comment author
    Duncan from Memberstack

    Marc Hudson Am i correct that you are trying to pull the email campaign name from a link param? And then pass that into a hidden field which gets saved in Memberstack?

    If so, maybe this will help? https://www.memberstack.com/scripts/prefill-form-based-on-url-parameters

    and then you can add the hidden custom field to your sign up form. https://docs.memberstack.com/hc/en-us/articles/7842471590811#hide

    0
  • Comment author
    Marc Hudson

    Hey Duncan, thanks, this is close to my existing code, however after sleeping on it, I remembered that memberstack has a “Hide from Pre-built UI” switch when creating Custom Fields. I know the data-ms-member attribute will work if the Custom Field already exists in the UI, so I managed to set the value by adding that attribute on a hidden form field.


    Some thoughts:

    • I saw that you can create and set a new Custom Field on the fly (which hasn’t been created in the UI) by using $memberstack.updateMember() but this doesn’t appear to be possible when using data-ms-member="<new_custom_field>" on the form itself. Might be a useful addition.
    • I still feel this type of information is more suited to being stored in metaData (so the user can’t alter it). If I move the value over to metaData via Make, I’m left with an empty Custom Field that I can’t remove. If you could not only create a custom field using a data-ms-member attribute, but then also delete it by setting its value to null , this would make Custom Fields more flexible.

    Thanks :)

    0

Please sign in to leave a comment.