58

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.

1
  • 1
    Denny, have you get the solution for this? Same scenario I am facing. Commented Aug 9, 2021 at 5:08

11 Answers 11

58
+150

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.

Sign up to request clarification or add additional context in comments.

14 Comments

@diidu how can i use in c#? please help
@BrijeshMavani I am not expert with C#, but my answer is completely language independent, so you can use it in any language.
I tried in this way: https://<my app>.app.goo.gl/?link=example.com/[email protected] This is giving shortlink as https://<my app>.app.goo.gl/abcd, after decoding this short url it is coming like https://<my app>.app.goo.gl/?link=example.com/?name=test?email%[email protected] %3D is coming in place of = after decoding it.
@OliverDixon You don't. You change it on the long url and generate a short one if needed.
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: emn178.github.io/online-tools/url_encode.html
|
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()
        }

6 Comments

That did not work for me. Maybe because I am using FirebaseDynamicLinks.getInstance() instead of Firebase.dynamicLinks?
They have changed something (firebase guys). Now when constructing a link to click use LINKNAME?PARAMETER Instead of LINKNAME/?PARAMETER
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://<domain>/<path>/?link=https://<domain>/<path>?PARAMETER=VALUE&apn=<appId> 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"
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
It worth mentioning the source document for this firebase.google.com/docs/dynamic-links/create-manually
|
12
  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

2 Comments

this was the right answer to me (in 2022), you have to pay attention to the whole long link and put your custom parameter at the place of PARAMETER on above URL
though it does redirect, it did not forward the custom parameters for a web url
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

2 Comments

and how do you retrieve it on the receiving side? thanks.
After decoding the short URL, params afrer & symbol is not coming
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

3 Comments

But then customParam1 will always be 'abc' when passed to the app. How can this be dynamic?
@Silas did you find the solution, or know how to achieve dynamic parameters?
@Silas were you able to achieve dynamic parameters?
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
            }
        }
    });

Comments

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();

Comments

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.");
                            }
                        }
                    });

Comments

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

Comments

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);
    

Comments

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.