Skip to main content
RapidDev - Software Development Agency
flutterflow-integrationsCustom Action (Dart)

Segment

Connect FlutterFlow to Segment using a Custom Action that wraps the official `analytics_flutter` SDK — initialize it with your Segment source write key, then call `track()` and `identify()` from Action Flows. The write key is client-side by design (publishable, not secret). Once events flow into Segment, enable your destinations (Google Analytics, Amplitude, Mixpanel) in the Segment dashboard — no extra SDKs needed in FlutterFlow.

What you'll learn

  • How to wrap the `analytics_flutter` Segment SDK in a FlutterFlow Custom Action
  • Why a Segment write key is safe in client code (unlike API secrets) and how it differs from the Public API token
  • How to call `track()` and `identify()` from FlutterFlow Action Flows for events and user identification
  • Why you should NOT install destination SDKs (GA, Amplitude) in FlutterFlow alongside Segment — it causes double counting
  • How to use the Segment HTTP Tracking API as a fallback for FlutterFlow web builds
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Intermediate17 min read30 minutesAnalyticsLast updated July 2026RapidDev Engineering Team
TL;DR

Connect FlutterFlow to Segment using a Custom Action that wraps the official `analytics_flutter` SDK — initialize it with your Segment source write key, then call `track()` and `identify()` from Action Flows. The write key is client-side by design (publishable, not secret). Once events flow into Segment, enable your destinations (Google Analytics, Amplitude, Mixpanel) in the Segment dashboard — no extra SDKs needed in FlutterFlow.

Quick facts about this guide
FactValue
ToolSegment
CategoryAnalytics
MethodCustom Action (Dart)
DifficultyIntermediate
Time required30 minutes
Last updatedJuly 2026

Capture Once, Route Everywhere: Segment Is the CDP Layer for FlutterFlow

Segment solves a specific problem that founders hit after their app grows: they start with Google Analytics, then add Mixpanel for funnels, then add Amplitude for retention — and now they have three different SDKs, three separate tracking implementations, and inevitably three sources of truth with slightly different numbers. Segment's answer is the Customer Data Platform model: capture your events once, let Segment route them to every destination.

For a FlutterFlow app, the integration point is the `analytics_flutter` package — Segment's official Flutter SDK. You wrap it in a Custom Action that initializes the SDK with your Segment source write key at app startup, then expose individual actions for `track()`, `identify()`, `screen()`, and `group()` calls. Those calls feed into Segment, and everything downstream (GA4, Amplitude, Mixpanel, BigQuery, Salesforce) is configured in Segment's dashboard — no code changes to your FlutterFlow app.

The write key deserves a moment of clarity: Segment source write keys are explicitly designed to be embedded in client-side code. They are publishable keys, not secrets. Segment's write key lets code send events to your Segment source — it does not grant access to read data, manage destinations, or access your workspace. This is different from the Segment Public API token (used for workspace management), which must stay server-side. So unlike Honeycomb's ingest key or Stripe's secret key, the Segment write key in a Custom Action is the correct and intended pattern.

Segment's free tier covers up to 1,000 monthly tracked users — check their current pricing as plans change. Paid Team plans unlock more destinations and higher volumes. Note that the Custom Action pattern runs on mobile device builds; for FlutterFlow web builds, use the HTTP Tracking API path described in Step 4.

Integration method

Custom Action (Dart)

FlutterFlow integrates with Segment through a Custom Action wrapping the `analytics_flutter` pub.dev package — Segment's official Flutter SDK. The Custom Action initializes the SDK with your source write key and exposes `track()`, `identify()`, and `group()` calls you can invoke from Action Flows. The write key is client-side publishable (unlike an API secret), so it's safe in a Custom Action. Once events flow into Segment, you configure destinations (GA4, Amplitude, Mixpanel, data warehouses) entirely in the Segment dashboard — without adding any extra SDKs to FlutterFlow.

