/
platform_interface_firebase_analytics.dart
146 lines (124 loc) 路 4.98 KB
/
platform_interface_firebase_analytics.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:firebase_core/firebase_core.dart';
import 'package:meta/meta.dart' show protected;
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import '../../firebase_analytics_platform_interface.dart';
/// The interface that implementations of `firebase_analytics` must extend.
///
/// Platform implementations should extend this class rather than implement it
/// as `firebase_analytics` does not consider newly added methods to be breaking
/// changes. Extending this class (using `extends`) ensures that the subclass
/// will get the default implementation, while platform implementations that
/// `implements` this interface will be broken by newly added
/// [FirebaseAnalyticsPlatform] methods.
abstract class FirebaseAnalyticsPlatform extends PlatformInterface {
/// The [FirebaseApp] this instance was initialized with.
@protected
FirebaseApp? appInstance;
/// Create an instance using [app]
FirebaseAnalyticsPlatform({this.appInstance}) : super(token: _token);
static final Object _token = Object();
static FirebaseAnalyticsPlatform? _instance;
/// Returns the [FirebaseApp] for the current instance.
FirebaseApp get app {
if (appInstance == null) {
return Firebase.app();
}
return appInstance!;
}
/// Create an instance using [app] using the existing implementation
factory FirebaseAnalyticsPlatform.instanceFor({required FirebaseApp app}) {
return FirebaseAnalyticsPlatform.instance.delegateFor(app: app);
}
/// The current default [FirebaseAnalyticsPlatform] instance.
///
/// It will always default to [MethodChannelFirebaseAnalytics]
/// if no other implementation was provided.
static FirebaseAnalyticsPlatform get instance {
return _instance ??= MethodChannelFirebaseAnalytics.instance;
}
/// Sets the [FirebaseAnalyticsPlatform.instance]
static set instance(FirebaseAnalyticsPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
/// Enables delegates to create new instances of themselves
FirebaseAnalyticsPlatform delegateFor({required FirebaseApp app}) {
throw UnimplementedError('delegateFor() is not implemented');
}
/// isSupported() informs web users whether
/// the browser supports Firebase.Analytics
Future<bool> isSupported() {
throw UnimplementedError('isSupported() is not implemented');
}
/// Logs the given event [name] with the given [parameters].
Future<void> logEvent({
required String name,
Map<String, Object?>? parameters,
AnalyticsCallOptions? callOptions,
}) {
throw UnimplementedError('logEvent() is not implemented');
}
/// Sets whether analytics collection is enabled for this app.
Future<void> setAnalyticsCollectionEnabled(bool enabled) {
throw UnimplementedError(
'setAnalyticsCollectionEnabled() is not implemented',
);
}
/// Sets the user id.
/// Setting a null [id] removes the user id.
/// [callOptions] are for web platform only.
Future<void> setUserId({
String? id,
AnalyticsCallOptions? callOptions,
}) {
throw UnimplementedError('setUserId() is not implemented');
}
/// Sets the current screen name, which specifies the current visual context
/// in your app.
///
/// Setting a null [screenName] clears the current screen name.
/// [callOptions] are for web platform only.
Future<void> setCurrentScreen({
String? screenName,
String? screenClassOverride,
AnalyticsCallOptions? callOptions,
}) {
throw UnimplementedError('setCurrentScreen() is not implemented');
}
/// Sets a user property to the given value.
/// Setting a null [value] removes the user property.
/// [callOptions] are for web platform only.
Future<void> setUserProperty({
required String name,
required String? value,
AnalyticsCallOptions? callOptions,
}) {
throw UnimplementedError('setUserProperty() is not implemented');
}
/// Clears all analytics data for this app from the device and resets the app
/// instance id.
Future<void> resetAnalyticsData() {
throw UnimplementedError('resetAnalyticsData() is not implemented');
}
/// Sets the duration of inactivity that terminates the current session.
Future<void> setSessionTimeoutDuration(Duration timeout) {
throw UnimplementedError('setSessionTimeoutDuration() is not implemented');
}
/// Sets the applicable end user consent state.
Future<void> setConsent({
bool? adStorageConsentGranted,
bool? analyticsStorageConsentGranted,
}) {
throw UnimplementedError('setConsent() is not implemented');
}
/// Adds parameters that will be set on every event logged from the SDK, including automatic ones.
Future<void> setDefaultEventParameters(
Map<String, Object?>? defaultParameters,
) {
throw UnimplementedError('setDefaultEventParameters() is not implemented');
}
}