Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing referral rewards in Flutter

I would like to set up a referrals system in my application, so that users can invite their friends via email/phone number etc (whichever is easiest) and when it is confirmed that the invitee has installed the application, it will reward the original invite sender with, say, a month of no banner ads.

The only reference I can find online is this one: https://pub.dev/packages/firebase_dynamic_links#-readme-tab-

I am not sure if this is what I am after and unfortunately, because it was set up by the Flutter Team it offers exactly 0 explanations on how to actually implement any of it, as they sort of expect you to already be a professional full-time coder, able to fill in all the blanks for yourself.

Is this the right plugin for what I am after? Are there any better resources?

Edit

Going down the Firebase Dynamic Links Path. First hurdle I came to is it required me to own a domain, that I could create the URLs for the dynamic links in. So I registered myself a domain last night and set it up as required by Firebase to get it verified and connected to the Firebase project (it steps you through this, and everything appears to work fine, just may need to give your DNS host time to reflect the TXT and A record changes this process requires).

So now I have a blank, verified domain called example.com

Within Firebase now, under the project I created, down the left-hand side is a button called Dynamic Links. This will require example.com to be verified by the A records it had you enter previously, but once verified it will allow you to create a New Dynamic Link.

There are 5 steps here:

Step 1) It suggests a short URL link for you. In my case: example.com/gd7W. I accepted this and hit next.

Step 2) Set up your Dynamic Link. It asks for a Deep Link URL and a Dynamic Link Name. In my case I used example.com/apps/refer_a_friend and you can give the Dynamic Link any name you like. I just called mine "Refer a Friend Promotion". Hit next.

Step 3) Define link behaviour for iOS. I just left it as "open deep link in browser"

Step 4) Define link behaviour for Android. I just left it as "open deep link in browser"

Step 5) Campaign tracking, social tags and advanced options. It doesn't appear that this stuff is important at this stage, not for what this post requires which is just getting the thing working. This stuff is for analytics and tracking of your promotion once it is working. You can come back and edit it later.

So in Step 2, the Deep Link URL I referenced does not actually exist. I am not sure if it is supposed to. If I am meant to create this page on my website, but then if so, what am I supposed to put on this page? My current thoughts are that I should create a redirect on my site from this address to the URL of the google play store for the app. I have tried this but it is not redirecting.