Prerequisites

  • A Segment account with a source created — go to app.segment.com → Sources → Add Source → Select 'Android' (for mobile) or 'HTTP API' (for testing)
  • Your Segment source write key — found in the Source Settings → API Keys section after creating the source
  • A FlutterFlow project open and ready to add Custom Code
  • Basic understanding of which events you want to track (event names, properties) before writing Custom Actions
  • An understanding that the Custom Action method is for mobile device builds; web builds use the HTTP Tracking API instead

Step-by-step guide

1

Create a Segment Source and Copy the Write Key

Log in to your Segment workspace at app.segment.com. In the left sidebar, click 'Sources' then 'Add Source'. For a FlutterFlow mobile app, select 'Android' or 'iOS' as your source type — these correspond to the mobile SDK events you'll be sending. If you're building both iOS and Android from FlutterFlow (which you are, since FlutterFlow compiles to both), you can create one source for each platform or use a single source and differentiate by sending a `platform` property with each event. Alternatively, select 'HTTP API' as the source type, which accepts events from the Tracking API directly and works for both the Custom Action SDK path and the web Tracking API fallback. After creating the source, click into it and go to Settings → API Keys. Copy the 'Write Key'. This is the value you'll use in your Custom Action to initialize the Segment SDK. Important distinction: the write key is a source-specific publishable key — it lets code send events to this particular Segment source. It does NOT grant access to your Segment workspace settings, destinations, or other sources. This is why it's safe to use in client code. Keep it separate from the Segment Public API Bearer Token (used for workspace management via the Config API), which is a secret and must never appear in FlutterFlow. For destinations: don't enable them yet — you'll come back to this after verifying events flow correctly in Step 3. Premature destination configuration before the event flow is verified makes debugging harder.

Pro tip: Create a separate Segment source for development and production — for example, 'FlutterFlow Dev' and 'FlutterFlow Prod'. This prevents test events from polluting your analytics destinations during development.

Expected result: You have a Segment source with a write key copied, ready to paste into the Custom Action. In the Segment UI, the source shows as 'Awaiting Data' until the first event arrives.

2

Build the Segment Custom Action in FlutterFlow

In your FlutterFlow project, go to the left nav and click 'Custom Code' (the code bracket icon). Click '+ Add' and select 'Action'. Name it 'InitializeSegment'. In the Dependencies field, add `analytics_flutter: ^2.0.0` — check pub.dev for the latest stable version of the `analytics_flutter` package before pinning a version. FlutterFlow will add this to your project's pubspec.yaml automatically. Set no return type for the init action (it initializes the SDK globally). Add one argument named 'writeKey' of type String. Paste the initialization Dart code from the code block. This action should be called once at app startup: add it to the On Initialization Action of your initial page or a splash screen. Next, create a second Custom Action named 'SegmentTrack'. Add arguments: `eventName` (String), `properties` (JSON/Map). This action calls `analytics.track(TrackEvent(event: eventName, properties: properties))` using the Analytics singleton. Repeat for 'SegmentIdentify' with arguments `userId` (String) and `traits` (JSON/Map). To use these Custom Actions: in the Action Flow Editor for any widget, click '+ Add Action' → select 'Custom Actions' → select 'SegmentTrack' → fill in the event name (e.g., 'Product Viewed') and the properties JSON object (build it with FlutterFlow's JSON builder from your widget state values). Remember: Custom Actions do not run in FlutterFlow's web Run mode preview. The browser preview doesn't support the compiled Dart environment that the analytics SDK needs. Test exclusively on a real device via Test Mode. To confirm events arrive, open Segment's Debugger tab on your source — events appear in real time as they're sent from your device.

