LogoLogo
  • Contributing to RudderStack
  • Destination_Name
  • LICENSE
  • RudderStack Docs
  • docs
    • FAQ
    • Identity Resolution
    • Home
    • cloud-extract-sources
      • ActiveCampaign Source
      • Bing Ads
      • Chargebee
      • Common Settings
      • Facebook Ads
      • Freshdesk
      • Google Ads Source
      • Google Analytics
      • Google Search Console
      • Google Sheets
      • Cloud Extract Sources
      • Intercom v2
      • Intercom
      • Mailchimp
      • Marketo
      • Mixpanel
      • NetSuite
      • Pipedrive
      • QuickBooks
      • Salesforce Pardot
      • Sendgrid Source
      • Stripe Source
      • Xero
      • Zendesk Chat
      • Zendesk
      • hubspot
        • HubSpot Data Model and Schema Information
        • HubSpot
      • salesforce
        • Salesforce
        • Schema Comparison: RudderStack vs. Segment
    • connections
      • Connection Modes: Cloud Mode vs. Device Mode
    • data-governance
      • Data Governance
      • RudderTyper
      • Data Governance API
      • RudderTyper
      • tracking-plans
        • Tracking Plans
        • Tracking Plan Spreadsheet
    • data-warehouse-integrations
      • Amazon Redshift
      • Azure Data Lake
      • Azure Synapse
      • ClickHouse
      • Databricks Delta Lake
      • Google Cloud Storage Data Lake
      • Google BigQuery
      • Identity Resolution
      • Warehouse Destinations
      • Microsoft SQL Server
      • PostgreSQL
      • Amazon S3 Data Lake
      • Snowflake
      • FAQ
      • Warehouse Schema
    • destinations
      • Destinations
      • Webhooks
      • advertising
        • Bing Ads
        • Criteo
        • DCM Floodlight
        • Facebook App Events
        • Facebook Custom Audience
        • Facebook Pixel
        • Google Ads (gtag.js)
        • Google AdWords Enhanced Conversions
        • Google Adwords Remarketing Lists (Customer Match)
        • Advertising
        • LinkedIn Insight Tag
        • Lotame
        • Pinterest Tag
        • Reddit Pixel
        • Snap Pixel
        • TikTok Ads
      • analytics
        • Amplitude
        • AWS Personalize
        • Chartbeat
        • Firebase
        • FullStory
        • Google Analytics 360
        • Google Analytics
        • Heap.io
        • Hotjar
        • Analytics
        • Indicative
        • Keen
        • Kissmetrics
        • Kubit
        • Lytics
        • Mixpanel
        • Pendo
        • PostHog
        • Quantum Metric
        • Singular
        • adobe-analytics
          • Adobe Analytics Heartbeat Measurement
          • Mobile Device Mode Settings
          • Web Device Mode Settings
          • E-commerce Events
          • Adobe Analytics
          • Setting Up Adobe Analytics in RudderStack
        • google-analytics-4
          • Cloud Mode
          • Device Mode
          • Google Analytics 4
          • Setting up Google Analytics 4
        • profitwell
          • ProfitWell
          • Cloud Mode
          • Device Mode
      • attribution
        • Adjust
        • AppsFlyer
        • Branch
        • Attribution
        • Kochava
        • TVSquared
      • business-messaging
        • Business Messaging
        • Intercom
        • Kustomer
        • Slack
        • Trengo
      • continuous-integration
        • Visual Studio App Center
        • Continuous Integration
      • crm
        • Delighted
        • HubSpot
        • CRM
        • Salesforce
        • Variance
        • Zendesk
      • customer-data-platform
        • Customer Data Platform
        • Segment
      • error-reporting
        • Bugsnag
        • Error Reporting
        • Sentry
      • marketing
        • ActiveCampaign
        • AdRoll
        • Airship
        • Appcues
        • Autopilot
        • Blueshift
        • Braze
        • CleverTap
        • Customer.io
        • Gainsight PX
        • Gainsight
        • Marketing
        • Iterable
        • Klaviyo
        • Leanplum
        • Mailchimp
        • Marketo Lead Import
        • Marketo
        • MoEngage
        • Ometria
        • Pardot
        • Post Affiliate Pro
        • Qualtrics
        • SendGrid
        • Salesforce Marketing Cloud
        • Userlist
        • drip
          • Cloud Mode
          • Device Mode
          • Drip
          • Setting Up Drip in RudderStack
      • productivity
        • Google Sheets
        • Productivity
      • storage-platforms
        • Amazon S3
        • DigitalOcean Spaces
        • Google Cloud Storage
        • Storage Platforms
        • Azure Blob Storage
        • MinIO
        • Redis
      • streaming-platforms
        • Amazon EventBridge
        • Amazon Kinesis Firehose
        • Amazon Kinesis
        • Azure Event Hubs
        • BigQuery Stream
        • Confluent Cloud
        • Google Pub/Sub
        • Streaming Platforms
        • Apache Kafka
      • tag-managers
        • Google Tag Manager
        • Tag Managers
      • testing-and-personalization
        • Algolia Insights
        • Candu
        • Google Optimize
        • A/B Testing & Personalization
        • LaunchDarkly
        • Monetate
        • Optimizely Full Stack
        • Optimizely Web
        • Split.io
        • Statsig
        • VWO (Visual Website Optimizer)
    • get-started
      • RudderStack Cloud vs. RudderStack Open Source
      • Glossary
      • Get Started
      • RudderStack Architecture
    • reverse-etl
      • Amazon Redshift
      • Amazon S3
      • ClickHouse
      • FAQ
      • Google BigQuery
      • Reverse ETL
      • PostgreSQL
      • Snowflake
      • common-settings
        • Importing Data using Models
        • Importing Data using Tables
        • Common Settings
        • Sync Modes
        • Sync Schedule
      • features
        • Airflow Provider
        • Features
        • Models
        • Visual Data Mapper
    • rudderstack-api
      • Data Regulation API
      • HTTP API
      • RudderStack API
      • Personal Access Tokens
      • Pixel API
      • Test API
      • api-specification
        • Application Lifecycle Events Specification
        • API Specification
        • Video Events Specification
        • rudderstack-ecommerce-events-specification
          • Browsing
          • Coupons
          • E-Commerce Events Specification
          • Ordering
          • Promotions
          • Reviewing
          • Sharing
          • Wishlist
        • rudderstack-spec
          • Alias
          • Common Fields
          • Group
          • Identify
          • RudderStack Event Specification
          • Page
          • Screen
          • Track
    • rudderstack-cloud
      • Audit Logs
      • Dashboard Overview
      • Destinations
      • RudderStack Cloud
      • Live Events
      • Connection Modes: Cloud Mode vs. Device Mode
      • Sources
      • Teammates (User Management)
      • connections
        • Adding a Destination
        • Connections
    • rudderstack-open-source
      • Control Plane Setup
      • RudderStack Open Source
      • installing-and-setting-up-rudderstack
        • Developer Machine Setup
        • Docker
        • Data Plane Setup
        • Kubernetes
        • Sending Test Events
    • stream-sources
      • App Center
      • AppsFlyer
      • Auth0
      • Braze
      • Customer.io
      • Extole
      • Event Stream Sources
      • Iterable
      • Looker
      • PostHog
      • Segment
      • Shopify
      • Webhook Source
      • rudderstack-sdk-integration-guides
        • Client-side Event Filtering
        • SDKs
        • AMP Analytics
        • Cordova
        • .NET
        • Go
        • Java
        • Node.js
        • PHP
        • Python
        • React Native
        • Ruby
        • Rust
        • Unity
        • SDK FAQs
        • rudderstack-android-sdk
          • Adding Application Class
          • Flushing Events Periodically
          • Android
        • rudderstack-flutter-sdk
          • Flutter SDK v1
          • Flutter v2
          • Flutter
        • rudderstack-ios-sdk
          • iOS
          • tvOS
          • watchOS
        • rudderstack-javascript-sdk
          • Data Storage in Cookies
          • Detecting Ad-blocked Pages
          • JavaScript
          • JavaScript SDK Enhancements
          • JavaScript SDK FAQs
          • Querystring API
          • Quick Start Guide
          • Version Migration Guide
          • consent-managers
            • Consent Managers
            • OneTrust
    • transformations
      • Access Token
      • FAQ
      • Transformations
      • Transformations API
    • user-guides
      • User Guides
      • administrators-guide
        • Troubleshooting Guide
        • Alerting Guide
        • Bucket Configuration Settings for Event Backups
        • Configuration Parameters
        • Event Replay
        • High Availability
        • Horizontal Scaling
        • Administrator's Guides
        • Infrastructure Provisioning
        • Monitoring and Metrics
        • Okta SSO Setup
        • OneLogin SSO Setup
        • RudderStack Grafana Dashboard
        • Software Releases
      • how-to-guides
        • How to Use Custom Domains
        • How to Develop Integrations for RudderStack
        • How to Configure a Destination via the Event Payload
        • How to Filter Events using Different Methods
        • How to Filter Selective Destinations
        • How to Submit a Pull Request for a New Integration
        • How-to Guides
        • How to Debug Live Destination Events
        • How to Use AWS Lambda Functions with RudderStack
        • create-a-new-destination-transformer-for-rudder
          • Best Practices for Coding Transformation Functions in JavaScript
          • How to Create a New Destination Transformation for RudderStack
        • implement-native-js-sdk-integration
          • How to Add a Device Mode SDK to RudderStack JavaScript SDK
          • How to Implement a Native JavaScript SDK Integration
        • rudderstack-jamstack-integration
          • How to Integrate RudderStack with Your JAMstack Site
          • How to Integrate Rudderstack with Your Angular App
          • How to Integrate Rudderstack with Your Astro Site
          • How to Integrate Rudderstack with Your Eleventy Site
          • How to Integrate Rudderstack with Your Ember.js App
          • How to Integrate Rudderstack with a Gatsby Website
          • How to Integrate Rudderstack with a Hugo Site
          • How to Integrate Rudderstack with Your Jekyll Site
          • How to Integrate Rudderstack with Your Next.js App
          • How to Integrate Rudderstack with Your Nuxt.js App
          • How to Integrate Rudderstack with Your Svelte App
          • How to Integrate Rudderstack with Your Vue App
      • migration-guides
        • Migrating from Blendo to RudderStack
        • Migrating Your Warehouse Destination from Segment to RudderStack
        • Migration Guides
        • Migrating from Segment to RudderStack
  • src
    • @rocketseat
      • gatsby-theme-docs
        • text
          • Home
Powered by GitBook
On this page
  • SDK setup requirements
  • Installing the Flutter SDK
  • Initializing the RudderStack client
  • Track
  • Identify
  • Screen
  • Group
  • Alias
  • Reset
  • Enabling/disabling user tracking via the optOut API (GDPR Support)
  • Enabling/disabling events for specific destinations
  • 1. Passing destinations while initializing the SDK
  • 2. Passing destinations while making event calls
  • External ID
  • Anonymous ID
  • Advertising ID
  • Setting the device token
  • Configuring your RudderStack client
  • Self-hosted control plane
  • Debugging
  • FAQs
  • How do I get the user traits after making an identify call?
  • Contact us

Was this helpful?

  1. docs
  2. stream-sources
  3. rudderstack-sdk-integration-guides
  4. rudderstack-flutter-sdk

Flutter SDK v1

Detailed instructions for using RudderStack's Flutter SDK v1.

Previousrudderstack-flutter-sdkNextFlutter v2

Last updated 3 years ago

Was this helpful?

SDK setup requirements

To set up the RudderStack Flutter SDK, the prerequisites are as mentioned below:

  • You will need to set up a .

  • Once signed up, set up a Flutter source in the dashboard. For more information, follow . You should then see a Write Key for this source, as shown:

  • You will also need a data plane URL. Follow for more information on the data plane URL and where to get it.

  • We also recommend setting up the on your system.

We have migrated the RudderStack Flutter SDK to Null Safety starting from version 1.0.2.

Installing the Flutter SDK

The recommended way to install the Flutter SDK is through .

To add the SDK as a dependency, perform the following steps:

  • Open pubspec.yaml and add rudder_sdk_flutter under dependencies section:

dependencies:
  rudder_sdk_flutter: ^1.0.5
  • Navigate to your Application's root folder and install all the required dependencies with:

flutter pub get

Initializing the RudderStack client

After adding the SDK as a dependency, you need to set up the SDK.

  • To import the SDK, refer to the following snippet:

import 'package:rudder_sdk_flutter/RudderClient.dart';
import 'package:rudder_sdk_flutter/RudderConfig.dart';
import 'package:rudder_sdk_flutter/RudderLogger.dart';
  • Add the following code somewhere in your application.

RudderLogger.init(RudderLogger.VERBOSE);
RudderConfigBuilder builder = RudderConfigBuilder();
builder.withDataPlaneUrl(DATA_PLANE_URL);
builder.withTrackLifecycleEvents(true);
RudderClient.getInstance(WRITE_KEY,config: builder.build());

The setup method has the following signature:

Name
Data Type
Required
Description

writeKey

String

Yes

Your Flutter source writeKey

config

RudderConfig

