title: Implementing referral rewards in Flutter
body: <p>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.</p>
  
  <p>The only reference I can find online is this one:  <a href="https://pub.dev/packages/firebase_dynamic_links#-readme-tab-" rel="noreferrer">https://pub.dev/packages/firebase_dynamic_links#-readme-tab-</a></p>
  
  <p>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.</p>
  
  <p>Is this the right plugin for what I am after?  Are there any better resources?</p>
  
  <h2>Edit</h2>
  
  <p>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).</p>
  
  <p>So now I have a blank, verified domain called example.com</p>
  
  <p>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.</p>
  
  <p>There are 5 steps here:</p>
  
  <p>Step 1) It suggests a short URL link for you.  In my case: example.com/gd7W. I accepted this and hit next.</p>
  
  <p>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.</p>
  
  <p>Step 3) Define link behaviour for iOS.   I just left it as "open deep link in browser"</p>
  
  <p>Step 4) Define link behaviour for Android.   I just left it as "open deep link in browser"</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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: <a href="https://github.com/flutter/plugins/tree/master/packages/firebase_dynamic_links/example" rel="noreferrer">https://github.com/flutter/plugins/tree/master/packages/firebase_dynamic_links/example</a>).</p>
  
  <p>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:</p>
  
  <pre><code>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',
    ),
  );
  </code></pre>
  
  <p>I changed this section of code to try and match my work above, so updated to this:</p>
  
  <pre><code>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',
    ),
  );
  </code></pre>
  
  <p>When I run the app and click the Get Short Link button, the following error appears in the logs:</p>
  
  <pre><code>PlatformException(short_link_error, 400: Your project does not own Dynamic Links domain: https://example.com
  </code></pre>
  
  <p>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.</p>
  
  <h2>Edit 2</h2>
  
  <p>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:</p>
  
  <pre><code>https://example.com/gd7W?amv=0&amp;apn=company01.appname&amp;ibi=company01.appname&amp;imv=0&amp;link=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcompany01.appname%26hl%3Den
  </code></pre>
  
  <p>Which appears to be all the components I have specified at various points, but maybe incorrectly.  This looks like progress of a kind though!</p>
  
  <h2>Edit 3</h2>
  
  <p>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.</p>
  
  <p>What other things can I try to set this up?</p>
  
  <h2>Edit 4</h2>
  
  <p>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. </p>