This is a Jitsu.Classic documentation. For the lastest version, please visit docs.jitsu.com. Read about differences here.

πŸ“œ Configuration

Configuration UI

πŸ‘©β€πŸ”¬ Extending Jitsu

Overview
Destination Extensions
Source Extensions
API Specs

Jitsu Internals

Jitsu Server

Segment Integration

Jitsu supports collecting events from Segment without a need to touch your backend or frontend code. Just create a Segment integration function with the JS code below and connect it as a destination to your source on Segment. Integration functions are applied to all events from your landing pages, web applications or servers that are gone through Segment. All events will be additionally sent to Jitsu with.

Income events are mapped on JS SDK 2.0 structure automatically.

If you are using deprecated events API (events structure with eventn_ctx prefix) please use /api/v1/segment/compat endpoint.

Copy this javascript code into Segment integration function body:

async function send(event, settings) {
	let response;
	try {
	    //If you are using cloud.jitsu.com - put URL: https://t.jitsu.com/api/v1/segment
		response = await fetch('<JITSU_HOST_HERE>/api/v1/segment', {
			method: 'POST',
			headers: {
				'X-Auth-Token': '<JITSU_SERVER_API_KEY>',
				'Content-Type': 'application/json'
			},
			body: JSON.stringify({ ...event, ...settings })
		});
	} catch (error) {
		// Retry on connection error
		throw new RetryError(error.message);
	}

	if (response.status >= 500 || response.status === 429) {
		throw new RetryError(`Failed with ${response.status}`);
	}
}

async function onTrack(event, settings) {
	await send(event, settings);
}

async function onIdentify(event, settings) {
	await send(event, settings);
}

/**
 * Handle group event
 * @param  {SegmentGroupEvent} event
 * @param  {FunctionSettings} settings
 */
async function onGroup(event, settings) {
	await send(event, settings);
}

async function onPage(event, settings) {
	await send(event, settings);
}

async function onScreen(event, settings) {
	await send(event, settings);
}

async function onAlias(event, settings) {
	await send(event, settings);
}

async function onDelete(event, settings) {
	await send(event, settings);
}