Skip to content

Instantly share code, notes, and snippets.

@bipiane
Last active March 18, 2022 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bipiane/1e1218c99111d495e5467ce90078a24d to your computer and use it in GitHub Desktop.
Save bipiane/1e1218c99111d495e5467ce90078a24d to your computer and use it in GitHub Desktop.
kaviyo & segment
<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