Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 3679 - reporting with a 000000000000 matomo user id #3840

Merged
merged 11 commits into from
Apr 4, 2023
Merged

fix: 3679 - reporting with a 000000000000 matomo user id #3840

merged 11 commits into from
Apr 4, 2023

Conversation

sgtSeme4ki
Copy link
Contributor

What

  • If a user opts out from analytics then track with a 000000000000 user-id

Fixes bug(s)

Part of

@sgtSeme4ki sgtSeme4ki requested a review from a team as a code owner April 2, 2023 14:16
markdurst added 2 commits April 2, 2023 16:16
@github-actions github-actions bot added 📈 Analytics We use Sentry and Matomo, with an opt-in system 🧪 Tests labels Apr 2, 2023
Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Hi @sgtSeme4ki!
Please have a look at my quick review.

@@ -90,6 +89,8 @@ class AnalyticsHelper {

static String latestSearch = '';

static bool allow = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
static bool allow = false;
static bool _allow = false;

Comment on lines 124 to 125
version: '1.0.0',
buildNumber: '2.2.2',
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment if those are dummy values.

await AnalyticsHelper.initMatomo(isScreenshotMode);
// assert
final String? matomoUserId = matomoTrackerInstance.visitor.userId;
expect(matomoUserId, '0000000000000000');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(matomoUserId, '0000000000000000');
expect(matomoUserId, '0' * 16);

@sgtSeme4ki
Copy link
Contributor Author

@monsieurtanuki Thank you for the review, I tried to resolve anything as far as possible

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Hi @sgtSeme4ki, and thank you for your additional commits.
Please have a look at my comments; basically your code is good but I still have pending questions.

Comment on lines 151 to 158
// if user opts out then track anonymously with userId containg zeros
if (!_allow) {
return '0' * 16;
} else if (kDebugMode) {
return 'smoothie_debug--';
} else {
return OpenFoodAPIConfiguration.uuid;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// if user opts out then track anonymously with userId containg zeros
if (!_allow) {
return '0' * 16;
} else if (kDebugMode) {
return 'smoothie_debug--';
} else {
return OpenFoodAPIConfiguration.uuid;
}
if (kDebugMode) {
return 'smoothie_debug--';
}
// if user opts out then track anonymously with userId containg zeros
if (!_allow) {
return '0' * 16;
}
return OpenFoodAPIConfiguration.uuid;

I believe we want to track "real users", not developers debugging.
That's why I would put the kDebugMode check first.
In addition to that I don't like elses so as we return we can get rid of them, but it's just a matter of personal taste.
The most important here is to check kDebugMode first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If kDebugMode is checked first, the test always fails, because tests are always run in debug mode (always returns "smoothie_debug--". Do you have an idea how to overcome this? My first thought was setting an env-variable like TEST_MODE in the test and checking for it in the "get uuid"-method, but this seems dirty to me. But honestly I can't come up with something better.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand your point, but you seem to be more interested in the test than in the code.
The code should match our needs, and that's why I would put the kDebugMode check first.

If there's no way to test it properly, let's not test it. Especially in that case, it's just a if we're checking. Of course a test would be better; it's not essential.

If really you insist, perhaps you could use @visibleForTesting. But I wouldn't put too much effort into it, and I would discard the test altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your input. Am always interested in tests, because I come from a strict TDD-Household and the guys at the company I work in regard the tests as holy ;). But the most pragmatic way is to drop the test and it probably isn't worth it for like just 5 lines of code. I removed the test and the mockPackageInfo().

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's be pragmatic 😉

sgtSeme4ki and others added 7 commits April 3, 2023 21:51
Co-authored-by: monsieurtanuki <fabrice_fontaine@hotmail.com>
Co-authored-by: monsieurtanuki <fabrice_fontaine@hotmail.com>
Co-authored-by: monsieurtanuki <fabrice_fontaine@hotmail.com>
Co-authored-by: monsieurtanuki <fabrice_fontaine@hotmail.com>
Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Thank you @sgtSeme4ki and congratulations for your first contribution here!

@monsieurtanuki monsieurtanuki merged commit 54560ff into openfoodfacts:develop Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📈 Analytics We use Sentry and Matomo, with an opt-in system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reporting with a 000000000000 matomo user id
2 participants