Last active
March 18, 2022 13:19
-
-
Save bipiane/1e1218c99111d495e5467ce90078a24d to your computer and use it in GitHub Desktop.
kaviyo & segment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
window.addEventListener('klaviyoForms', function(e){ | |
if (typeof analytics != 'undefined' && e.detail.type === 'stepSubmit' && e.detail.metaData) { | |
console.debug('klaviyoForms: ', e.detail.metaData); | |
if (e.detail.metaData.$email) { | |
const userId = ''; | |
const traits = { | |
email: e.detail.metaData.$email, | |
accepts_email_marketing: true | |
}; | |
console.debug('klaviyoForms: sending newsletter Identify event', {userId, traits}); | |
analytics.identify(userId, traits); | |
const EVENT_FRONT_EMAIL_SIGNUP = 'Email Signup Completed'; | |
const properties = { | |
email: e.detail.metaData.$email, | |
name: e.detail.metaData.$first_name | |
}; | |
console.debug('klaviyoForms: sending "' + EVENT_FRONT_EMAIL_SIGNUP + '" event', properties); | |
analytics.track(EVENT_FRONT_EMAIL_SIGNUP, properties); | |
} else if (e.detail.metaData.$phone_number) { | |
const userId = ''; | |
const traits = { | |
phone: e.detail.metaData.$phone_number, | |
accepts_sms_marketing: true | |
}; | |
console.debug('klaviyoForms: sending SMS Identify event', {userId, traits}); | |
analytics.identify(userId, traits); | |
const EVENT_FRONT_SMS_SIGNUP = 'SMS Signup Completed'; | |
const properties = {phone: e.detail.metaData.$phone_number}; | |
console.debug('klaviyoForms: sending "' + EVENT_FRONT_SMS_SIGNUP + '" event', properties); | |
analytics.track(EVENT_FRONT_SMS_SIGNUP, properties); | |
} | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment