Flutter SDK v1
Detailed instructions for using RudderStack's Flutter SDK v1.
Last updated
Was this helpful?
Detailed instructions for using RudderStack's Flutter SDK v1.
Last updated
Was this helpful?
To set up the RudderStack Flutter SDK, the prerequisites are as mentioned below:
You will need to set up a RudderStack Account.
Once signed up, set up a Flutter source in the dashboard. For more information, follow this guide. You should then see a Write Key for this source, as shown:
You will also need a data plane URL. Follow this section for more information on the data plane URL and where to get it.
We also recommend setting up the Flutter development environment on your system.
We have migrated the RudderStack Flutter SDK to Null Safety starting from version 1.0.2.
The recommended way to install the Flutter SDK is through pub
.
To add the SDK as a dependency, perform the following steps:
Open pubspec.yaml
and add rudder_sdk_flutter
under dependencies
section:
Navigate to your Application's root folder and install all the required dependencies with:
After adding the SDK as a dependency, you need to set up the SDK.
To import the SDK, refer to the following snippet:
Add the following code somewhere in your application.
The setup
method has the following signature:
writeKey
String
Yes
Your Flutter source writeKey
config
RudderConfig
No
Contains the RudderStack Client configuration
Check the Configuring your RudderStack client section below for a full list of the configurable parameters.
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:
The track
method has the following signature:
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:
Application Installed
Application Updated
Application Opened
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.
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.
According to the Apple documentation, 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
.
A sample identify
event is as shown:
The identify
method has the following signature:
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
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:
The screen
method has the following signature:
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.
The group
call associates a user to a specific organization.
An example of group
event is as shown:
The group
method has the following signature:
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.
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.
For detailed explanation of the alias
call, refer to the RudderStack API Specification guide.
A sample alias
call is as shown:
The alias
method has the following signature:
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.
You can use the reset
method to clear the persisted traits
for the identify
call. This is required for Logout
operations.
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:
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:
The optOut
API is available in the Flutter SDK starting from version 1.0.6
.
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:
The keyword All
in the above snippet represents all the destinations connected to a source. Its value is set to true
by default.
Make sure the destination names that you pass while specifying the destinations should exactly match the names as listed here.
You can pass the destination(s) specified in the above snippet to the SDK in two ways:
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).
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.
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.
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.
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
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:
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.
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:
You can configure your client based on the following parameters by passing them in the RudderConfigBuilder
object of your RudderClient.getInstance()
call.
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
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 Control Plane Lite utility to host your own control plane, then follow this guide 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 RudderStack dashboard from https://app.rudderstack.com. This parameter is supported only if you are using our open-source Control Plane Lite utility to set up your own control plane.
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:
Then to turn on the logging, change your RudderClient
initialization to the following:
You can set the log level to one of the following values:
NONE
ERROR
WARN
INFO
DEBUG
VERBOSE
traits
after making an identify
call?You can get the user traits after making an identify
call in the following way:
For queries on any of the sections covered in this guide, you can contact us or start a conversation in our Slack community.
If you come across any issues while using the Flutter SDK, you can also open an issue on our GitHub Issues page.
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.
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.