55

I am writing a App for a Open Source Conference.

Originally each attendees will receive different link via email or SMS like

https://example.com/?token=fccfc8bfa07643a1ca8015cbe74f5f17

then use this link to open app, we can know the user is which attendee by the token.

Firebase release a new feature Dynamic Links in I/O 2016, it provide better experience for users.

I had try that, but I can't find any way to pass the custom parameters (the token) in dynamic links, how to use the same link with different parameters to my users?

Thanks.

Denny Huang
  • 651
  • 2
  • 7
  • 12

11 Answers11

57

I don't think you can use the short url: https://<my app>.app.goo.gl/Gk3m unless you create one for each user, but you can use the long url: https://<my app>.app.goo.gl/?link=https://example.com/?token=fccfc8bfa07643a1ca8015cbe74f5f17 ...(add other parameters as needed) and set new token for each user.

I assume you generate the tokens automatically. In that case you can use this to shorten the links.

Rick
  • 1,177
  • 1
  • 19
  • 27
diidu
  • 2,823
  • 17
  • 32
  • @diidu how can i use in c#? please help – Brijesh Mavani Apr 13 '18 at 11:38
  • @BrijeshMavani I am not expert with C#, but my answer is completely language independent, so you can use it in any language. – diidu Apr 16 '18 at 12:39
  • I tried in this way: https://.app.goo.gl/?link=https://example.com/?name=test?email=test@test.com This is giving shortlink as https://.app.goo.gl/abcd, after decoding this short url it is coming like https://.app.goo.gl/?link=https://example.com/?name=test?email%3Dtest@test.com %3D is coming in place of = after decoding it. – sreekanth kuriyala May 31 '18 at 09:09
  • How do we change the token from the short url? – Oliver Dixon Nov 20 '19 at 16:10
  • 1
    @OliverDixon You don't. You change it on the long url and generate a short one if needed. – diidu Nov 21 '19 at 11:22
  • This is my solution for sending/receiving parameters using long url https://stackoverflow.com/a/59436486/2238515 – Almeida Dec 22 '19 at 12:19
  • @diidu Is short url useless in this case? – Carlos Eduardo Ki Lee Jan 27 '20 at 20:50
  • @CarlosEduardoKiLee Yes. The one generated at Firebase console is pretty much useless in this case. – diidu Jan 28 '20 at 13:27
  • So this is not a Dynamic Link? Seems like Deep Link. – LacOniC Mar 03 '20 at 12:35
  • I don't understand, are we create new dynamic link for each invitation? – Taha Malik Jan 30 '21 at 18:45
  • @TahaMalik Hi, so are your create dynamic link for each invitation or you made some custom on it? – MNFS Sep 26 '22 at 23:51
  • @diidu let say I create dynamic link for e-commerce apps, should I create dynamic link for each product on fierbase console? – MNFS Sep 26 '22 at 23:51
  • @MNFS It is a while since I worked with dynamic links, some things have changed since then and I may not remember all the details, but I think it depends how you want to use the links. If you want the link to open specific app, you'll need different link for each app. Unless you are happy with Android popping up a list of apps for user to select and that only works with installed apps. There is no way to direct the link to multiple Play store pages. – diidu Sep 27 '22 at 09:30
  • Important if you want to pass more than one parameter: You have to encode your parameter list in URL e.g. `param1=123&param2=321` in `param1%3D123%26param2%3D321`. Link: https://emn178.github.io/online-tools/url_encode.html – THE-E Mar 04 '23 at 00:21
14

1) From https://console.firebase.google.com/ (no need for custom parameter here.)

enter image description here

2) Create link somewhere, f.e. on your confluence page (here we add our parameter):

https://PROJECTNAME.page.link/?link=https://PROJECTNAME.page.link/LINKNAME?PARAMETER=1&ofl=https://www.PROJECTNAME.com/

PARAMETER is your custom parameter.

ofl is a link where to go if click the link from another platform (PC, Mac).

3) Getting link data from android project Kotlin code:

Firebase.dynamicLinks
        .getDynamicLink(intent)
        .addOnSuccessListener { pendingDynamicLinkData ->
            val parameter: String =
                pendingDynamicLinkData?.link?.getQueryParameter("PARAMETER").orEmpty()
        }