No

Contains the RudderStack Client configuration

Track

You can record the users' activity through the track method. Every action performed by the user is called an event.

A sample track event is shown below:

RudderProperty property = RudderProperty();
property.put("test_key_1", "test_key_1");
RudderProperty childProperty = RudderProperty();
childProperty.put("test_child_key_1", "test_child_value_1");
property.put("test_key_2",childProperty);
RudderClient.track("test_track_event", properties: property);

The track method has the following signature:

Name
Data Type
Required
Description

name

String

Yes

Contains the name of the event you want to track

properties

RudderProperty

No

Contains the extra data properties you want to send along with the event

options

RudderOption

No

Contains the extra event options

We automatically track the following optional events:

  1. Application Installed

  2. Application Updated

  3. Application Opened

  4. Application Backgrounded

You can disable these events by calling withTrackLifeCycleEvents(false) on RudderConfigBuilder object while initializing the RudderClient. However, it is highly recommended to keep them enabled.

Identify

We capture the deviceId and use that as the anonymousId for identifying the user. This helps to track the users across the application installation. To attach more information to the user, you can use the identify method. Once a user is identified, the SDK persists all the user information and passes it to the successive track or screen calls. To reset the user identification, you can use the reset method.

On the Android devices, the deviceId is assigned during the first boot. It remains consistent across the applications and installs. This can be changed only after a factory reset of the device.

A sample identify event is as shown:

RudderTraits traits = RudderTraits();
traits.putBirthdayDate(new DateTime.now());
traits.putEmail("abc@123.com");
traits.putFirstName("First");
traits.putLastName("Last");
traits.putGender("m");
traits.putPhone("5555555555");

Address address = Address();
address.putCity("City");
address.putCountry("USA");
traits.putAddress(address);

traits.put("boolean", true);
traits.put("integer", 50);
traits.put("float", 120.4);
traits.put("long", 1234);
traits.put("string", "hello");
traits.put("date", new DateTime.now().millisecondsSinceEpoch);

RudderClient.identify("test_user_id", traits: traits, options: null);

The identify method has the following signature:

Name
Data Type
Required
Description

userId

String

Yes

Includes the developer identity for the user

traits

RudderTraits

No

Contains information related to the user traits

options

RudderOption

No

Extra options for the identify event

Screen

You can use the screen call to record whenever the user sees a screen on the mobile device. You can also send some extra properties along with this event.

An example of the screen event is as shown:

RudderProperty screenProperty = new RudderProperty();
screenProperty.put("foo", "bar");
RudderClient.screen("Main Activity",
    properties: screenProperty, options: null);

The screen method has the following signature:

Name
Data Type
Required
Description

screenName

String

Yes

Name of the screen viewed.

properties

RudderProperty

No

