Skip to main content
Automation

Segment Integration

Learn to integrate Featurebase with Segment and the key features.

Written By Markus Palm

Last updated 1 day ago

Segment x Featurebase integration.

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, 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.


Setting up the Segment integration

1

Install the Segment integration

  1. Start in Segment by going to the connections tab, and click Add Source

  2. Select Javascript and click next on the bottom right corner

  3. Enter your website name (e.g. “yourcompany feedback portal”)

  4. Add the website URL, which is your Featurebase Portal’s URL (e.g. https://yourcompany.featurebase.app/)

  5. Click Create Source

  6. Copy the text (Write key) in the analytics.load() function as seen below 👇

  7. Go to Featurebase Settings → Integrations

  8. Click Configure on Segment, paste your Segment write key under Send events to Segment, 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 users from Segment to Featurebase

A Segment destination function sends each identify call to Featurebase with your Segment key. Featurebase saves the person with their name, email, custom fields and company. This needs the Growth plan or higher.

  1. In Featurebase Settings → Integrations, click Configure on Segment, then Create key under Sync users from Segment. Copy the key: it is shown only once.

  2. In Segment, go to Connections → Catalog, open the Functions tab and click New Function

  3. Select Destination and click Next: Build Function

  4. Replace all of the code with this, and change YOURORG to your Featurebase subdomain:

    // Sync Segment identify calls to Featurebase.
    // Replace YOURORG with your Featurebase subdomain (YOURORG.featurebase.app).
    const ENDPOINT = 'https://YOURORG.featurebase.app/api/v1/webhook/segment/identify';
    
    // Map your Segment traits to Featurebase. Change the trait names to match yours.
    function toFeaturebase(event) {
      const traits = event.traits || {};
      const firstName = traits.firstName || traits.first_name;
      const lastName = traits.lastName || traits.last_name;
      const avatar = traits.avatar || traits.profilePicture;
      const company = traits.company;
      return {
        userId: event.userId,
        email: traits.email,
        name: traits.name || [firstName, lastName].filter(Boolean).join(' ') || undefined,
        profilePicture: /^https?:\/\//.test(avatar || '') ? avatar : undefined,
        createdAt: traits.createdAt || traits.created_at,
        // Each key must match a user attribute in Featurebase (Settings → Data → Users).
        customFields: { plan: traits.plan },
        companies: company && company.id && company.name ? [{ id: String(company.id), name: company.name }] : undefined,
      };
    }
    
    async function onIdentify(event, settings) {
      const key = (settings.featurebaseKey || '').trim();
      if (!key) throw new ValidationError('Add your Featurebase key in the destination settings.');
      if (!event.userId) throw new EventNotSupported('Featurebase needs a userId.');
    
      let response;
      try {
        response = await fetch(ENDPOINT, {
          method: 'POST',
          headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
          body: JSON.stringify({ userId: event.userId, featurebaseIdentify: toFeaturebase(event) }),
        });
      } catch (error) {
        throw new RetryError(error.message);
      }
      if (response.status >= 500 || response.status === 429) throw new RetryError(`Featurebase answered ${response.status}`);
      if (!response.ok) throw new ValidationError(`Featurebase answered ${response.status}: ${await response.text()}`);
    }
  5. In the Settings tab, click Add Setting: label featurebaseKey, type String, with Required and Secret on

  6. Click Configure, enter a name (e.g. Featurebase) and click Create Function

  7. Click Connect Destination and select a server-side source, such as your backend

  8. In the destination settings, paste your Featurebase key into featurebaseKey, click Save and turn the destination on

Use a server-side source. Visitors can change the data a website source sends.

A custom field is saved when a user attribute with the same name exists in Settings → Data → Users.

If your workspace uses identity verification, Segment updates people who already exist in Featurebase. New people are added when they sign in.

This syncs users. To send product events, use the Events API.


And that's it! 🎉 If you have any ideas about how we can improve the Segment integration, please post on our feedback board.