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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
import React from "react";
import ReactDOM from "react-dom";
import { MultiStageAboutWelcome } from "./components/MultiStageAboutWelcome";
import { SimpleAboutWelcome } from "./components/SimpleAboutWelcome";
import { ReturnToAMO } from "./components/ReturnToAMO";
import {
AboutWelcomeUtils,
DEFAULT_WELCOME_CONTENT,
} from "../lib/aboutwelcome-utils";
class AboutWelcome extends React.PureComponent {
constructor(props) {
super(props);
this.state = { metricsFlowUri: null };
this.fetchFxAFlowUri = this.fetchFxAFlowUri.bind(this);
this.handleStartBtnClick = this.handleStartBtnClick.bind(this);
}
async fetchFxAFlowUri() {
this.setState({ metricsFlowUri: await window.AWGetFxAMetricsFlowURI() });
}
componentDidMount() {
this.fetchFxAFlowUri();
// Record impression with performance data after allowing the page to load
const recordImpression = domState => {
const { domComplete, domInteractive } = performance
.getEntriesByType("navigation")
.pop();
window.AWSendEventTelemetry({
event: "IMPRESSION",
event_context: {
domComplete,
domInteractive,
mountStart: performance.getEntriesByName("mount").pop().startTime,
domState,
source: this.props.UTMTerm,
page: "about:welcome",
},
message_id: this.props.messageId,
});
};
if (document.readyState === "complete") {
// Page might have already triggered a load event because it waited for async data,
// e.g., attribution, so the dom load timing could be of a empty content
// with domState in telemetry captured as 'complete'
recordImpression(document.readyState);
} else {
window.addEventListener("load", () => recordImpression("load"), {
once: true,
});
}
// Captures user has seen about:welcome by setting
// firstrun.didSeeAboutWelcome pref to true and capturing welcome UI unique messageId
window.AWSendToParent("SET_WELCOME_MESSAGE_SEEN", this.props.messageId);
}
handleStartBtnClick() {
AboutWelcomeUtils.handleUserAction(this.props.startButton.action);
const ping = {
event: "CLICK_BUTTON",
event_context: {
source: this.props.startButton.message_id,
page: "about:welcome",
},
message_id: this.props.messageId,
id: "ABOUT_WELCOME",
};
window.AWSendEventTelemetry(ping);
}
render() {
const { props } = this;
if (props.template === "simplified") {
return (
<SimpleAboutWelcome
metricsFlowUri={this.state.metricsFlowUri}
message_id={props.messageId}
utm_term={props.UTMTerm}
title={props.title}
subtitle={props.subtitle}
cards={props.cards}
startButton={props.startButton}
handleStartBtnClick={this.handleStartBtnClick}
/>
);
} else if (props.template === "return_to_amo") {
return (
<ReturnToAMO
message_id={props.messageId}
name={props.name}
url={props.url}
iconURL={props.iconURL}
/>
);
}
return (
<MultiStageAboutWelcome
screens={props.screens}
metricsFlowUri={this.state.metricsFlowUri}
message_id={props.messageId}
utm_term={props.UTMTerm}
/>
);
}
}
AboutWelcome.defaultProps = DEFAULT_WELCOME_CONTENT;
// Computes messageId and UTMTerm info used in telemetry
function ComputeTelemetryInfo(welcomeContent, experimentId, branchId) {
let messageId =
welcomeContent.template === "return_to_amo"
? "RTAMO_DEFAULT_WELCOME"
: "DEFAULT_ABOUTWELCOME";
let UTMTerm = "default";
if (welcomeContent.id) {
messageId = welcomeContent.id.toUpperCase();
}
if (experimentId && branchId) {
UTMTerm = `${experimentId}-${branchId}`.toLowerCase();
}
return {
messageId,
UTMTerm,
};
}
async function retrieveRenderContent() {
// Check for override content in pref browser.aboutwelcome.overrideContent
let aboutWelcomeProps = await window.AWGetWelcomeOverrideContent();
if (aboutWelcomeProps?.template) {
let { messageId, UTMTerm } = ComputeTelemetryInfo(aboutWelcomeProps);
return { aboutWelcomeProps, messageId, UTMTerm };
}
// Check for experiment and retrieve content
const { slug, branch } = await window.AWGetExperimentData();
aboutWelcomeProps = branch?.feature ? branch.feature.value : {};
// Check if there is any attribution data, this could take a while to await in series
// especially when there is an add-on that requires remote lookup
// Moving RTAMO as part of another screen of multistage is one option to fix the delay
// as it will allow the initial page to be fast while we fetch attribution data in parallel for a later screen.
const attribution = await window.AWGetAttributionData();
if (attribution?.template) {
aboutWelcomeProps = {
...aboutWelcomeProps,
// If part of an experiment, render experiment template
template: aboutWelcomeProps?.template
? aboutWelcomeProps.template
: attribution.template,
...attribution.extraProps,
};
}
let { messageId, UTMTerm } = ComputeTelemetryInfo(
aboutWelcomeProps,
slug,
branch && branch.slug
);
return { aboutWelcomeProps, messageId, UTMTerm };
}
async function mount() {
let { aboutWelcomeProps, messageId, UTMTerm } = await retrieveRenderContent();
ReactDOM.render(
<AboutWelcome
messageId={messageId}
UTMTerm={UTMTerm}
{...aboutWelcomeProps}
/>,
document.getElementById("root")
);
}
performance.mark("mount");
mount();
|