Extra property object that you want to pass along with the screen call.

options

RudderOption

No

Extra options to be passed along with screen event.

Group

The group call associates a user to a specific organization.

An example of group event is as shown:

RudderTraits groupTraits = RudderTraits();
groupTraits.put("foo", "bar");
groupTraits.put("foo1", "bar1");
RudderClient.group("sample_group_id",
    groupTraits: groupTraits, options: null);

The group method has the following signature:

Name
Data Type
Required
Description

groupId

String

Yes

An ID of the organization with which you want to associate your user

groupTraits

RudderTraits

No

Any other traits of the organization you want to pass along with the group call.

options

RudderOption

No

Extra options to be passed along with group event.

RudderStack does not persist the traits for the group across the sessions.

Alias

The alias call lets you merge different identities of a known user.

alias is an advanced method that lets you change the tracked user's ID explicitly. This method is useful when managing identities for some of the downstream destinations.

A sample alias call is as shown:

RudderClient.alias("new_user_id", options: null);

The alias method has the following signature:

Name
Data Type
Required
Description

newId

String

Yes

The new userId you want to assign to the user

options

RudderOption

No

Extra options to be passed along with alias event.

RudderStack replaces the old userId with the newUserId and persists that identification across the sessions.

Reset

You can use the reset method to clear the persisted traits for the identify call. This is required for Logout operations.

RudderClient.reset();

Enabling/disabling user tracking via the optOut API (GDPR Support)

RudderStack gives the users (e.g., an EU user) the ability to opt out of tracking any user activity until the user gives their consent. You can do this by leveraging RudderStack's optOut API.

The optOut API takes true or false as a Boolean value to enable or disable tracking user activities. This flag persists across device reboots.

The following snippet highlights the use of the optOut API to disable user tracking:

RudderClient.optOut(true);

Once the user grants their consent, you can enable user tracking once again by using the optOut API with false as a parameter sent to it, as shown:

RudderClient.optOut(false);

The optOut API is available in the Flutter SDK starting from version 1.0.6.

Enabling/disabling events for specific destinations

The Flutter SDK lets you enable or disable sending events to a specific destination or all the destinations connected to a source. You can specify these destinations by creating an object as shown in the following snippet:

RudderOption options = new RudderOption();
// default value for `All` is true
options.putIntegration("All", false);
// specifying destination by its display name
options.putIntegration("Mixpanel", false);
// specifying destination by its Factory object
options.putIntegrationWithFactory(Appcenter(), true);

The keyword All in the above snippet represents all the destinations connected to a source. Its value is set to true by default.

You can pass the destination(s) specified in the above snippet to the SDK in two ways:

1. Passing destinations while initializing the SDK

This is helpful when you want to enable/disable sending the events across all the event calls made using the SDK to the specified destination(s).

RudderClient.getInstance(WRITE_KEY,
                    config: builder.build(),options: options);

2. Passing destinations while making event calls

This approach is helpful when you want to enable/disable sending only a particular event to the specified destination(s) or if you want to override the specified destinations passed with the SDK initialization for a particular event.

RudderProperty property = RudderProperty();
property.put("test_key_1", "test_key_1");
RudderClient.track("test_track_event", properties: property, options: options);

If you specify the destinations both while initializing the SDK as well as while making an event call, then the destinations specified at the event level only will be considered.

External ID

You can pass your custom userId along with standard userId in your identify calls. We add those values under context.externalId. The following code snippet shows a way to add externalId to your identify request.

RudderOption option = RudderOption();
option.putExternalId("externalId", "some_external_id_1");
RudderClient.identify("testUserId", options: option);

Anonymous ID

We use the deviceId as anonymousId by default. You can use the following method to override and use your own anonymousId with the SDK.

An example of setting the anonymousId is as below

RudderClient.putAnonymousId(<ANONYMOUS_ID>);

Advertising ID

You can use the putAdvertisingId method to pass your Android and iOS AAID and IDFA respectively. The putAdvertisingId method accepts a string argument :

  • id : Your Android advertisingId (AAID) or your iOS advertisingId (IDFA).

