Created
May 22, 2019 09:43
-
-
Save unity/7e28080d716cb66f3c3478f6bf2e75ff to your computer and use it in GitHub Desktop.
Capture Calendly Webhooks and track them as User Events
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
const { payload = {}, event: event_action = {} } = body; | |
const { event = {}, event_type = {}, invitee = {}, questions_and_answers, time } = payload; | |
const { name: event_name } = event_type; | |
const { email } = invitee; | |
const ident = { | |
email, | |
anonymous_id: email | |
} | |
let isTracked = false; | |
const actionName = event_action === "invitee.canceled" ? "canceled" : "booked"; | |
const eventName = `Demo ${actionName}` | |
const { | |
assigned_to = "none", | |
cancel_reason, | |
canceled, | |
canceled_at, | |
end_time, | |
start_time, | |
uuid, | |
location | |
} = event | |
const { | |
kind: type_kind, | |
name: type_name, | |
slug: type_slug, | |
uuid: type_uuid, | |
duration: type_duration_min | |
} = event_type | |
const properties = { | |
assigned_to, | |
cancel_reason, | |
canceled, | |
canceled_at: moment(canceled_at).toISOString(), | |
end_time_at: moment(end_time).toISOString(), | |
start_time_at: moment(start_time).toISOString(), | |
uuid, | |
location, | |
type_kind, | |
type_name, | |
type_slug, | |
type_uuid, | |
type_duration_min, | |
demo_email: email | |
} | |
hull | |
.user(userIdent) | |
.track(eventName, properties, { | |
created_at: moment(time).toISOString() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment