20

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Bisclavret
  • 1,327
  • 9
  • 37
  • 65
  • So, Finally did you find any solution for referral program or not? – Himanshu Jun 12 '21 at 12:08
  • I did not mate, ended up giving up. Haven't implemented this into my app at all, and haven't worked on it at all in over a year now. – Bisclavret Jul 23 '21 at 00:17
  • 1
    I found the easiest solution and implemented and working great.....I have posted it as answer. With the test cases. – Himanshu Jul 28 '21 at 14:15

4 Answers4

6

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);
    });
}
Olga
  • 291
  • 2
  • 12
  • Perfect solution brother. I've been looking for this kind of solution for deep linking and referral code. What an amazing answer with pure description. Thanks again. – Harsh Patel May 30 '20 at 13:29
1

Regarding the documentation, you can read through the README page, which explains all available functions and also how to set up your project to make the plugin work.
On top of that, you can view the example application, which contains the project files for a full implementation of this plugin. You can view the Dart code and all other required setup.

Now, I would like to come to the real question: should you use firebase_dynamic_links if you want to set up referral rewards?
First, you need to know that this is part of the Firebase product suite. It is not quite clear from your question if you use Firebase for your project already, however, you should most likely only use this product if you either plan to use or already use Firebase in your project.
Firebase Dynamic Links works for this task and is very convenient if you already use Firebase, however, I am not quite sure if it does great as a standalone product.
Using Firebase also has some implications for the rest of your project, i.e. you will be collecting analytics data etc.

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.
If you wanted to set up rewards, you would need to write your own platform-specific code and handle deep links this way, which is also how firebase_dynamic_links does it for Firebase.

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
  • Hi again! My resident saviour. I had already added Firebase to my project for nothing more than analytics statistics at this point, so would this be the best path? With regards to the full implementation of the plugin, I have pulled that example out as a separate app at present and am trying to get it working. There is a line: final PendingDynamicLinkData data = and that's all it says. Clearly it seems there is supposed to be something there but no indication what. I tried a dynamic link from Firebase, but it will not accept String. The app does nothing and I assume this is why. – Bisclavret Jun 25 '19 at 07:49
  • @Bisclavret Well, you need to consider that Dynamic Links might have functionality that you do not need. If you only want deep links, it is more efficient to implement it yourself using platform code. It says `final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.retrieveDynamicLink();` in the documentation. – creativecreatorormaybenot Jun 25 '19 at 07:53
  • Still looking at this one and trying to get the example app working. I have had to buy a domain online, and I have gone through the verification process. I think my DNS host takes a long time to reflect the changes, so I am just having to wait at this point. Then I should be able to create a dynamic link to test the example app with. – Bisclavret Jun 26 '19 at 01:49
  • Ok so everything is verified now. I have set up the URL for referrals on my domain, but now I am getting an error in the app because my URL path doesn't actually contain anything. What am I supposed to do with this? My plan is to set up a URL path that simply redirects to the google play store page for the app, is this basically what needs to be done here? – Bisclavret Jun 26 '19 at 03:16
  • Going to update my original question with additional details of what is going on behind the scenes. – Bisclavret Jun 26 '19 at 03:26
1

The simplest Solution I found and successfully implemented with

https://pub.dev/packages/flutter_branch_sdk

Whether you have the app installed in the device or not.

Scenario 1: When you tap on the referral link and you don't have app install in your phone -> It will redirect you to the Google Play Store or App store -> Once you install the app and come to the app you will get the referral code which is mapped in the referral link.

Scenario 2: When you have already app installed in you phone and click on the referral link - app will be opened and you will receive the referral code which mapped in the referral link.

Its easeiest solution I found with successful implementation as well.

Himanshu
  • 861
  • 10
  • 25
1

I also had to build a referral reward program in my app.

I came across this tutorial which uses Branch I/O and it works fine. Flutter Deep Linking Using Branch I/O

And there is also a working project on GitHub, posted by the Author of this tutorial. here

But the Branch I/O is free only till 10,000 monthly active users.

Madhav Kumar
  • 856
  • 8
  • 19