custom_action.dart
1// FlutterFlow Custom Action: InitializeSegment
2// Dependencies: analytics_flutter: ^2.0.0
3// Arguments: writeKey (String)
4// Return type: void
5import 'package:analytics_flutter/analytics_flutter.dart';
6import 'package:analytics_flutter/state.dart';
7
8Final _analytics = Analytics.with(Configuration(writeKey));
9
10// Note: In production, use a singleton pattern to avoid re-initializing.
11// Store the Analytics instance in a global variable or use the Analytics.with
12// factory which handles this internally.
13
14Future<void> initializeSegment(String writeKey) async {
15 final configuration = Configuration(writeKey)
16 ..trackApplicationLifecycleEvents = true
17 ..debug = false; // Set to true during development
18
19 await Analytics.setup(configuration);
20}
21
22// =====================================================
23// FlutterFlow Custom Action: SegmentTrack
24// Arguments: eventName (String), properties (dynamic)
25// Return type: void
26import 'package:analytics_flutter/analytics_flutter.dart';
27import 'package:analytics_flutter/event.dart';
28
29Future<void> segmentTrack(
30 String eventName,
31 dynamic properties,
32) async {
33 final analytics = Analytics.shared();
34 if (analytics == null) {
35 debugPrint('Segment not initialized. Call initializeSegment first.');
36 return;
37 }
38
39 final props = properties is Map<String, dynamic>
40 ? properties
41 : <String, dynamic>{};
42
43 await analytics.track(TrackEvent(
44 event: eventName,
45 properties: props,
46 ));
47}
48
49// =====================================================
50// FlutterFlow Custom Action: SegmentIdentify
51// Arguments: userId (String), traits (dynamic)
52// Return type: void
53Future<void> segmentIdentify(
54 String userId,
55 dynamic traits,
56) async {
57 final analytics = Analytics.shared();
58 if (analytics == null) return;
59
60 final traitMap = traits is Map<String, dynamic>
61 ? traits
62 : <String, dynamic>{};
63
64 await analytics.identify(IdentifyEvent(
65 userId: userId,
66 traits: Traits.fromMap(traitMap),
67 ));
68}

Pro tip: Always call InitializeSegment first — add it to your splash screen or first page's On Page Load action. If SegmentTrack is called before initialization, it will silently drop the event.

Expected result: The Custom Actions appear in the FlutterFlow Action Flow Editor under 'Custom Actions'. On a real device Test Mode build, triggering an action sends an event visible in Segment's Source Debugger within seconds.

3

Verify Events in Segment Debugger and Enable Destinations

Before enabling any destinations, confirm that events are flowing correctly from your FlutterFlow app to Segment. Install a Test Mode build on a real device. Open Segment in your browser → your source → 'Debugger' tab. Trigger some actions in your app (tap a button that calls SegmentTrack, or navigate to a screen that calls SegmentTrack on page load). Within a few seconds, you should see the events appear in the Debugger with their event names and properties. In the Debugger, click on an event to inspect its full payload. Verify that: - The event name is correct (exactly matches what you want in your downstream tools) - All properties you passed are present and have the right values - The `context.os.name` and `context.library` fields show the device platform and SDK version Once events are flowing and look correct in the Debugger, go to your source → 'Destinations' → 'Add Destination'. Search for the tools you want to send data to (Google Analytics 4, Mixpanel, Amplitude, etc.). Segment will prompt you for destination-specific configuration — for GA4, this means your Measurement ID; for Mixpanel, your project token. Follow each destination's setup wizard. Critical warning: do NOT also install the GA4 Firebase Analytics toggle (Settings & Integrations → Firebase → Google Analytics) alongside Segment. If both Segment's GA4 destination and FlutterFlow's native Firebase Analytics are active, every event gets counted twice in GA4 — once from Segment's server-side delivery and once from the native SDK on the device. Pick one path. If you want Segment as the source of truth for GA4, disable FlutterFlow's native Firebase Analytics toggle. This double-counting pitfall extends to all destinations: if you use Segment for Mixpanel, remove any direct Mixpanel SDK you might have added. Segment's job is to be the one place you instrument.

Pro tip: Use Segment's 'Schema' tab on your source to see a compiled list of all event names and properties that have been sent. This is useful for auditing your tracking plan and catching event names that drifted (e.g., 'ButtonClick' in some places and 'button_click' in others).

