<aside> 💡 We currently support segment by a custom function
</aside>
To get started, go to Catalog in the sidebar

Click Functions in the top bar

Create new function and select Destination
A code editor comes up. Paste following content into it.
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);
}
Next, press on Settings in the right bar

Add a new setting with the label projectId . The type should be String
Press Configure, enter name Splitbee and press Create Function
Go to Catalog → Functions → Splitbee
Now press Connect Destination → Select your Source
Now enter your projectId which is the TOKEN of the Splitbee project settings.
Activate the destination by pressing the toggle

You successfully added the Splitbee integration with Segment! 🎉