Learn to integrate Featurebase with Segment and the key features.
Written By Markus Palm
Last updated 15 days ago
Overview
The Featurebase ↔ Segment integration enables you to easily track all events (like new posts, comments, and votes) that your users make on your Public Portal.
Key features:
Track different events, page views, and user actions on your Featurebase Portal
Sync your users’ data from Segment to Featurebase for better feedback prioritization, automatic authentication, etc.
Example: If you already have your user data in Segment, you can sync it with their feedback in Featurebase to see their info (e.g. plan, company size, etc.) next to their posts.
You can also automatically authenticate them to Featurebase so they don’t have to create a separate account or log in.
Setting up the Segment integration
1. Install the Segment integration
Start in Segment by going to the connections tab, and click Add Source
Select Javascript and click next on the bottom right corner
Enter your website name (e.g. “yourcompany feedback portal”)
Add the website URL, which is your Featurebase Portal’s URL (e.g. https://yourcompany.featurebase.app/)
Click Create Source
Copy the text (Write key) in the analytics.load() function as seen below 👇
Go to Featurebase Settings → Integrations
Click set your API key, paste in your Segment write key, and click save
All done! 🎉 You can now see all the events made on your feedback portal appear under the Debugger in Segment.
2. Sync Segment userIDs to Featurebase
This part of the set up goes through the process of syncing your Segment userIDs into Featurebase to allow tracking your users better.
In Segment, go to Connections → Destinations, and click Add Destination
Select the Functions tab and click on Create Function
Pick Destination and click on Build on the bottom right
Delete all of the code inside the function and replace it with this:
Example/** * Map the incoming event traits to Featurebase identify fields. This let's you see the users data in the Users tab (dashboard) and on each post they create. * If you do not wish to send along this data, add a "return null;" to the beginning of it. * This function is intended to be customized by you based on your specific event.traits structure. * You should map their traits to the corresponding fields in the featurebaseIdentify object. * * You are advised to modify this function to suit your needs. If your traits object has different field names, adjust the return object accordingly. * * Feel free to remove any optional fields if you do not have them in your incoming data. * * @param {Object} event - The event object from the incoming request * @return {Object | null} - The mapped featurebaseIdentify object, or null if mandatory fields are not present in the traits */ function mapFeaturebaseIdentify(event) { /** * Example `featurebaseIdentify` object: * * let featurebaseIdentify = { * "email": "youruser@example.com", // User's email address (required) * "name": "John Steezy", // User's name (required) * "id": "123456789", // User's ID (required) * "profilePicture": "https://example.com/profile.jpg", // URL to the user's profile picture (optional) * "createdAt": "2023-05-19T15:35:49.915Z", // Date and time when the user was created (optional) * "customFields": { // Additional information about the user. Key-value pairs of type 'string' allowed. (optional) * "title": "Product Manager", * "plan": "Premium" * }, * "companies": [ // List of companies associated with the user (optional) * { * "id": "987654321", // Company's ID (required) * "name": "Business Inc.", // Company's name (required) * "monthlySpend": 500, // Company's monthly spend (optional) * "createdAt": "2023-05-19T15:35:49.915Z", // Date and time when the company was created (optional) * "customFields": { // Additional information about the company. Key-value pairs of type 'string' allowed. (optional) * "location": "Canada", * "language": "French" * } * } * ] * } */ /* This is the part you need to customize */ let featurebaseIdentify = { name: event.traits.name, email: event.traits.email, id: event.userId, profilePicture: event.traits.profilePicture || null, createdAt: event.traits.createdAt || null, customFields: event.traits.customFields || {}, companies: event.traits.companies || [] }; let mandatoryFields = ['name', 'email', 'id']; let isValid = mandatoryFields.every(field => featurebaseIdentify[field]); if (!isValid) { console.error( 'You did not provide all the mandatory fields. Please provide id, name and email to identify your users in Featurebase. Skipping identification.' ); } // Return the featurebaseIdentify object if all mandatory fields are present, else return null return isValid ? featurebaseIdentify : null; } /** * Handle identify event for Featurebase. * * !!! IMPORTANT !!! * Make sure to replace YOURORGNAME with your own organizations name. * * @param {SegmentIdentifyEvent} event * @param {FunctionSettings} settings */ async function onIdentify(event, settings) { const endpoint = 'https://YOURORGNAME.featurebase.app/api/v1/webhook/segment/identify'; let response; // Map event traits to featurebaseIdentify event.featurebaseIdentify = mapFeaturebaseIdentify(event); try { response = await fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(event) }); } 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}`); } }
Change both
mapFeaturebaseIdentify
andonIdentify
functions
(It is VERY IMPORTANT that you modify both mapFeaturebaseIdentify and onIdentify in the code. It will not work otherwise. Please read the comments above each of the functions to better understand what is needed from you.
By properly customizingmapFeaturebaseIdentify
, you get access to their data in the Users tab in the dashboard and on each post they create. If you do not wish to send along this information, add areturn null;
to the beginning ofmapFeaturebaseIdentify
function.)Once you've pasted the code, modified or disabled the
mapFeaturebaseIdentify
function and replaced YOURORGNAME inonIdentify
, click on ConfigureEnter a name for the destination (e.g. Featurebase) and click on Create Function
To connect the destination to something, click on Connect Destination
Select a source and click Next
Add a destination name and click Save
You've now successfully started syncing your segment userIDs into Featurebase.
And that's it! 🎉 If you have any ideas about how we can improve the Segment integration, please post on our feedback board.