Repository navigation
feat(analytics): Tracking takes the Analytics service; start() replaces enableAllAutoTracking - #1986
Merged
Merged
Conversation
…mitter
The tracking helpers took an emitter callback, so every caller hand-wrote the
same adapter to createEvent: supply the required url, and flatten props into
the alternating key/value list the endpoint takes. That conversion now lives
inside the helper, which is constructed from the generated service and the
property id the events path requires.
- Web: AnalyticsTracking -> Tracking(analytics, propertyId, options?);
AnalyticsTrackingOptions -> TrackingOptions, AnalyticsEventOptions ->
TrackingEventOptions; AnalyticsEventEmitter removed. url defaults to the
current page.
- Flutter: AnalyticsTracking -> Tracking(analytics, propertyId, {url}),
AnalyticsObserver -> TrackingObserver(tracking); AnalyticsEventEmitter
removed. Files renamed to tracking.dart / tracking_observer.dart. Screen
names resolve against a base url (page origin on web, app://<platform>
elsewhere) since the endpoint only accepts absolute URLs.
The requires gating from #1977 is unchanged.
start() covers the same default set as before: pageviews, outbound links, scroll depth and engagement time on web, lifecycle events on Flutter. Downloads (web) and route tracking (Flutter) stay opt-in.
🟢 Tier S · Ready to mergeThe tracking helpers now accept the generated Analytics service and property ID directly, with
📂 Walkthrough · 7
Reviewed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Review asked that the tracking helper take the analytics service directly:
Before this, the helpers took an emitter callback. Every caller hand-wrote the same adapter to
createEvent: pass the requiredurl, and flattenpropsinto the alternating key/value list the endpoint takes. That adapter now lives inside the helper, which is built from the generated service and the property id the events path requires.Renames
new AnalyticsTracking(emitter, options?)new Tracking(analytics, propertyId, options?)AnalyticsTrackingOptionsTrackingOptionsAnalyticsEventOptionsTrackingEventOptionsAnalyticsEventEmitterenableAllAutoTracking()start()AnalyticsTracking(emitter)Tracking(analytics, propertyId, {url})AnalyticsObserver(...)TrackingObserver(tracking)AnalyticsEventEmitterenableAllAutoTracking()start()lib/src/analytics_tracking.dart,lib/src/analytics_observer.dartlib/src/tracking.dart,lib/src/tracking_observer.dartThe granular
enableAuto*/disableAuto*methods are unchanged.start()turns on the same setenableAllAutoTracking()did:enableAutoDownloadTracking(), because the list of file extensions depends on the app.TrackingObserver.The observer keeps the
Trackingprefix because a bareObserverreads as aNavigatorObserver. It takes theTrackinginstance, so the property id and base url are configured once.Flutter URLs
The endpoint only accepts absolute URLs. Screen names now resolve against a base url: the page origin on Flutter web, and
app://<platform>everywhere else. Passurl:to the constructor to override it.Gating
The
requires: analyticsgating from #1977 is unchanged.GenerationTest::testAnalyticsCompanionsFollowTheServicestill generates against a spec without the analytics service, and confirms the helpers are left out there and shipped when the service is present.Compatibility
This is a breaking change for published prereleases. The following ship
AnalyticsTrackingandenableAllAutoTracking(), and code written against them will not compile on an SDK generated from this branch:appwrite@28.2.0-rc.4(checked from the registry tarball)@appwrite.io/console@18.3.0-rc.2(checked from the registry tarball)appwrite@27.1.0-rc.1andappwrite@27.1.0-rc.4, which shiplib/src/analytics_tracking.dartandlib/src/analytics_observer.dart. I checked the archives downloaded from pub.dev.27.1.0-rc.2,-rc.3and-rc.7have no analytics service, so they ship no helpers. No older pub prerelease ships them.We accept this because these are all prereleases and the only consumer we know of is our own.
Coupled change: refetch
refetch (refetch-io/refetch) pins
appwrite@28.2.0-rc.4. Itslib/analytics.tsusesAnalyticsTrackingwith the emitter, so refetch must be updated at the same time as the first SDK release that includes this change. A follow-up refetch PR will switch it tonew Tracking(analytics, propertyId).start()plusenableAutoDownloadTracking().Test Plan
vendor/bin/phpunit tests/generation/GenerationTest.php: 95 tests and 1245 assertions pass. 4 tests are skipped, all for languages with nothing to check (for example, cli declares no enums).php example.php web client, real 2.3.x spec with the analytics service):npm ci,format:check,lint,analyse(tsc --noEmit) andbuildall pass.php example.php flutter client, Flutter 3.47.1):flutter analyze lib/src/tracking.dart lib/src/tracking_observer.dartreports no issues in either file.flutter analyzereports no errors. Every warning and info it reports comes from existing generated code or tests, none from these files.dart format --set-exit-if-changedleaves the tracking files unchanged.composer lintandcomposer refactor:check(Rector) pass.Related PRs and Issues