Eugene P.
  • 926
  • 9
  • 12
  • That did not work for me. Maybe because I am using FirebaseDynamicLinks.getInstance() instead of Firebase.dynamicLinks? – Guilherme Oliveira Jun 03 '20 at 13:54
  • They have changed something (firebase guys). Now when constructing a link to click use LINKNAME?PARAMETER Instead of LINKNAME/?PARAMETER – Eugene P. Jul 23 '20 at 14:01
  • 2
    This worked for me in 2021. Make sure you add your custom params after the inner link, not at the end of the main link: https:////?link=https:///?PARAMETER=VALUE&apn= I was adding it after the apn, but apn is a parameter of the outer URL, and PARAMETER should be in the query of the inner URL under "link" – Aleksander Niedziolko Oct 29 '21 at 10:07
  • You can find your long-version dynamic link by clicking the ⋮ menu next to the link on the console, going in Link Details and using your 'Long Dynamic Link'. Add parameters to the inner link and they will come through in the app – Aleksander Niedziolko Oct 29 '21 at 10:10
  • It worth mentioning the source document for this https://firebase.google.com/docs/dynamic-links/create-manually – AmitP Sep 29 '22 at 15:24
  • @AmitP thanks. This page did not exist when I answered this question. – Eugene P. Sep 30 '22 at 09:23
9
  1. Create a dynamic link

    Enter image description here

  2. Go to link details

    Enter image description here

  3. Copy the long dynamic link and add your parameter in the link parameter of the URL, e.g., PARAMETER=132323

    https://link.projectname.com/?link=https://link.projectname.com/LINK?PARAMETER=132323&apn=com.projectname.app&afl=https://link.projectname.com/LINK

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sehrish Waheed
  • 1,230
  • 14
  • 17
8

If you want to use dynamic links with custom arguments with REST, here is an example of a payload:

{
  "dynamicLinkInfo": {
        "dynamicLinkDomain": "example.app.goo.gl",
        "link": "http://someurl.com?my_first_param=test&my_second_param=test2"
  },
  "suffix": {
     "option":"UNGUESSABLE"
    }
}

Make sure your remove 'https://' from your dynamicLinkDomain

Julien

JulienCoo
  • 1,128
  • 3
  • 13
  • 24
6

Case A. If you want the short link to expand to a link with multiple parameters:

In the part where you setup a dynamic link, any parameter you append to the deep link URL will go on all platforms (web, iOS, android) enter image description here

Case B. If you want to use dynamic parameters, you should use the api to create a short link

see documentation

Ted
  • 22,696
  • 11
  • 95
  • 109
5

Now you can create short links using the Firebase SDK through the FirebaseDynamicLinks.getInstance().createDynamicLink(): https://firebase.google.com/docs/dynamic-links/android/create

Sample code:

Task shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
    .setLink(Uri.parse("https://example.com/"))
    .setDynamicLinkDomain("abc123.app.goo.gl")
    // Set parameters
    // ...
    .buildShortDynamicLink()
    .addOnCompleteListener(this, new OnCompleteListener() {
        @Override
        public void onComplete(@NonNull Task task) {
            if (task.isSuccessful()) {
                // Short link created
                Uri shortLink = task.getResult().getShortLink();
                Uri flowchartLink = task.getResult().getPreviewLink();
            } else {
                // Error
            }
        }
    });
Shirane85
  • 2,255
  • 1
  • 26
  • 38
3

1 First Change your Dynamic Link in firebase console from http://exampleandroid/test to http://exampleandroid/test?data 2. You send the query paramter data with this

 DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
                   // .setLink(dynamicLinkUri)
                    .setLink(Uri.parse("http://exampleandroid/test?data=dsads"))
                    .setDomainUriPrefix("https://App_Name.page.link")
                    // Open links with this app on Android
                    .setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
                    // Open links with com.example.ios on iOS
                    .setIosParameters(new DynamicLink.IosParameters.Builder("com.appinventiv.ios").build())
                    .buildDynamicLink();

            dynamicLinkUri = dynamicLink.getUri();
