analytics_flutter
analytics_flutter copied to clipboard
Context app version wrong on Flutter web
Segment is receiving AppleWebKit version instead of the app version in flutter web.
Here are 2 event contexts received, one from Flutter mobile and the other from Flutter web.
Mobile:
"context": { "app": { "build": "120", "name": "APPNAME", "namespace": "com.APP.APPNAME", "version": "1.5.30" },
Web:
"context": { "app": { "build": "", "name": "Netscape", "namespace": "Mozilla", "version": "5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" },
Thanks!
We are working on this.
Please update to version 1.1.7.
In a Flutter web app, the pubspec.yaml file isn't directly accessible at runtime—especially from within client-side browser code—since it's a build-time configuration. Hence till version 1.1.6, the following line in analytics_web.dart:
version: web.window.navigator.appVersion
used to return the browser version string, not the app's version from pubspec.yaml. In a web app, to make the app's version available at runtime, we need to manually expose it.
In version 1.1.7, the line version: web.window.navigator.appVersion has been replaced with version: getAppVersion() method in analytics_web.dart. This method looks for <meta name="app-version" content="1.2.3"> in <project-root>/web/index.html and return the value inside 'content' attribute. This method returns the browser version as fallback.