4
4
5
5
const lazy = { } ;
6
6
ChromeUtils . defineESModuleGetters ( lazy , {
7
- PingCentre : "resource:///modules/PingCentre.sys.mjs" ,
8
7
TelemetryEnvironment : "resource://gre/modules/TelemetryEnvironment.sys.mjs" ,
9
8
pktApi : "chrome://pocket/content/pktApi.sys.mjs" ,
10
9
} ) ;
11
10
12
- // List of namespaces for the structured ingestion system.
13
- // They are defined in https://github.com/mozilla-services/mozilla-pipeline-schemas
14
- const STRUCTURED_INGESTION_NAMESPACE_AS = "activity-stream" ;
15
- const STRUCTURED_INGESTION_ENDPOINT_PREF =
16
- "browser.newtabpage.activity-stream.telemetry.structuredIngestion.endpoint" ;
17
- // This is the topic for telemetry pings, used inside PingCentre.
18
- const POCKET_TELEMETRY_TOPIC = "pocket" ;
19
11
const PREF_IMPRESSION_ID = "browser.newtabpage.activity-stream.impressionId" ;
20
12
21
- ChromeUtils . defineLazyGetter ( lazy , "pingCentre" , ( ) => {
22
- return new lazy . PingCentre ( { topic : POCKET_TELEMETRY_TOPIC } ) ;
23
- } ) ;
24
-
25
13
export var pktTelemetry = {
26
- get structuredIngestionEndpointBase ( ) {
27
- if ( ! this . _structuredIngestionEndpointBase ) {
28
- this . _structuredIngestionEndpointBase = Services . prefs . getStringPref (
29
- STRUCTURED_INGESTION_ENDPOINT_PREF ,
30
- ""
31
- ) ;
32
- }
33
- return this . _structuredIngestionEndpointBase ;
34
- } ,
35
-
36
14
get impressionId ( ) {
37
15
if ( ! this . _impressionId ) {
38
16
this . _impressionId = this . getOrCreateImpressionId ( ) ;
@@ -53,62 +31,13 @@ export var pktTelemetry = {
53
31
return impressionId ;
54
32
} ,
55
33
56
- /**
57
- * createPingPayload - Create a ping for an impression stats
58
- *
59
- * @param {ob } data The data object to be included in the ping.
60
- * @return {obj } A telemetry ping
61
- */
62
- createPingPayload ( data ) {
63
- // experiments, locale, version, and release_channel are provided by pingCentre.
64
- // model and events is provided in the data param.
65
- return {
66
- ...data ,
67
- impression_id : this . impressionId ,
68
- pocket_logged_in_status : lazy . pktApi . isUserLoggedIn ( ) ,
69
- profile_creation_date : this . _profileCreationDate ( ) ,
70
- } ;
71
- } ,
72
-
73
34
_profileCreationDate ( ) {
74
35
return (
75
36
lazy . TelemetryEnvironment . currentEnvironment . profile . resetDate ||
76
37
lazy . TelemetryEnvironment . currentEnvironment . profile . creationDate
77
38
) ;
78
39
} ,
79
40
80
- _generateUUID ( ) {
81
- return String ( Services . uuid . generateUUID ( ) ) ;
82
- } ,
83
-
84
- /**
85
- * Generates an endpoint for Structured Ingestion telemetry pipeline. Note that
86
- * Structured Ingestion requires a different endpoint for each ping. See more
87
- * details about endpoint schema at:
88
- * https://github.com/mozilla/gcp-ingestion/blob/master/docs/edge.md#postput-request
89
- */
90
- _generateStructuredIngestionEndpoint ( ) {
91
- const uuid = this . _generateUUID ( ) ;
92
- // Structured Ingestion does not support the UUID generated by gUUIDGenerator,
93
- // because it contains leading and trailing braces. Need to trim them first.
94
- const docID = uuid . slice ( 1 , - 1 ) ;
95
- const extension = `${ STRUCTURED_INGESTION_NAMESPACE_AS } /pocket-button/1/${ docID } ` ;
96
- return `${ this . structuredIngestionEndpointBase } /${ extension } ` ;
97
- } ,
98
-
99
- /**
100
- * sendStructuredIngestionEvent - Sent a ping for an impression stats
101
- *
102
- * @param {ob } eventObject The data object to be included in the ping.
103
- */
104
- sendStructuredIngestionEvent ( eventObject ) {
105
- lazy . pingCentre . sendStructuredIngestionPing (
106
- eventObject ,
107
- this . _generateStructuredIngestionEndpoint ( ) ,
108
- STRUCTURED_INGESTION_NAMESPACE_AS
109
- ) ;
110
- } ,
111
-
112
41
/**
113
42
* Records the provided data and common pocket-button data to Glean,
114
43
* then submits it all in a pocket-button ping.
0 commit comments