department-of-veterans-affairs / va-mobile-app

"If VA were a company, it would have a flagship mobile app."
https://department-of-veterans-affairs.github.io/va-mobile-app/
10 stars 1 forks source link

CU - Capture Campaign Analytics in Firebase #7548

Closed dumathane closed 3 months ago

dumathane commented 7 months ago

Description

We want to know which users are navigating to the VA-Mobile-App from specific campaign urls to gauge effectiveness.

As part of this story we want to:

Acceptance Criteria

- [ ] Confirm we are capturing these analytics with a test campaign URL ## Notes & Open Questions -Old UA Link for [this](https://support.google.com/analytics/answer/3389142?hl=en#zippy=%2Cin-this-article). -Potential Google Analytics [solution](https://support.google.com/analytics/answer/9353532?sjid=6444765686374521066-NC). -Other Greta [Link](https://medium.com/firebase-developers/firebase-traffic-source-attribution-guide-287d7de80d76). -lmgtfy.com/HowToCampaignAnalyticForDummies - Dependencies/Roadblocks: - Any internal/external dependencies? - Test accounts needed? - Does this require QA? - Dev Notes: ## Ticket Checklist - [ ] Acceptance criteria defined - [ ] Labels added (front-end, back-end, feature) - [ ] Linked to an Epic
theodur commented 6 months ago

Google sunsetted the mobile API for sending data directly to Google Analytics, so everything is done via Firebase now. After looking into whether campaign analytics are automatically captured, it looks like they aren't automatically captured with the React Native Firebase library as they are with the official Google Firebase Analytics SDK. This means we need to manually log them in the app.

React Native Firebase has a logCampaignDetails event that can log the campaign parameters in Firebase. This will log the event as campaign_details. The important parameters we'd need to track from the URL are utm_source, utm_medium, and utm_campaign.

We can then mark campaign_details as a conversion event in Firebase, and it should be synced with Google Analytics

theodur commented 6 months ago

The PR for implementing logging of campaign links is completed and merged ✅. There isn't anything for QA to verify since it's just adding analytics

theodur commented 5 months ago

I tested my implementation in prod, and it turns out the campaign link tracking wasn't working. After looking into the issue, the reason it wasn't working is due to how the Play Store launches apps when the user taps the "Open" button from the Play store listing. Instead of launching the app via a deep link, it launches it via an intent.

In order to track campaign analytics, we would need access to the Play Install Referrer Library which is only available in the native Android API. This API can tell us information about the user's install, which includes most importantly the referrer URL (campaign link) that was used to install the app. I started working on a native module for accessing the install referrer API and created a draft PR for it. One important thing to note is the referrer URL will remain the same for up to 90 days or until the user uninstalls the app and re-installs it from a different campaign URL.

After speaking with @ajsarkar28, we decided it may be worthwhile to try using Firebase Dynamic Links until we migrate to a more permanent solution. The reason being it handles the functionality that we're looking for in tracking campaign links by:

Unfortunately, Firebase Dynamic Links will be deprecated on August 25, 2025, so we would eventually need to migrate to a new service that handles the functionality of Dynamic Links. The caveat is these services are mainly subscription based, but a few popular ones are Branch, URLgenius, and AppsFlyer.

I was able to create a test dynamic link in our Firebase console: https://vamobileapp.page.link/qbvQ I tested the functionality, and it seems to work well. I won't be able to test launching iOS users until I'm able to add the Apple Team ID in the project setting, which I'll be able to get with the help of Binny tomorrow. I don't have any doubts that it'll work correctly for iOS also once we're able to test that out.

The domain of the test dynamic link I created is a Google provided one, but we also have the ability to use our own domain for dynamic links, e.g. va.gov. There's manual configuration needed in order to use your own domain for Dynamic Links, so there'd be some extra work there. Using the va.gov domain may or may not be worth it since we'd be using Dynamic Links as a temporary solution.

The dynamic link I created in the console can be viewed here: https://console.firebase.google.com/project/va-mobile-app/durablelinks/links

theodur commented 5 months ago

