import assert from "assert"; import { RawEvent, NormalizedEvent } from "../../types"; export default (event: RawEvent): NormalizedEvent<"mixpanel"> => { assert(event, `Mixpanel:event null event: ${event}`); assert( event.properties.distinct_id, `Mixpanel:event event is missing the required field properties.distinct_id ${event}` ); assert( event.properties.time, `Mixpanel:event event is missing the required field properties.time ${event}` ); // generate IDs the same way stitch does, except we don't have the message hash // meaning this event *might* drop events that actually happen // within the same second and have the same name and user and we kinda can't do anything about it const id = `mixpanel|${event.event}:${event.properties.time}:${event.properties.distinct_id}}`; return { id, ts: typeof event.properties.time === "number" ? event.properties.time : Date.parse(event.properties.time), user_info: { source_user_id: event.properties.distinct_id, user_id: null, name: null, email: null, title: null, birthday: null, company: { name: null, id: null, industry: null, employee_count: null, plan: null }, created_at: null, age: null, gender: null, website: null, ip: null, avatar: null, nickname: null, phone: null, city: event.properties["$city"] || null, country: event.properties["$region"] || null, postal_code: null, region: null, address_line1: null, continent_code: null, address_line2: null, country_code: event.properties.mp_country_code || null, timezone: null, user_agent: null, is_employee: null, custom_attributes: null }, text: event.event === "Loaded a Page" ? `Viewed ${event.properties.url || event.properties.title || "a page"}` : event.event, href: event.event === "Loaded a Page" ? event.properties.url : null, is_bad: false, direction: "inbound", source: "mixpanel", stream: "raw_data" }; };