Expected result: Events appear in Segment's Source Debugger in real time when triggered from a Test Mode device build. After enabling destinations, events begin appearing in your downstream tools (GA4, Mixpanel, etc.) with a small propagation delay per destination.

4

(Web Builds) Use the HTTP Tracking API Instead of the Custom Action SDK

The `analytics_flutter` Custom Action is device-only — it uses compiled Dart code that does not run in FlutterFlow's web environment. If your FlutterFlow app is a web build (or you want analytics on both mobile and web), you need the Segment HTTP Tracking API as an alternative or complement. The HTTP Tracking API is a REST endpoint at `https://api.segment.io/v1/track` (and `/v1/identify`, `/v1/page`, `/v1/batch`). It accepts the same event format as the SDK but over plain HTTP. Authentication uses HTTP Basic Auth with your write key as the username and no password. In FlutterFlow, create an API Group named 'SegmentHTTP' with base URL `https://api.segment.io`. For authentication, select 'Basic Auth' → enter your write key as the username and leave the password empty. Add API Calls for 'Track' (POST `/v1/track`), 'Identify' (POST `/v1/identify`), and optionally 'Batch' (POST `/v1/batch`). Each call body takes a JSON object with the required Segment fields. The Track body needs at minimum: `type`, `event`, and `userId` or `anonymousId`. Note on write key in Basic Auth: unlike a secret key, the Segment write key in an API Group header is acceptable (it's the same key used in the mobile SDK). However, if you want to be extra cautious, you can route these calls through a Cloud Function. For the write key — a publishable, send-only key — the direct API Call pattern is widely used and is the approach Segment's own documentation recommends for client-side HTTP tracking. For mobile + web apps: use the Custom Action SDK for native device builds (better performance, offline queuing, automatic context metadata) and the HTTP API Call for web builds. You can detect the platform using a FlutterFlow Conditional Action (Platform == Web → use API Call, otherwise → use Custom Action).

api_call_body.json
1// Segment HTTP Tracking API — Track event
2// FlutterFlow API Call body (POST /v1/track)
3// Content-Type: application/json
4// Auth: Basic (writeKey as username, password empty)
5{
6 "type": "track",
7 "event": "{{eventName}}",
8 "userId": "{{userId}}",
9 "anonymousId": "{{anonymousId}}",
10 "properties": {
11 "category": "{{category}}",
12 "label": "{{label}}",
13 "value": "{{value}}"
14 },
15 "context": {
16 "library": {
17 "name": "FlutterFlow HTTP",
18 "version": "1.0.0"
19 }
20 },
21 "timestamp": "{{timestamp}}"
22}
23
24// Segment HTTP Tracking API — Identify user
25// FlutterFlow API Call body (POST /v1/identify)
26{
27 "type": "identify",
28 "userId": "{{userId}}",
29 "traits": {
30 "email": "{{email}}",
31 "name": "{{name}}",
32 "plan": "{{plan}}"
33 },
34 "timestamp": "{{timestamp}}"
35}

Pro tip: RapidDev's team builds FlutterFlow integrations like this every week, including Segment setups for both mobile and web — free scoping call at rapidevelopers.com/contact.

Expected result: Web builds of your FlutterFlow app successfully send track and identify events to Segment via the HTTP API Call, visible in the Segment Source Debugger alongside mobile events from the Custom Action SDK path.

Common use cases

Multi-channel analytics setup that feeds GA4, Mixpanel, and BigQuery from one event stream

A FlutterFlow e-commerce app uses Segment to capture all user events once (page views, product taps, purchases) and fan them out to Google Analytics 4 for ad attribution, Mixpanel for funnel analysis, and BigQuery for long-term data warehouse storage — all configured in Segment's dashboard without any additional SDKs in FlutterFlow. When the team wants to add a new analytics tool, they enable a new destination in Segment instead of touching app code.

FlutterFlow Prompt

