Skip to content

Asserts added to check all relevant GA4 limitations #96

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

Merged
merged 20 commits into from
May 31, 2023

Conversation

eliasyishak
Copy link
Contributor

Addresses:

Asserts added (and can be turned on from factory constructors) to check against GA4 limitations. By default Analytics() constructor will have asserts disabled and the Analytics.development() constructor will have them enabled


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.

Contribution guidelines:

Many Dart repos have a weekly cadence for reviewing PRs - please allow for a week or two of latency for initial review feedback.


@eliasyishak eliasyishak marked this pull request as ready for review May 24, 2023 19:14
@eliasyishak eliasyishak requested a review from bwilkerson May 24, 2023 19:15
@eliasyishak
Copy link
Contributor Author

@bwilkerson this contains asserts that should enable us to find any events that are breaking GA4's limitations as we discussed last week. I suggest that we internally set the enableAssert (the Analytics.development(...) constructor will have this enabled by default) to true when developing to ensure our events can send.

@@ -511,6 +532,8 @@ class TestAnalytics extends AnalyticsImpl {
userProperty: userProperty,
);

if (_enableAsserts) checkBody(body);
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the reasoning behind adding a separate flag when the VM already has a flag that serves the same purpose.

You could just as easily have removed the field _enableAsserts, changed checkBody to always return true, and written

assert(validBody(body));

It wouldn't need a message because it will always explicitly throw an exception when the body isn't valid.

Anyway, that seems much cleaner, and means that

  • anyone can enable the checks when there's a need for it without having to write code that passes in the flag, and
  • we can't ever accidentally leave the assert enabled in production code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm that's interesting, is this also the same behavior for the flutter tool? I was only made aware of this flag recently and didn't think that it was implemented for the flutter cli.

If i'm wrong, I'm happy to refactor this PR

Copy link
Member

Choose a reason for hiding this comment

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

I don't know whether the flutter CLI supports passing additional flags to the VM. It's quite possible that it doesn't, because I believe it's produced by an AOT compilation, so the asserts are probably already stripped out.

Are we planning to add flags to the dart and flutter commands to allow a different value of the flag to be passed it? If so, then we should leave it as is. If not, then it isn't clear that the current structure has value.

I guess I'm just too accustomed to running from source, or at least from a snapshot, where the flag can still be passed in at runtime.

As with all of my feedback, use you best judgement about whether to change the code or ignore the feedback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How we use this new flag will need to be discussed, the purpose of this PR was to have the code ready to be used in what we decide as a team.

But to continue using the --enable-asserts flag from dart, we could set this flag in the Analytics constructor to true if that flag was detected when run through the dart cli command... and on the flutter side, we can determine another approach since we don't have --enable-asserts for the flutter cli

@github-actions github-actions bot added the type-infra A repository infrastructure change or enhancement label May 30, 2023
@eliasyishak eliasyishak merged commit a436fee into dart-lang:main May 31, 2023
@eliasyishak eliasyishak deleted the 94-asserts-for-dev-constructor branch May 31, 2023 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:unified_analytics type-infra A repository infrastructure change or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants