2

When I create dynamic links which contain UTM parameters and share it, I was able to retrieve the data and encoded queries from the link. But when I try to create a short link of a dynamic link using firebase recommended method, I can only able to retrieve the path, but not the encoded queries. how do I solve it?

METHOD FOR CREATING DYNAMIC LINK :

public void buildReferral() {
    DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLink(Uri.parse("sample link"))
            .setDynamicLinkDomain("sample domain")
            .setAndroidParameters(
                    new DynamicLink.AndroidParameters.Builder("com.package.my")
                            .build())
            .setGoogleAnalyticsParameters(
                    new DynamicLink.GoogleAnalyticsParameters.Builder()
                            .setSource("referral")
                            .setContent("content")
                            .setMedium("Android")
                            .build())
            .buildDynamicLink();
    buildShortUrl(dynamicLink);
}

METHOD FOR CREATING SHORT LINK :

 public void buildShortUrl(DynamicLink dynamicLink) {
    Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLongLink(Uri.parse(dynamicLink.getUri().toString()))
            .buildShortDynamicLink()
            .addOnCompleteListener(this, new OnCompleteListener<ShortDynamicLink>() {
                @Override
                public void onComplete(@NonNull Task<ShortDynamicLink> task) {
                    if (task.isSuccessful()) {
                        // Short link created
                        Uri shortLink = task.getResult().getShortLink();
                        Uri flowchartLink = task.getResult().getPreviewLink();
                    } else {
                        // Error
                        // ...
                    }
                }
            });
}
  • How are you sharing the shortened link? Passing it to `AppInviteInvitation.IntentBuilder().setDeepLink()`? – Bob Snyder May 20 '18 at 19:38
  • Intent intent = new AppInviteInvitation.IntentBuilder("Share via") .setMessage(getString(R.string.referral_text)) .setDeepLink(shortLinkUri) .setCallToActionText("Install") .build(); startActivityForResult(intent, 100); this is how the short link is shared. @BobSnyder – Aswathaman Ragunathan May 21 '18 at 14:51
  • My experience has been that AppInvite shortens the link you pass to `setDeepLink()`. I don't think there is any value in you shortening it before passing to `setDeepLink()`. I am able to send a long link with params, see the short link received, and extract the params from the URI in the received dynamic link data. – Bob Snyder May 21 '18 at 15:16
  • I was not able to invite users via WhatsApp using firebase invites. hence I thought of shortening the link and sharing it via Intent normally to WhatsApp. Is there a way to share links to WhatsApp using firebase? – Aswathaman Ragunathan May 21 '18 at 15:25
  • I don't know about WhatsApp. I would guess that you could shorten the link as you are doing and embed it in a text message. In my app, if the user wants to send a dynamic link using Firebase Invites, I send the long link. Or the user can share the link using SMS or email. For those cases, I shorten the link as you are doing. – Bob Snyder May 21 '18 at 15:34

1 Answers1

1

You can use appendQueryParameter() to add multiple parameters to the link, and by using getQueryParameter() you can retrieve parameters from link. You can see this answer how you can achieve it.

Rohit Maurya
  • 730
  • 1
  • 9
  • 22
  • Thanks for the answer, but I want to get the parameters passed here, not which I pass using appendQuery() - .setGoogleAnalyticsParameters( new DynamicLink.GoogleAnalyticsParameters.Builder() .setSource("referral") .setContent("content") .setMedium("Android") .build()) – Aswathaman Ragunathan May 21 '18 at 15:07