Skip to content

Simplify Analytics configuration#2410

Merged
MiSikora merged 9 commits intomainfrom
task/refactor-tracking
Jun 28, 2024
Merged

Simplify Analytics configuration#2410
MiSikora merged 9 commits intomainfrom
task/refactor-tracking

Conversation

@MiSikora
Copy link
Contributor

@MiSikora MiSikora commented Jun 28, 2024

Description

I'm doing this work to make my work with clip analytics easier.

We had a strange configuration of object AnalyticsTracker and class AnalyticsTrackerWrapper. The first one was used to register all trackers and the latter one was used for DI but it was a bit clunky to use because it called object AnalyticsTracker inside.

This PR removes object AnalyticsTracker and uses proper DI for class AnalyticsTracker. Previously DI was impossible because there was a cyclic dependency, which I had to break in this PR by introducing AccountManagerStatusInfo. The PR also decouples it from Settings making testing a bit easier without a need for mocks.

You can ignore 6605bba as it is just a renaming PR. The meat of the PR is in f399dc9.

Testing Instructions

  1. Open the app as the unsigned user and verify that tracking works.
  2. Analytic events should have "user_is_logged_in":false property.
  3. Sign in.
  4. Analytic events should have "user_is_logged_in":true property. Signing out at this point will fail to reflect the property change (User logged in status is cached #2409).
  5. You can verify in the network inspector that user ID (_ui) is still correctly tracked. However user type will be incorrect due to this bug - Fix all Simplenote users and Pocket Cast users being set to Day One users Automattic-Tracks-Android#223.
    Screenshot 2024-06-28 at 10 43 33
  6. Go to privacy settings and disable Analytics.
  7. Notice that events are no longer tracked.

Checklist

  • If this is a user-facing change, I have added an entry in CHANGELOG.md
  • Ensure the linter passes (./gradlew spotlessApply to automatically apply formatting/linting)
  • I have considered whether it makes sense to add tests for my changes
  • All strings that need to be localized are in modules/services/localization/src/main/res/values/strings.xml
  • Any jetpack compose components I added or changed are covered by compose previews
  • I have updated (or requested that someone edit) the spreadsheet to reflect any new or changed analytics.

I have tested any UI changes...

  • with different themes
  • with a landscape orientation
  • with the device set to have a large display and font size
  • for accessibility with TalkBack

@MiSikora MiSikora added the [Area] Analytics Analytics related issues label Jun 28, 2024
@MiSikora MiSikora added this to the 7.68 milestone Jun 28, 2024
@MiSikora MiSikora requested a review from a team as a code owner June 28, 2024 09:16
@MiSikora MiSikora requested review from geekygecko and removed request for a team June 28, 2024 09:16
@dangermattic
Copy link
Collaborator

dangermattic commented Jun 28, 2024

2 Warnings
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ Class AccountManagerStatusInfo is missing tests, but unit-tests-exemption label was set to ignore this.

Generated by 🚫 Danger

Comment on lines -124 to -126
private fun setupAnalytics() {
AnalyticsTracker.init(settings)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that Automotive app unlike Phone and Wear apps does not refresh trackers metadata here. I'm not sure if it is a bug but I kept previous behavior.

AnalyticsTracker.register(tracksTracker, bumpStatsTracker)
AnalyticsTracker.init(settings)
AnalyticsTracker.refreshMetadata()
analyticsTracker.clearAllData()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the old logic also cleared the data. Do you know why we do that? I was wondering if that would clear events that should be sent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? I don't know. I think it would be better to leave it for another PR to know what should be done here.

@MiSikora MiSikora merged commit 76e40d3 into main Jun 28, 2024
@MiSikora MiSikora deleted the task/refactor-tracking branch June 28, 2024 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants