Getting Started

ReferralHero Flutter/Dart SDK

Getting started

To start using the ReferralHero SDK, you will need to add it to your project as a package from pub.dev.

Adding the Dependency

Step 1:

  1. Open your Flutter project.

  2. Add the following dependency to your pubspec.yaml file:

dependencies:
  referral_hero_flutter: latest_version
  1. Run flutter pub get to fetch the new dependency.

Step 2:

  1. Import ReferralHero in your Dart code:

import 'package:referral_hero/referral_hero.dart';
  1. Initialize the SDK in your main application file (main.dart):

late ReferralHeroFlutter _referralHeroService;

  final apiKey = "Your-api-key";
  final uuid = "You-uuid";

  @override
  void initState() {
    super.initState();
    _referralHeroService = ReferralHeroFlutter(apiKey, uuid);
  }

Step 3:

  1. Get your API_TOKEN from the ReferralHero Dashboard -> API: ReferralHero Dashboard.

  2. Back in the ReferralHero overview, click to edit your desired Campaign.

  1. Then the Installation tab, then Mobile App Installation.

  1. Get your UUID: The 12-letter ID that starts with ‘MF’ in Edit Campaign > launch > Mobile app installation, e.g. MF15298bba6d.

  1. Add the Campaign Token obtained from the campaign, and UUID from the installation Tab.

Step 4:

In the Goal section of your Campaign settings, ensure you have added the Google Play and Apple App Store links and a default referral link for desktop web users.

Well done! You should now be able to build and run your campaign. Before using the more advanced features of the SDK, you should learn about a couple of important concepts.

Tracking Referrals

Now that you have implemented the SDK, you can start identifying and tracking referrals!

For that, you will need 2 things:

  1. Universal Link

  2. Your Integrated App

The RH SDK Pulls information from your Device, like this:

final referralParams = {
  'email': 'user@example.com', // Capture this from user
  'domain': 'https://a.domain.co/', // Optional value, and set as default by admin
  'name': 'User Name', // Capture this from user
  'referrer': 'referrerCode', // Optional value, only necessary if you want to capture the referrer code from user
  'uuid': 'MFcd4113d4bf', // Get this from RH Dashboard
  'device': referralHeroService.deviceInfo.getDeviceType(), // Get device type
  'ip_address': referralHeroService.deviceInfo.getIpAddress(), // Get IP address
  'os_type': referralHeroService.deviceInfo.getOperatingSystem(), // Get operating system type
  'screen_size': referralHeroService.deviceInfo.getDeviceScreenSize() // Get screen size
};

The format for screen sizes is not native to RH, and the format should be parsed to RH accepted, such as:

String transformResolution(String input) {
  final dimensions = input.split('*').map((e) => e.trim()).toList();
  return '${dimensions[0]} x ${dimensions[1]}';
}

With this information, you should be able to add the subscriber data, with the Get Referrer, Add Subscriber, Create Pending Referral, or Track Referral methods to automatically identify or track a referral:

void formSubmit() {
  referralHeroService.addSubscriber(referralParams);
}

To further understand the implementation of these methods, please check the Public Methods section, and our Github Sample Project.

Last updated