Dishant Kawatra
  • 638
  • 7
  • 5
2

You can add extra parameter to your link to generate Short URL from Firebase. Here I given example of Short URL generation using Firebase API. Here ServiceRequestHelper(this).PostCall is my generic class to make API request

String url = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=YOUR_KEY";

    try {
        PackageManager manager = this.getPackageManager();
        PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
        JSONObject jsonObject = new JSONObject();
        JSONObject androidInfoObject = new JSONObject();
        androidInfoObject.put("androidPackageName", getApplicationContext().getPackageName());
        androidInfoObject.put("androidMinPackageVersionCode",String.valueOf(info.versionCode));

        JSONObject iosInfoObject = new JSONObject();
        iosInfoObject.put("iosBundleId", "tettares.Test_ID");
        JSONObject dynamicLinkInfoObj = new JSONObject();
        dynamicLinkInfoObj.put("dynamicLinkDomain", "wgv3v.app.goo.gl");
        dynamicLinkInfoObj.put("link", "https://test.in/?UserId=14&UserName=Naveen");  // Pass your extra paramters to here
        dynamicLinkInfoObj.put("androidInfo", androidInfoObject);
        dynamicLinkInfoObj.put("iosInfo", iosInfoObject);

        JSONObject suffixObject = new JSONObject();
        suffixObject.put("option" , "SHORT");
        jsonObject.put("dynamicLinkInfo", dynamicLinkInfoObj);
        jsonObject.put("suffix", suffixObject);

        Log.d("JSON Object : " , jsonObject.toString());

        new ServiceRequestHelper(this).PostCall(url, jsonObject, false, new CallBackJson() {
            @Override
            public void done(JSONObject result) throws JSONException {

                try {
                    if (result.has("shortLink")) {
                        DEEP_LINK_URL = result.getString("shortLink");                                                   }
                } catch(Exception e)
                {
                    e.printStackTrace();
                }

            }
        });


    } catch (JSONException | PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

In Your Receiving Activity:

boolean autoLaunchDeepLink = false;
    AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
            .setResultCallback(
                    new ResultCallback<AppInviteInvitationResult>() {
                        @Override
                        public void onResult(@NonNull AppInviteInvitationResult result) {
                            if (result.getStatus().isSuccess()) {
                                // Extract deep link from Intent
                                Intent intent = result.getInvitationIntent();
                                String deepLink = AppInviteReferral.getDeepLink(intent);

                                // Handle the deep link. For example, open the linked
                                // content, or apply promotional credit to the user's
                                // account.

                                // [START_EXCLUDE]
                                // Display deep link in the UI
                                Log.d(TAG, "deeplink URL: " + deeplink); // Here you get https://test.in/?UserId=14&UserName=Naveen
                                // [END_EXCLUDE]
                            } else {
                                Log.d(TAG, "getInvitation: no deep link found.");
                            }
                        }
                    });
Naveen Kumar M
  • 7,497
  • 7
  • 60
  • 74
1

I tried all above but none work. So I think you should change the link http://example.com/?userid=123tohttp://example.com/userid/123

chii
  • 2,111
  • 3
  • 17
  • 21
0

No need of all the hustle

  1. Don't shorten the url if you want to pass parameters
  2. Write the links like this.

    //APP_CODE is firebase link
    String link = "https://APP_CODE.app.goo.gl/?refferer=" + userId;
    
    Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
                    .setMessage(getString(R.string.invitation_custom_message)))
                    .setDeepLink(Uri.parse(link))
                    .setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
                    .setCallToActionText(getString(R.string.invitation_cta))
                    .build();
    
    startActivityForResult(intent, REQUEST_INVITE);
    
ElOjcar
  • 301
  • 2
  • 4
  • 12
Job M
  • 3,331
  • 2
  • 19
  • 26
0

For web apps, which generating dynamic links..

const data = {
  dynamicLinkInfo: {
    domainUriPrefix: 'subdomain.page.link',
    link: url,
  },
  suffix: {
    option: 'SHORT'
  }
};
return fetch(`https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=${environment.firebaseConfig.apiKey}`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(data),
}).then(res => res.json()).then(response => response.shortLink).catch(console.error);