An example of how to use putAdvertisingId is as shown:

RudderClient.putAdvertisingId(<ADVERTISING_ID>);

The id parameter that you pass in the putAdvertisingId method is assigned as the AAID if you are on an Android device, and as the IDFA if you are on an iOS device.

Setting the device token

You can pass your device-token for push notifications to be passed to the destinations which support the Push Notification feature. We set the token under context.device.token.

An example of setting the device-token is as below:

RudderClient.putDeviceToken(<DEVICE_TOKEN>);

Configuring your RudderStack client

You can configure your client based on the following parameters by passing them in the RudderConfigBuilder object of your RudderClient.getInstance() call.

Parameter
Type
Description
Default Value

logLevel

int

Controls how much of the log you want to see from the Flutter SDK.

RudderLogger.RudderLogLevel.NONE

endPointUri

string

Your data plane URL.

https://hosted.rudderlabs.com

flushQueueSize

int

Number of events in a batch request to the server.

30

dbThresholdCount

int

Number of events to be saved in the SQLite database. Once the limit is reached, older events are deleted from the DB.

10000

sleepTimeout

int

Minimum waiting time to flush the events to the server.

10 seconds

configRefreshInterval

int

Fetches the config from the dashboard after this specified time.

2 hours

trackLifecycleEvents

boolean

Whether SDK will capture application life cycle events automatically.

true

controlPlaneUrl

string

https://api.rudderlabs.com

Self-hosted control plane

Debugging

If you run into any issues regarding the RudderStack Flutter SDK, you can turn on the VERBOSE or DEBUG logging to find out what the issue is.

First, make sure you import RudderLogger with the below command:

import 'package:rudder_sdk_flutter/RudderLogger.dart';

Then to turn on the logging, change your RudderClient initialization to the following:

RudderConfigBuilder builder = RudderConfigBuilder();
builder.withDataPlaneUrl(DATA_PLANE_URL);
builder.withLogLevel(RudderLogger.VERBOSE);
RudderClient.getInstance(WRITE_KEY,
                          config: builder.build());

You can set the log level to one of the following values:

  1. NONE

  2. ERROR

  3. WARN

  4. INFO

  5. DEBUG

  6. VERBOSE

FAQs

How do I get the user traits after making an identify call?

You can get the user traits after making an identify call in the following way:

Map context = await RudderClient.getRudderContext();
print(context["traits"]);

Contact us

IMPORTANT: This version of the Flutter SDK will soon be deprecated. We highly recommend upgrading to the latest SDK version by going to our . For the latest documentation, refer to guide.

Check the section below for a full list of the configurable parameters.

According to the Apple , if the iOS device has multiple apps from the same vendor, all the apps will be assigned the same deviceId. If all the applications from a vendor are uninstalled and then reinstalled, then they will be assigned a new deviceId.

For detailed explanation of the alias call, refer to the guide.

Make sure the destination names that you pass while specifying the destinations should exactly match the names as listed .

This parameter should be changed only if you are self-hosting the control plane. Check the section below for more information. The SDK will add /sourceConfig along with this URL to fetch the configuration.

If you are using a device mode destination like Adjust, Firebase, etc., the Flutter SDK needs to fetch the required configuration from the control plane. If you are using the utility to host your own control plane, then follow and specify controlPlaneUrl in your RudderConfig.Builder that points to your hosted source configuration file.

You shouldn't pass the controlPlaneUrl parameter during SDK initialization if you are using the from . This parameter is supported only if you are using our open-source utility to set up your own control plane.

For queries on any of the sections covered in this guide, you can or start a conversation in our community.

If you come across any issues while using the Flutter SDK, you can also open an issue on our .

Configuring your RudderStack client
documentation
RudderStack API Specification
here
Control Plane Lite
this guide
RudderStack dashboard
https://app.rudderstack.com
Control Plane Lite
contact us
Slack
GitHub Issues page
GitHub repository
this
Self-hosted control plane
RudderStack Account
this guide
this section
Flutter development environment
pub
Github Badge
Flutter source write key