Skip to main content

Overview

This guide provides step-by-step instructions to initialize the AppTrove Flutter SDK in your Flutter application. Proper initialization ensures accurate tracking, attribution, and reporting across Android and iOS platforms.

Prerequisites

  • A Flutter application with the AppTrove SDK installed
  • Access to the Trackier Panel
  • Flutter 2.0 or later, Dart 2.12 or later
  • Basic knowledge of Dart and Flutter development

Initialization

Step 1: Retrieve SDK Key

  1. Log in to your Trackier Panel.
  2. Select your application, click the Action button, and log in.
  3. In the Dashboard, click the SDK Integration option on the left side of the panel.
  4. Under SDK Integration, locate and copy the SDK Key.

important

Using the correct SDK key is critical. An incorrect key may cause attribution and reporting issues.


Step 2: Initialize the SDK

Initialize the AppTrove SDK in the initState() method of your main.dart class to ensure it loads during app startup.

main.dart
class _MyHomePageState extends State<MyHomePage> {

void initState() {
super.initState();
initializeSdk();
}

Future<void> initializeSdk() async {
String key = "xxxx-xx-4505-bc8b-xx"; // Please pass your Development key here.

/* While Initializing the Sdk, You need to pass the two arguments in the TrackierSDKConfig.
* In First argument, you need to pass the AppTrove SDK api key
* In second argument, you need to pass the environment which can be either "development", "production" or "testing". */

TrackerSDKConfig trackerSDKConfig = TrackerSDKConfig(key, "production");
Trackierfluttersdk.initializeSDK(trackerSDKConfig);
}
}

Parameters

  • key: Your SDK key from the Trackier Panel.
  • environment: Environment setting. Use:
    • "development" for testing.
    • "production" for release builds.
    • "testing" for staging environments.
note

Ensure the SDK key matches your application in the Trackier Panel to avoid attribution and reporting issues.


Step 3: Associate User Info (Optional)

You can associate user information (e.g., User ID, Email) during SDK initialization to enhance tracking and attribution.

main.dart
void userDetails() {
/* Passing the UserId and User EmailId Data */
Trackierfluttersdk.setUserId("XXXXXXXX"); // Pass the UserId values here
Trackierfluttersdk.setUserEmail("abc@gmail.com"); // Pass the user email id in the argument

/* Passing the additional data */
var userDetails = Map<String, Object>();
userDetails["name"] = "abcd"; // You can pass the Username data
userDetails["mobile_number"] = "872xxxxx87"; // You can pass user mobile number
Trackierfluttersdk.setUserAdditonalDetail(userDetails);
}

Available Methods

  • setUserId(String): Unique user identifier.
  • setUserEmail(String): User's email address.
  • setUserAdditonalDetail(Map<String, Object>): Custom key-value pairs for extra metadata (e.g., name, mobile number).

Best Practices

  • Initialize Early: Place initialization in initState() to capture all app launches.
  • Use Correct Environment: Set "testing" or "development" during testing to avoid polluting production data. Switch to "production" for release builds.
  • Verify SDK Key: Ensure the SDK key matches the one in the Trackier Panel to prevent tracking issues.
  • Leverage User Info: Associate user details (e.g., User ID, Email) to improve attribution accuracy.

Troubleshooting

  • Incorrect SDK Key: Verify the SDK key matches the one in the Trackier Panel.
  • Initialization Issues: Ensure initialization occurs in initState() and the SDK is properly added to pubspec.yaml.
  • Environment Mismatch: Confirm the environment ("testing", "development", or "production") aligns with your deployment stage.
  • User Data Not Recorded: Check that user detail methods (e.g., setUserId) are called before tracking events.

For further assistance, refer to the Trackier Documentation Portal or contact Trackier support at support@trackier.com.