Set up Segment tracking in our FlutterFlow app so every product view, add-to-cart, and purchase event flows to both Google Analytics and Mixpanel automatically through Segment.

Copy this prompt to try it in FlutterFlow

User identification pipeline that syncs FlutterFlow app users to a CRM and email platform

When a user signs up or logs in to a FlutterFlow app, a Segment `identify()` call captures their user ID, name, email, and plan tier. Segment routes this profile data to HubSpot (CRM), Klaviyo (email), and Amplitude (product analytics) in real time. The sales team sees new signups in HubSpot automatically; Klaviyo triggers a welcome email sequence — all from a single `identify()` call in the FlutterFlow Action Flow.

FlutterFlow Prompt

When a user completes signup, call Segment identify() with their user ID, email, full name, and plan type, and route that data to HubSpot and Klaviyo via Segment destinations.

Copy this prompt to try it in FlutterFlow

A/B test event tracking where Segment routes events to an experimentation platform

A FlutterFlow app running an A/B test on its onboarding flow uses Segment to track which variant each user saw and their subsequent conversion events. Segment routes these events to Optimizely or LaunchDarkly's analytics destination, giving the growth team a clean record of experiment exposure and outcome — without instrumenting a separate experiment tracking SDK in FlutterFlow.

FlutterFlow Prompt

Track which onboarding variant (A or B) each new user sees, send the variant assignment as a Segment track event with the experiment name and variant as properties, and route it to our analytics destination.

Copy this prompt to try it in FlutterFlow

Troubleshooting

Events are being counted twice in Google Analytics 4 or Mixpanel after adding Segment

Cause: Both Segment's destination for the tool and FlutterFlow's native SDK for the same tool are active simultaneously. For GA4, this means the Firebase Analytics native toggle AND Segment's GA4 destination are both sending the same events to GA4 — from the device (native SDK) and from Segment's servers.

Solution: Disable the duplicate native SDK in FlutterFlow. If using Segment for GA4, go to Settings & Integrations → Firebase → disable the Google Analytics toggle. If using Segment for Mixpanel, remove any direct Mixpanel Custom Action. Segment's value is that it replaces all destination SDKs — not supplements them.

Custom Action events don't appear in Segment Debugger after being triggered in the app

Cause: Either the Custom Action is being tested from FlutterFlow's web Run preview (Custom Actions don't run there), or InitializeSegment was not called before SegmentTrack, or the write key in the Custom Action is incorrect.

Solution: Test exclusively on a real device using Test Mode (not web Run preview). Confirm InitializeSegment is called on app startup before any track/identify calls — add it to the splash screen or first page's On Page Load. Double-check the write key by comparing it to the API Keys section in your Segment source settings. Add a `debugPrint` to the Custom Action to confirm it's being invoked.

iOS builds fail with 'Missing platform-specific implementation' or ATT-related analytics gaps

Cause: iOS 14.5+ requires App Tracking Transparency (ATT) permission for certain types of tracking, particularly advertising-related. Additionally, some Segment destination SDKs bundled by Segment require Info.plist entries that FlutterFlow's default build doesn't include.

Solution: For ATT consent: add the NSUserTrackingUsageDescription key to your iOS Info.plist via FlutterFlow's iOS settings if any of your Segment destinations use advertising identifiers. For platform-specific destination SDK issues, check Segment's documentation for your specific destination — some destinations require additional native configuration that may need a custom build step.

HTTP Tracking API call returns 400 Bad Request from the Segment /v1/track endpoint

Cause: The request body is missing a required field. Segment's Tracking API requires either `userId` or `anonymousId` on every event. If both are missing or empty strings, the API rejects the request.

Solution: Ensure every API Call body includes either `userId` (a string identifying the logged-in user) or `anonymousId` (a randomly generated UUID for anonymous users). In FlutterFlow, generate an anonymous ID on first app launch and store it in App State: create a String app state variable 'anonymousId', set it to a UUID on first launch (using a Custom Function with `const Uuid().v4()`), and bind it to the API Call body variable.