After adding the Team ID to the Firebase project, the dynamic link is launching users to the app store if they don't have the app installed. It seems like this is working as expected for the most part. The only issue I'm noticing is that when an iOS user has the app installed, the link won't launch the app, but still opens the app store. This may be a Firebase bug, since they don't actively maintain/support Dynamic Links since they're being deprecated soon, but I think the functionality as is should be enough for now, especially since we'll need to migrate to a new system anyway.

Android:

App installed on device:

https://github.com/department-of-veterans-affairs/va-mobile-app/assets/9042882/7729ba7d-baf9-4243-a545-8c7315ba8acc

App not installed on device:

https://github.com/department-of-veterans-affairs/va-mobile-app/assets/9042882/e9c076db-c773-4960-8137-4d0c70606bfa

iOS:

https://github.com/department-of-veterans-affairs/va-mobile-app/assets/9042882/912e69c2-5084-42cb-8a5c-f6f6c5f670f6

theodur commented 5 months ago

Even though there's no code that needs to be reviewed, I'm moving this ticket into the Code Review lane to signify it's ready for review by @ajsarkar28. I'll plan to sync with Ameet when he's back in

theodur commented 4 months ago

After further testing of Dynamic links, we noticed metrics like First open, Re-Opens, App Installs weren't being logged in the Firebase console. This was due to Dynamic links not being configured in the app. I made a PR for configuring it, and tested that the metrics above are being logged, except for App Installs, because I can't install a test build from opening a Dynamic link. We'll need to wait until it's released to prod to make sure the App Installs metric is being tracked.

Other than that, this seems like it's working as it should. Since we already have BigQuery integrated with the Firebase project, Dynamic Link metrics should be available to query in BigQuery.

theodur commented 4 months ago

The PR has been approved and merged. No QA testing is needed, so this is good to close

TKDickson commented 4 months ago

The first iOS on-demand build I tried from the new branch/PR was not successful. Running it again.

TKDickson commented 4 months ago

iOS build referenced above failed twice, moving back to in-progress. Also, @theodur when this ticket comes back into QA can you please include a "this is why the builds were failing and why they will be working now" explanation? Thanks!

My brain only remembers "something something something maybe environments in firebase" as the explanation I've heard verbally.

theodur commented 4 months ago

@TKDickson The PR for this had to be merged into develop in order for us to update the certificates. We were able to update them this afternoon, and ran a successful build afterward ✅ so no more broken iOS builds. Now, we just need to wait until this gets released to the app store to test Dynamic Links with the app store app. I tested it locally during the development of my PR, and it worked as expected, so I'm confident it'll work once released

theodur commented 4 months ago

@ajsarkar28 Based on my comment above, do you want to keep this ticket open until this gets released to the app store (3/26) and we can test this on prod, or can we close this and test it on prod asynchronously after the release?

ajsarkar28 commented 4 months ago

@theodur let's keep it open

TKDickson commented 4 months ago

I moved it to the 'with QA' column to at least indicate that it's in develop (and therefore will be in the release branch)

theodur commented 3 months ago

When testing Dynamic Links after the 3/26 release, we discovered the links (vamobileapp.page.link) weren't opening the app on iOS when the app is installed on the device. This issue was impacting physical devices, but not simulators.

After LOTS of research, I came across the Universal Links diagnostics tool in the developer settings of the device, and discovered that the app ID that's associated with our app wasn't the same as the app ID specified in the apple-app-site-association (file that's required for Universal and Dynamic Links) that's hosted at the Dynamic Link domain. The app ID associated with the app from the app store follows the format: APP_PREFIX.gov.va.mobileapp as opposed to the format of the app ID in the hosted file: TEAM_ID.gov.va.mobileapp. The confusing thing is the Firebase console only has a place for the team ID in the iOS app settings and not the app prefix. I updated the team ID in the console to be the app prefix, and that seems to have fixed the problem. Good thing is this didn't require any code changes from us, as the apple-app-site-association file changes happen on the BE of Firebase.

I confirmed all use cases of Dynamic links for iOS and Android work as expected:

This ticket should be good to close now, but I'll sync with @ajsarkar28 to recap and confirm before closing