Next, back to the example app again (and here I am referring to the example we are working on in the comments below that is sourced from here: https://github.com/flutter/plugins/tree/master/packages/firebase_dynamic_links/example).

This section is what I believe we need to look at, as it needs editing to fit your own links and addresses from your previous steps:

final DynamicLinkParameters parameters = DynamicLinkParameters(
  uriPrefix: 'https://cx4k7.app.goo.gl',
  link: Uri.parse('https://dynamic.link.example/helloworld'),
  androidParameters: AndroidParameters(
    packageName: 'io.flutter.plugins.firebasedynamiclinksexample',
    minimumVersion: 0,
  ),
  dynamicLinkParametersOptions: DynamicLinkParametersOptions(
    shortDynamicLinkPathLength: ShortDynamicLinkPathLength.short,
  ),
  iosParameters: IosParameters(
    bundleId: 'com.google.FirebaseCppDynamicLinksTestApp.dev',
    minimumVersion: '0',
  ),
);

I changed this section of code to try and match my work above, so updated to this:

final DynamicLinkParameters parameters = DynamicLinkParameters(
  uriPrefix: 'https://example.com/gd7W',
  link: Uri.parse('https://example.com/apps/refer_a_friend'),
  androidParameters: AndroidParameters(
    packageName: 'company01.appname', //The appID of my app on the store
    minimumVersion: 0,
  ),
  dynamicLinkParametersOptions: DynamicLinkParametersOptions(
    shortDynamicLinkPathLength: ShortDynamicLinkPathLength.short,
  ),
  iosParameters: IosParameters(
    bundleId: 'company01.appname', //The appID of my app on the store
    minimumVersion: '0',
  ),
);

When I run the app and click the Get Short Link button, the following error appears in the logs:

PlatformException(short_link_error, 400: Your project does not own Dynamic Links domain: https://example.com

Which I am not sure is the correct error, as in the Firebase console this domain is verified and currently connected. It appears to be working fine. I am wondering if the real issue is that my deep link doesn't really do anything at this point, and as I mentioned I am not entirely sure what it should be doing.

Edit 2

Just to add, when I click the Get Long Link button it actually seems to return something, an extremely long URL that appears as something like:

https://example.com/gd7W?amv=0&apn=company01.appname&ibi=company01.appname&imv=0&link=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcompany01.appname%26hl%3Den

Which appears to be all the components I have specified at various points, but maybe incorrectly. This looks like progress of a kind though!

Edit 3

I have been going through every example I can find. Not one of them tells me what the Dynamic Link URL should be, how to make it, where it supposed to point to, or what to do with it. This appears to be the missing link in getting this working.

What other things can I try to set this up?

Edit 4

I know a lot of people have been reading this thread, so I would love to be able to give you all a working example. I did not receive enough assistance with this, so I never got it working. I had to remove referrals from my app completely so I could meet the deadline.

like image 815
Bisclavret Avatar asked Jun 22 '19 06:06

Bisclavret


People also ask

How do I create a dynamic link in flutter?

Set up Firebase and the Dynamic Links SDK If you're building an Android app, open the Project settings page of the Firebase console and make sure you've specified your SHA-1 signing key. If you use App Links, also specify your SHA-256 key. In the Firebase console, open the Dynamic Links section.

Is Firebase_Dynamic_Links the flutter solution for referral rewards?

To conclude, firebase_dynamic_links is not the Flutter solution for referral rewards. It is simply the Firebase solution. There is no other plugin for Flutter that would allow you to easily set up these rewards, but this is to be expected. firebase_dynamic_links is a platform solution, i.e. it relies on Android and iOS plugins.

How do I grant referral rewards to new users?

Then, when they open your app for the first time, you can retrieve the referral information you included in the Dynamic Link and use it to apply the reward. Usually, you want to grant referral rewards only after the invitation recipient signs up, or even only after the new user completes some task.

What is the best plugin for flutter rewards?

There is no other plugin for Flutter that would allow you to easily set up these rewards, but this is to be expected. firebase_dynamic_links is a platform solution, i.e. it relies on Android and iOS plugins.

How to add a rewardedad to the flutter widget tree?

A RewardedAd is displayed as an Overlay on top of all app content and is statically placed; thus, it can't be added to the Flutter widget tree. You can choose when to show the add by calling show () .


1 Answers

That is how I got it work:

  1. Create your project in Firebase console.
  2. In the left panel choose "Dynamic Links"
  3. Click "Get started"
  4. Enter domain like yourappname.page.link
  5. Click "Finish"
  6. In the left panel click "Project Settings"
  7. Add your Android and iOS apps as it described here: https://firebase.google.com/docs/flutter/setup
  8. To make dynamic links work in iOS you should do some additional steps as it described here: https://www.youtube.com/watch?v=sFPo296OQqk&feature=youtu.be&t=2m40s

To create dynamic link I used this code:

String link = Constants.REFERENCE_BASE_URL + referenceId; // it can be any url, it does not have to be an existing one
final DynamicLinkParameters parameters = DynamicLinkParameters(
      uriPrefix: 'https://myappname.page.link', // uri prefix used for Dynamic Links in Firebase Console
      link: Uri.parse(link),
      androidParameters: AndroidParameters(
        packageName: 'com.example.myappname', // package name for your app
        minimumVersion: 0,
      ),
      iosParameters: IosParameters(bundleId: 'com.example.myappname'), // bundle ID for your app
    );
final ShortDynamicLink shortDynamicLink =
        await parameters.buildShortLink();

To receive dynamic link I used this code in main.dart file:

@override
  void initState() {
  super.initState();
  initDynamicLinks();
}

void initDynamicLinks() async {
  final PendingDynamicLinkData data =
    await FirebaseDynamicLinks.instance.getInitialLink();
  final Uri deepLink = data?.link;

  if (deepLink != null) {
    Navigator.pushNamed(context, deepLink.path);
  }

  FirebaseDynamicLinks.instance.onLink(
    onSuccess: (PendingDynamicLinkData dynamicLink) async {
      final Uri deepLink = dynamicLink?.link;

      if (deepLink != null) {
        Navigator.pushNamed(context, deepLink.path);
      }
    }, 
    onError: (OnLinkErrorException e) async {
      print('onLinkError');
      print(e.message);
    });
}
like image 129
Olga Avatar answered Sep 17 '22 11:09

Olga