Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
76cbbeb6
Unverified
Commit
76cbbeb6
authored
Jul 19, 2019
by
Zachary Anderson
Committed by
GitHub
Jul 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tool] Send the local time to analytics with screens and events (#36545)
parent
6830edd0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
23 deletions
+106
-23
usage.dart
packages/flutter_tools/lib/src/reporting/usage.dart
+44
-18
analytics_test.dart
...ages/flutter_tools/test/general.shard/analytics_test.dart
+62
-5
No files found.
packages/flutter_tools/lib/src/reporting/usage.dart
View file @
76cbbeb6
...
...
@@ -12,6 +12,7 @@ import '../base/context.dart';
import
'../base/file_system.dart'
;
import
'../base/os.dart'
;
import
'../base/platform.dart'
;
import
'../base/time.dart'
;
import
'../base/utils.dart'
;
import
'../features.dart'
;
import
'../globals.dart'
;
...
...
@@ -19,6 +20,9 @@ import '../version.dart';
const
String
_kFlutterUA
=
'UA-67589403-6'
;
// Attached to all `Usage.sendCommand` and `Usage.sendEvent`.
const
String
_kLocalTimeParameter
=
'cd33'
;
const
String
kSessionHostOsDetails
=
'cd1'
;
const
String
kSessionChannelName
=
'cd2'
;
...
...
@@ -59,7 +63,7 @@ const String reloadExceptionEmulator = 'cd29';
const
String
reloadExceptionFullRestart
=
'cd30'
;
const
String
enabledFlutterFeatures
=
'cd32'
;
// Next ID: cd3
3
// Next ID: cd3
4
Usage
get
flutterUsage
=>
Usage
.
instance
;
...
...
@@ -141,12 +145,16 @@ class Usage {
String
get
clientId
=>
_analytics
.
clientId
;
void
sendCommand
(
String
command
,
{
Map
<
String
,
String
>
parameters
})
{
if
(
suppressAnalytics
)
if
(
suppressAnalytics
)
{
return
;
}
parameters
??=
const
<
String
,
String
>{};
final
Map
<
String
,
String
>
paramsWithLocalTime
=
<
String
,
String
>{
...?
parameters
,
_kLocalTimeParameter:
systemClock
.
now
().
toString
(),
};
_analytics
.
sendScreenView
(
command
,
parameters:
param
eters
);
_analytics
.
sendScreenView
(
command
,
parameters:
param
sWithLocalTime
);
}
void
sendEvent
(
...
...
@@ -154,12 +162,16 @@ class Usage {
String
parameter
,
{
Map
<
String
,
String
>
parameters
,
})
{
if
(
suppressAnalytics
)
if
(
suppressAnalytics
)
{
return
;
}
parameters
??=
const
<
String
,
String
>{};
final
Map
<
String
,
String
>
paramsWithLocalTime
=
<
String
,
String
>{
...?
parameters
,
_kLocalTimeParameter:
systemClock
.
now
().
toString
(),
};
_analytics
.
sendEvent
(
category
,
parameter
,
parameters:
param
eters
);
_analytics
.
sendEvent
(
category
,
parameter
,
parameters:
param
sWithLocalTime
);
}
void
sendTiming
(
...
...
@@ -168,7 +180,9 @@ class Usage {
Duration
duration
,
{
String
label
,
})
{
if
(!
suppressAnalytics
)
{
if
(
suppressAnalytics
)
{
return
;
}
_analytics
.
sendTiming
(
variableName
,
duration
.
inMilliseconds
,
...
...
@@ -176,10 +190,11 @@ class Usage {
label:
label
,
);
}
}
void
sendException
(
dynamic
exception
)
{
if
(!
suppressAnalytics
)
if
(
suppressAnalytics
)
{
return
;
}
_analytics
.
sendException
(
exception
.
runtimeType
.
toString
());
}
...
...
@@ -199,8 +214,9 @@ class Usage {
void
printWelcome
()
{
// This gets called if it's the first run by the selected command, if any,
// and on exit, in case there was no command.
if
(
_printedWelcome
)
if
(
_printedWelcome
)
{
return
;
}
_printedWelcome
=
true
;
printStatus
(
''
);
...
...
@@ -239,7 +255,17 @@ class LogToFileAnalytics extends AnalyticsMock {
Future
<
void
>
sendScreenView
(
String
viewName
,
{
Map
<
String
,
String
>
parameters
})
{
parameters
??=
<
String
,
String
>{};
parameters
[
'viewName'
]
=
viewName
;
logFile
.
writeAsStringSync
(
'screenView
$parameters
\n
'
);
logFile
.
writeAsStringSync
(
'screenView
$parameters
\n
'
,
mode:
FileMode
.
append
);
return
Future
<
void
>.
value
(
null
);
}
@override
Future
<
void
>
sendEvent
(
String
category
,
String
action
,
{
String
label
,
int
value
,
Map
<
String
,
String
>
parameters
})
{
parameters
??=
<
String
,
String
>{};
parameters
[
'category'
]
=
category
;
parameters
[
'action'
]
=
action
;
logFile
.
writeAsStringSync
(
'event
$parameters
\n
'
,
mode:
FileMode
.
append
);
return
Future
<
void
>.
value
(
null
);
}
}
packages/flutter_tools/test/general.shard/analytics_test.dart
View file @
76cbbeb6
...
...
@@ -3,23 +3,26 @@
// found in the LICENSE file.
import
'package:args/command_runner.dart'
;
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/base/config.dart'
;
import
'package:flutter_tools/src/base/time.dart'
;
import
'package:flutter_tools/src/features.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/time.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/commands/build.dart'
;
import
'package:flutter_tools/src/commands/config.dart'
;
import
'package:flutter_tools/src/commands/doctor.dart'
;
import
'package:flutter_tools/src/doctor.dart'
;
import
'package:flutter_tools/src/
runner/flutter_command
.dart'
;
import
'package:flutter_tools/src/
features
.dart'
;
import
'package:flutter_tools/src/reporting/usage.dart'
;
import
'package:flutter_tools/src/runner/flutter_command.dart'
;
import
'package:flutter_tools/src/version.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:platform/platform.dart'
;
import
'../src/common.dart'
;
import
'../src/context.dart'
;
import
'../src/mocks.dart'
;
void
main
(
)
{
group
(
'analytics'
,
()
{
...
...
@@ -123,12 +126,16 @@ void main() {
});
group
(
'analytics with mocks'
,
()
{
MemoryFileSystem
memoryFileSystem
;
MockStdio
mockStdio
;
Usage
mockUsage
;
SystemClock
mockClock
;
Doctor
mockDoctor
;
List
<
int
>
mockTimes
;
setUp
(()
{
memoryFileSystem
=
MemoryFileSystem
();
mockStdio
=
MockStdio
();
mockUsage
=
MockUsage
();
when
(
mockUsage
.
isFirstRun
).
thenReturn
(
false
);
mockClock
=
MockClock
();
...
...
@@ -190,6 +197,56 @@ void main() {
},
overrides:
<
Type
,
Generator
>{
Usage:
()
=>
mockUsage
,
});
testUsingContext
(
'command sends localtime'
,
()
async
{
const
int
kMillis
=
1000
;
mockTimes
=
<
int
>[
kMillis
];
// Since FLUTTER_ANALYTICS_LOG_FILE is set in the environment, analytics
// will be written to a file.
final
Usage
usage
=
Usage
(
versionOverride:
'test'
);
usage
.
suppressAnalytics
=
false
;
usage
.
enabled
=
true
;
usage
.
sendCommand
(
'test'
);
final
String
log
=
fs
.
file
(
'analytics.log'
).
readAsStringSync
();
final
DateTime
dateTime
=
DateTime
.
fromMillisecondsSinceEpoch
(
kMillis
);
expect
(
log
.
contains
(
dateTime
.
toString
()),
isTrue
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
memoryFileSystem
,
SystemClock:
()
=>
mockClock
,
Platform:
()
=>
FakePlatform
(
environment:
<
String
,
String
>{
'FLUTTER_ANALYTICS_LOG_FILE'
:
'analytics.log'
,
},
),
Stdio:
()
=>
mockStdio
,
});
testUsingContext
(
'event sends localtime'
,
()
async
{
const
int
kMillis
=
1000
;
mockTimes
=
<
int
>[
kMillis
];
// Since FLUTTER_ANALYTICS_LOG_FILE is set in the environment, analytics
// will be written to a file.
final
Usage
usage
=
Usage
(
versionOverride:
'test'
);
usage
.
suppressAnalytics
=
false
;
usage
.
enabled
=
true
;
usage
.
sendEvent
(
'test'
,
'test'
);
final
String
log
=
fs
.
file
(
'analytics.log'
).
readAsStringSync
();
final
DateTime
dateTime
=
DateTime
.
fromMillisecondsSinceEpoch
(
kMillis
);
expect
(
log
.
contains
(
dateTime
.
toString
()),
isTrue
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
memoryFileSystem
,
SystemClock:
()
=>
mockClock
,
Platform:
()
=>
FakePlatform
(
environment:
<
String
,
String
>{
'FLUTTER_ANALYTICS_LOG_FILE'
:
'analytics.log'
,
},
),
Stdio:
()
=>
mockStdio
,
});
});
group
(
'analytics bots'
,
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment