Firebase Dynamic Link New Install Events

Viewed 677

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.

1 Answers

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.

Related