Birdeye Segment Setup
M
Written by Matt Panton
Updated over a week ago

Have the customer go to Segment.com and create an account. Click this link to be taken to the signup page: https://segment.com/signup

1 - Once you get access to their new Segment account, under Sources choose Add Source:

AddSource.png

2 - Select Javascript for the source type

Javascript.png

3 - Name the source "SMRT" leaving the other fields blank. Then Add Source.

NameSource.png

4 - Retrieve the Write API key to send to [email protected] by selecting your new source and navigating to Settings -> API Keys -> Write Key:

WriteKey.png

5 - Send Write Key to [email protected] along with Birdeye Location ID for each location.

6 - Birdeye Destination Setup. Sign in to your segment workspace at https://app.segment.com/ , and go to connections -> catalog -> functions -> new function as shown in below screenshot:

step_3.png

7 - Select function type "Destination" and press "Build" in the bottom right:

step_4.png

8 - Paste the code at the bottom of this guide under Integration Code, into the source code editor on the left side of the screen as shown in the screenshot below.

step_5.png

9 - Replace the text INSERT_API_KEY with your Birdeye API key. Please see the Prerequisites section for how to get the API key from Birdeye. Then press configure.

10 - Name the function Birdeye Customer Visit and press Create Function:

step_6.png

11 - After creating the function, a popup should appear on the right side of the screen showing a button Connect Destination that you should press. You can get back to this screen at a later time, by going to Connections => Catalog => Functions => Birdeye Customer Visit.

step_7.png

12 - Select the SMRT source that you already setup (see the Prerequisites section above), and press confirm source.

step_8.png

13 - On the next screen, flip the toggle to enable the integration. This activates the integration

step_9.png

Monitoring Integration

In segment, you can go to the delivery tab under the function, to monitor the integration. Please note that event delivery from SMRT is delayed by 10-20 minutes, and only triggers on store pickup or delivery, and not on new orders.

step_10.png

In Birdeye, you can also monitor the integration by going to the "Contacts" page. Any contacts with recent order returns, should be listed at the top (the page is sorted by last activity). If you hover a contact and press actions => contact journey, you should see the API at work like so:

Screenshot_2020-12-17_at_10.01.04.png

Integration Code

//Replace INSERT_API_KEY below with your Birdeye API key.
const apiKey = 'INSERT_API_KEY';async function onTrack(event, settings) {
	if (event.event !== 'Customer Visit') {
		return;
	}	if (
		!event.properties.homeStore ||
		!event.properties.homeStore.externalStoreIdentifier ||
		!event.properties.orderWasReturned
	) {
		return;
	}	const externalStoreIdentifier =
		event.properties.homeStore.externalStoreIdentifier;
	const endpoint = `https://api.birdeye.com/resources/v1/customer/checkin?api_key=${apiKey}&bid=${externalStoreIdentifier}`;
	let response;	const traits = event.context.traits;
	let name = '';	function isSet(val) {
		return !!val && val != '';
	}	if (isSet(traits.firstName) && isSet(traits.lastName)) {
		name = `${traits.firstName} ${traits.lastName}`;
	} else if (isSet(traits.firstName)) {
		name = traits.firstName;
	} else if (isSet(traits.lastName)) {
		name = traits.lastName;
	}	const payload = {
		name,
		phone: traits.phone,
		emailId: traits.email,
		smsEnabled: traits.receiveTexts ? 1 : 0,
		employees: [
			{
				emailId: event.properties.staff.staffEmail,
				firstName: event.properties.staff.staffFirstName,
				lastName: event.properties.staff.staffLastName
			}
		],
		additionalParams: {
			customerAgent: traits.agent,
			locationType: event.properties.locationType
		}
	};	try {
		response = await fetch(endpoint, {
			method: 'POST',
			headers: {
				Authorization: `Basic ${btoa(settings.apiKey + ':')}`,
				'Content-Type': 'application/json'
			},
			body: JSON.stringify(payload)
		});
	} catch (error) {
		// Retry on connection error
		throw new RetryError(error.message);
	}	if (response.status >= 500 || response.status === 429) {
		// Retry on 5xx (server errors) and 429s (rate limits)
		throw new RetryError(`Failed with ${response.status}`);
	}
}
Did this answer your question?