Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass Parameters in Dynamic Links?

How to receive parameters from firebase dynamic links in flutter?

I created a short url:

https://subdomain.example.com/product

which points to

https://example.com/view-product

But I want to add a url query parameter like:

https://example.com/view-product?id=56

Note that "56" is variable and changes dynamically inside app flow. I am unable to receive this "id" parameter.

On browser I tried entering https://subdomain.example.com/product?id=56

I received the link: https://example.com/view-product

     FirebaseDynamicLinks.instance.onLink(
        onSuccess: (PendingDynamicLinkData dynamicLink) async {

      final Uri deepLink = dynamicLink?.link;

      showModalBottomSheet(context: context, builder: (context){
        return Container(
          height: 100.0,
          child: Text(deepLink.toString()),
        );
      });
      if (deepLink != null) {
        debugPrint("Link found on line: "+deepLink.queryParameters.toString());

      }
    }, onError: (OnLinkErrorException e) async {
      print('onLinkError');
      print(e.message);
    });
like image 986
Pushan Gupta Avatar asked Oct 18 '19 18:10

Pushan Gupta


People also ask

What is a dynamic link URL?

Dynamic Links are smart URLs that allow you to send existing and potential users to any location within your iOS or Android app. They survive the app install process, so even new users see the content they're looking for when they open the app for the first time.

How do I debug dynamic links in Firebase?

To help you debug your Dynamic Links, you can preview your Dynamic Links' behavior on different platforms and configurations with an automatically-generated flowchart. Generate the flowchart by adding the d=1 parameter to any short or long Dynamic Link.


Video Answer


1 Answers

I finally figured it out!

I was understanding the concept totally wrong here.

There are 4 ways as of now to create dynamic links.

1) Firebase Console
2) Manually
3) Rest API
4) Dynamic Link Builder API on iOS and Android 

What I was doing wrong here is was, I created https://subdomain.example.com/product a dynamic link from firebase console and was testing it against a manually created link.

2nd method(Manually) is much more powerful is you need to link dynamic content from your website links.

https://your_subdomain.page.link/?link=your_deep_link&apn=package_name[&amv=minimum_version][&afl=fallback_link]

The above mentioned is the standard manual procedure for creating dynamic links.

Lets break down the above link so that it looks less scary:

  • https://your_subdomain.page.link ==> This is simply your subdomain you registered on firebase console. In our case it's https://subdomain.example.com

  • link=your_deep_link ==> your_deep_link is basically your deep link(the link you want to open with that exists on your server, it can contain all the parameters you need). In our case its https://example.com/view-product?id=56. But note that this link is to be embedded inside an url so it needs to be urlencoded first. Use any url encoder for this purpose. The resulting encoded string becomes

https%3A%2F%2Fexample.com%2Fview-product%3Fid%3D56

  • apn=package_name ==> your respective package name for IOS or Android

  • [&amv=minimum_version] ==> "[]" represent this as an optional parameters. This parameter is the minimum version number of your app that you want your app should respond to this dynamic link (0 if you want all versions to support)

  • [&afl=fallback_link] ==> ==> "[]" represent this as an optional parameters. This is the fallback url, again url encoded. Could be your android play store link.

So our final dynamic link looks like:

https://subdomain.example.com/?link=https%3A%2F%2Fexample.com%2Fview-product%3Fid%3D56&apn=com.example&amv=0

like image 182
Pushan Gupta Avatar answered Oct 02 '22 14:10

Pushan Gupta