<aside> 💡 We currently support segment by a custom function

</aside>

const splitbeeRequest = async (event, path, body, projectId) => {
	const res = await fetch(`https://hive.splitbee.io` + path, {
		method: 'POST',
		headers: {
			...(event.userId && { userId: event.userId }),
			...(event.anonymousId && { uid: event.anonymousId }),
			...(event.context.page && { origin: event.context.page.url }),
			...(projectId && { sbp: projectId }),
			...(event.context.userAgent && { 'user-agent': event.context.userAgent })
		},
		body: JSON.stringify({
			...body
		})
	});
};

async function onTrack(event, settings) {
	await splitbeeRequest(
		event,
		'/t',
		{
			event: event.event,
			data: event.properties
		},
		settings.projectId
	);
}

async function onIdentify(event, settings) {
	await splitbeeRequest(
		event,
		'/user',
		{
			...event.traits
		},
		settings.projectId
	);
}

/**
 * Handle group event
 * @param  {SegmentGroupEvent} event
 * @param  {FunctionSettings} settings
 */
async function onGroup(event, settings) {
	// Learn more at <https://segment.com/docs/connections/spec/group/>
	// console.log(event);
}

async function onPage(event, settings) {
	const location = new URL(event.context.page.url);
	const referrer =
		event.properties.referrer.indexOf(
			location.protocol + '//' + location.host
		) === 0
			? undefined
			: event.context.referrer;

	await splitbeeRequest(
		event,
		'/i',
		{
			origin: event.properties.url,
			...(referrer && { referrer })
		},
		settings.projectId
	);
}

/**
 * Handle screen event
 * @param  {SegmentScreenEvent} event
 * @param  {FunctionSettings} settings
 */
async function onScreen(event, settings) {
	// Learn more at <https://segment.com/docs/connections/spec/screen/>
  await splitbeeRequest(
		event,
		'/i',
		{
			page: event.name,
		},
		settings.projectId
	);
}

/**
 * Handle alias event
 * @param  {SegmentAliasEvent} event
 * @param  {FunctionSettings} settings
 */
async function onAlias(event, settings) {
	// Learn more at <https://segment.com/docs/connections/spec/alias/>
	console.log(event);
}

/**
 * Handle delete event
 * @param  {SegmentDeleteEvent} event
 * @param  {FunctionSettings} settings
 */
async function onDelete(event, settings) {
	// Learn more at <https://segment.com/docs/partners/spec/#delete>
	console.log(event);
}

Enable the destination

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/61c54cf7-f1fe-421b-82e7-3be9d1be062c/Untitled.png

You successfully added the Splitbee integration with Segment! 🎉