mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-26 16:46:51 +08:00
Analytics: Port to null safety
This commit is contained in:
@ -1,8 +1,5 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:io' show Platform;
|
import 'dart:io' show Platform;
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:device_info/device_info.dart';
|
import 'package:device_info/device_info.dart';
|
||||||
@ -138,8 +135,6 @@ String _eventToString(Event e) {
|
|||||||
case Event.AppUpdate:
|
case Event.AppUpdate:
|
||||||
return "gj_app_update";
|
return "gj_app_update";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "unknown_event";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Analytics {
|
class Analytics {
|
||||||
@ -147,7 +142,7 @@ class Analytics {
|
|||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
|
|
||||||
Future<void> log({
|
Future<void> log({
|
||||||
@required Event e,
|
required Event e,
|
||||||
Map<String, String> parameters = const {},
|
Map<String, String> parameters = const {},
|
||||||
}) async {
|
}) async {
|
||||||
String name = _eventToString(e);
|
String name = _eventToString(e);
|
||||||
@ -164,14 +159,14 @@ class Analytics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setCurrentScreen({@required String screenName}) async {
|
Future<void> setCurrentScreen({required String screenName}) async {
|
||||||
if (Platform.isAndroid || Platform.isIOS) {
|
if (Platform.isAndroid || Platform.isIOS) {
|
||||||
await firebase.setCurrentScreen(screenName: screenName);
|
await firebase.setCurrentScreen(screenName: screenName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setUserProperty(
|
Future<void> setUserProperty(
|
||||||
{@required String name, @required String value}) async {
|
{required String name, required String value}) async {
|
||||||
if (Platform.isAndroid || Platform.isIOS) {
|
if (Platform.isAndroid || Platform.isIOS) {
|
||||||
await firebase.setUserProperty(name: name, value: value);
|
await firebase.setUserProperty(name: name, value: value);
|
||||||
}
|
}
|
||||||
@ -203,7 +198,7 @@ class AnalyticsRouteObserver extends RouteObserver<PageRoute<dynamic>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
|
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
||||||
super.didPush(route, previousRoute);
|
super.didPush(route, previousRoute);
|
||||||
if (route is PageRoute) {
|
if (route is PageRoute) {
|
||||||
_sendScreenView(route);
|
_sendScreenView(route);
|
||||||
@ -213,7 +208,7 @@ class AnalyticsRouteObserver extends RouteObserver<PageRoute<dynamic>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didReplace({Route<dynamic> newRoute, Route<dynamic> oldRoute}) {
|
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
|
||||||
super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
|
super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
|
||||||
if (newRoute is PageRoute) {
|
if (newRoute is PageRoute) {
|
||||||
_sendScreenView(newRoute);
|
_sendScreenView(newRoute);
|
||||||
@ -223,7 +218,7 @@ class AnalyticsRouteObserver extends RouteObserver<PageRoute<dynamic>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didPop(Route<dynamic> route, Route<dynamic> previousRoute) {
|
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
||||||
super.didPop(route, previousRoute);
|
super.didPop(route, previousRoute);
|
||||||
if (previousRoute is PageRoute && route is PageRoute) {
|
if (previousRoute is PageRoute && route is PageRoute) {
|
||||||
_sendScreenView(previousRoute);
|
_sendScreenView(previousRoute);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
@ -8,33 +8,33 @@ import 'package:device_info/device_info.dart';
|
|||||||
// - https://support.google.com/firebase/answer/6317485?hl=en
|
// - https://support.google.com/firebase/answer/6317485?hl=en
|
||||||
|
|
||||||
class Event {
|
class Event {
|
||||||
DateTime date;
|
DateTime? date;
|
||||||
String name;
|
String? name;
|
||||||
Map<String, dynamic> params;
|
Map<String, dynamic>? params;
|
||||||
|
|
||||||
String userId;
|
String? userId;
|
||||||
String psuedoId;
|
String? psuedoId;
|
||||||
Map<String, dynamic> userProperties;
|
Map<String, dynamic>? userProperties;
|
||||||
|
|
||||||
// Unique session identifier (based on the timestamp of the session_start
|
// Unique session identifier (based on the timestamp of the session_start
|
||||||
// event) associated with each event that occurs within a session
|
// event) associated with each event that occurs within a session
|
||||||
String sessionID;
|
String? sessionID;
|
||||||
|
|
||||||
String platform;
|
String? platform;
|
||||||
DateTime userFirstTouchTimestamp;
|
DateTime? userFirstTouchTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Device {
|
class Device {
|
||||||
String category; // mobile
|
String? category; // mobile
|
||||||
String mobileBrandName;
|
String? mobileBrandName;
|
||||||
String mobileModelName;
|
String? mobileModelName;
|
||||||
String mobileOsHardwareModel;
|
String? mobileOsHardwareModel;
|
||||||
String operatingSystem;
|
String? operatingSystem;
|
||||||
String operatingSystemVersion;
|
String? operatingSystemVersion;
|
||||||
String vendorId;
|
String? vendorId;
|
||||||
String language;
|
String? language;
|
||||||
bool isLimitedAdTracking;
|
bool? isLimitedAdTracking;
|
||||||
int timeZoneOffsetSeconds;
|
int? timeZoneOffsetSeconds;
|
||||||
|
|
||||||
static Future<Device> build() async {
|
static Future<Device> build() async {
|
||||||
var device = Device();
|
var device = Device();
|
||||||
@ -69,10 +69,10 @@ class Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AppInfo {
|
class AppInfo {
|
||||||
String id;
|
String? id;
|
||||||
String version;
|
String? version;
|
||||||
String firebaseAppId;
|
String? firebaseAppId;
|
||||||
String installSource;
|
String? installSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user