typescript
1// Custom Function: generateAnonymousId
2// Return type: String
3import 'package:uuid/uuid.dart';
4
5String generateAnonymousId() {
6 return const Uuid().v4();
7}

Best practices

  • Use the `analytics_flutter` Custom Action SDK for mobile device builds and the HTTP Tracking API for web builds — they send identical data to Segment but are better suited to their respective environments.
  • Never install destination SDKs (Firebase Analytics, Mixpanel SDK, Amplitude SDK) in FlutterFlow alongside Segment — pick one routing strategy and stick to it to avoid double-counting events.
  • Call InitializeSegment once at app startup (on your splash or first page load) before any track/identify calls — events sent before initialization are silently dropped.
  • Use consistent event naming conventions (snake_case recommended: `product_viewed`, `checkout_completed`) across all screens so Segment's schema stays clean and destinations receive consistent field names.
  • Call `identify()` with the user's ID as soon as they log in, and `reset()` when they log out — this ensures event streams are correctly attributed to the right user profiles in downstream destinations.
  • Test new events in the Segment Debugger on a real device before enabling destinations — catch event name or property mistakes early so your analytics destinations don't receive inconsistent data.
  • Avoid tracking personally identifiable information (email, phone, name) as event properties — put PII in `identify()` traits where it's mapped to a user profile, not in track event properties that flow into data warehouses without proper access controls.

Alternatives

Frequently asked questions

Is it safe to put my Segment write key in a Custom Action or API Call?

Yes — the Segment source write key is explicitly a client-side publishable key. It's the same key that Segment puts in their browser JavaScript snippet for websites and in their mobile SDKs for apps. A write key lets code send events to a specific Segment source, but it does not grant access to read data, modify destinations, or manage your workspace. Keep the Segment Public API Bearer Token (used for workspace management) server-side, but the write key in a Custom Action is the correct and intended pattern.

Can I install the Google Analytics Firebase toggle AND use Segment's GA4 destination at the same time?

No — do not run both simultaneously. If FlutterFlow's native Firebase Analytics toggle is enabled and Segment's GA4 destination is also active, every event will be sent to GA4 twice: once from the Firebase Analytics SDK on the device, and once from Segment's server-side delivery to GA4. This causes all your metrics (sessions, events, conversions) to be exactly double what they should be. Pick one path: either the native Firebase toggle for direct GA4 tracking, or Segment's destination.

Why don't my Segment Custom Action events show up when I test in FlutterFlow's web preview?

The `analytics_flutter` Custom Action uses compiled Dart code running on the device, which is not available in FlutterFlow's browser-based Run mode preview. Custom Actions are only executed in Test Mode builds installed on real iOS or Android devices. This is expected behavior — use FlutterFlow's Test Mode, install the build on your phone, and check the Segment Source Debugger for incoming events.

How does Segment route events to destinations like Google Analytics or Mixpanel?

Segment receives your events via the SDK or HTTP API and stores them in your source. From there, Segment's pipeline delivers each event to your enabled destinations based on the rules you configure. For GA4, Segment maps your event names and properties to GA4 event format and sends them server-side via the GA4 Measurement Protocol. You configure which events go to which destinations, and whether any event transformations or filters apply — all in the Segment web UI, with no code changes in FlutterFlow.

What is the difference between Segment's write key and the Segment Public API token?

The write key is source-specific and client-safe: it lets your app send events to a particular Segment source. It does not grant any management access. The Public API Bearer Token (or Access Token) is a workspace-level credential used to manage sources, destinations, and workspace configuration via the Segment Config API. The Public API token is a secret and must never appear in FlutterFlow code. The write key is the one you use in Custom Actions and API Calls.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Integrations are where projects stall

We wire FlutterFlow integrations like this one every week — auth, webhooks, edge cases included. Fixed-price builds from $13K, delivered in 6–10 weeks.

Talk to an integration engineer

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.