Skip to content

Commit 32188fc

Browse files
Merge pull request #2011 from appwrite/CLO-4195-flutter-viewport-width
Send viewport width from Flutter tracking events
2 parents 54d863c + 24ef908 commit 32188fc

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎templates/flutter/lib/src/tracking.dart.twig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class Tracking with WidgetsBindingObserver {
127127
url == null
128128
? this.url
129129
: Uri.parse(this.url).resolve(url).toString(),
130+
screenWidth: _viewportWidth(),
130131
engagementTime: engagementTime,
131132
// The endpoint takes props as a flat alternating key/value list.
132133
props:
@@ -141,6 +142,16 @@ class Tracking with WidgetsBindingObserver {
141142
}
142143
}
143144

145+
// The endpoint buckets this as viewport width in logical pixels, matching
146+
// the Web helper's `innerWidth`, so physical width is divided by the ratio.
147+
int? _viewportWidth() {
148+
final view = PlatformDispatcher.instance.implicitView;
149+
if (view == null || view.physicalSize.width == 0) {
150+
return null;
151+
}
152+
return (view.physicalSize.width / view.devicePixelRatio).round();
153+
}
154+
144155
/// Mobile-idiomatic screen-view shortcut. Renders as a `screen_view`
145156
/// analytics event with `screen`, optional `screenClass` and any
146157
/// caller-supplied properties. [name] is also the event URL's path.

0 commit comments

Comments
 (0)