You can use the new Memberstack 2.0 front-end API and the following code to pass member data into Crisp.
Place the following code in the BODY section of your global site scripts:
<script type="text/javascript">
window.$memberstackDom.getCurrentMember().then(({ data: member }) => {
if (member) {
let email = member.auth.email
let name = member.customFields["name"]
$crisp.push(["set", "user:email", [email]])
$crisp.push(["set", "user:nickname", [name]])
} else {
$crisp.push(["do", "session:reset"])
}
});
</script>
Passing in Member Plan Data & Custom Fields (Advanced)
<script type="text/javascript">
CRISP_RUNTIME_CONFIG = {
session_merge : true
};
window.$memberstackDom.getCurrentMember()
.then(({ data: member }) => {
if (member) {
let email = member.auth.email
let name = member.customFields["name"]
let planConnections = member.planConnections;
let planIds = planConnections.map((plan) => plan.planId).join(', '),
$crisp.push(["set", "user:email", [email]])
$crisp.push(["set", "user:nickname", [name]])
$crisp.push(["set", "session:data", [[
["user-bill-amount", "$200"],
["user-id", "abcd"],
["plans", planIds],
]]]);
} else {
$crisp.push(["do", "session:reset"])
}
});
</script>
Comments
1 comment
The advanced cutom code did not work for me. After working with Crisp support here's the provided code :
<script type="text/javascript">
window.$memberstackDom.getCurrentMember().then(({ data: member }) => {
if (member) {
let email = member.auth.email;
let name = member.customFields["first-name"];
let planConnections = member.planConnections;
let planIds = planConnections.map((plan, index) => [`plan_${index + 1}`, plan.planId]);
$crisp.push(["set", "user:email", [email]]);
$crisp.push(["set", "user:nickname", [name]]);
$crisp.push(["set", "session:data", [planIds]]);
} else {
$crisp.push(["do", "session:reset"]);
}
});
</script>
Please note that in my case I'm using a custom field "first-name". You may need to adapt it.
Please sign in to leave a comment.