1

I want to get the event of New install or App open/re-open events in my Android App whenever user click on any dynamic link.

Following events are captured in Analytics as per documentation:

dynamic_link_first_open

dynamic_link_app_open

But I can't find any way to get these from sample listener.

Anukool srivastav
  • 807
  • 1
  • 12
  • 20

1 Answers1

1

I have found solution to my above question. Sharing details here.

Below code is tested from PlayStore also.

You can get mentioned two events through pendingDynamicLinkData callback object received from addOnSuccessListener.

Complete code to get link and associated Dynamic link data here.

FirebaseDynamicLinks.getInstance()
                .getDynamicLink(getIntent())
                .addOnSuccessListener(this, pendingDynamicLinkData -> {
                    // Get deep link from result (may be null if no link is found)
                    try {
                        Uri deepLink = null;
                        if (pendingDynamicLinkData != null) {
                            deepLink = pendingDynamicLinkData.getLink();

                            sendInstallDetailToAPI(pendingDynamicLinkData.getExtensions());

                        }
                        CgUtils.showLog(TAG, "getDynamicLink:onSuccess" + deepLink);
                    } catch (Exception e) {
                        CgUtils.showLog(TAG, "getDynamicLink:onFailure" + e);
                    }

                })
                .addOnFailureListener(this, e -> CgUtils.showLog(TAG, "getDynamicLink:onFailure" + e));

Below method to send the Dynamic Link data to your backend API if you want.

private void sendInstallDetailToAPI(Bundle deepBundle) {

      
        Bundle deepLinkData = deepBundle.getBundle("scionData");
        if (deepLinkData != null) {
            Bundle appReOpenBundle = deepLinkData.getBundle("dynamic_link_app_open");
            boolean isInstall = false;
            String medium = "", source = "", campaign = "", shortLink = "";
            if (appReOpenBundle != null) {
                medium = appReOpenBundle.getString("medium", "NA");
                source = appReOpenBundle.getString("source", "NA");
                campaign = appReOpenBundle.getString("campaign", "NA");
                shortLink = appReOpenBundle.getString("dynamic_link_link_id", "NA");
            }

            Bundle appFirstOpenBundle = deepLinkData.getBundle("dynamic_link_first_open");

            if (appFirstOpenBundle != null) {
                isInstall = true;
                medium = appFirstOpenBundle.getString("medium", "NA");
                source = appFirstOpenBundle.getString("source", "NA");
                campaign = appFirstOpenBundle.getString("campaign", "NA");
                shortLink = appFirstOpenBundle.getString("dynamic_link_link_id", "NA");
            }

        // Send ABOVE detail to your respective APIs


        }
    }

Now If isInstall flag is true that means it's first time open after install else reopen.

Anukool srivastav
  • 807
  • 1
  • 12
  • 20
  • hi @Anukool, I am using Kotlin, I've tried your code with adjustment related to kotlin, but I got empty when getting the pendingDynamicLInkData.extension. what do you think I am missing? other than that the dynamic link is working normal – M.R. Murazza Mar 22 '22 at 11:48
  • I am getting campaign, medium, source blank, can you share any sample url for passing these params. – Himanshu Apr 26 '23 at 04:40