From 1ef0c85bc0d3e44bf0834480d6f1a3af8c12a252 Mon Sep 17 00:00:00 2001 From: Erica Wright Date: Fri, 13 Jul 2018 11:38:19 -0400 Subject: [PATCH] Bug 1471514 - Add top-of-funnel metrics for fxa. --- .../StartupOverlay/StartupOverlay.jsx | 37 ++++++++++++++++--- lib/PrefsFeed.jsm | 4 ++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/content-src/components/StartupOverlay/StartupOverlay.jsx b/content-src/components/StartupOverlay/StartupOverlay.jsx index a1d13aa55..d235d8f28 100644 --- a/content-src/components/StartupOverlay/StartupOverlay.jsx +++ b/content-src/components/StartupOverlay/StartupOverlay.jsx @@ -1,5 +1,5 @@ +import {actionCreators as ac, actionTypes as at} from "common/Actions.jsm"; import {FormattedMessage, injectIntl} from "react-intl"; -import {actionCreators as ac} from "common/Actions.jsm"; import {connect} from "react-redux"; import React from "react"; @@ -15,8 +15,29 @@ export class _StartupOverlay extends React.PureComponent { this.state = { emailInput: "", - overlayRemoved: false + overlayRemoved: false, + flowId: "", + flowBeginTime: 0 }; + this.didFetch = false; + } + + async componentWillUpdate() { + if (this.props.fxa_endpoint && !this.didFetch) { + try { + this.didFetch = true; + const response = await fetch(`${this.props.fxa_endpoint}/metrics-flow`); + if (response.status === 200) { + const {flowId, flowBeginTime} = await response.json(); + this.setState({flowId, flowBeginTime}); + } + } catch (error) { + this.props.dispatch(ac.OnlyToMain({type: at.TELEMETRY_UNDESIRED_EVENT, data: {value: "FXA_METRICS_ERROR"}})); + } + } + } + + componentDidMount() { this.initScene(); } @@ -71,8 +92,9 @@ export class _StartupOverlay extends React.PureComponent { return null; } - let termsLink = (); - let privacyLink = (); + let termsLink = (); + let privacyLink = (); + return (
@@ -85,13 +107,15 @@ export class _StartupOverlay extends React.PureComponent {

-
+ + + {this.props.intl.formatMessage({id: "firstrun_invalid_input"})}
@@ -113,4 +137,5 @@ export class _StartupOverlay extends React.PureComponent { } } -export const StartupOverlay = connect()(injectIntl(_StartupOverlay)); +const getState = state => ({fxa_endpoint: state.Prefs.values.fxa_endpoint}); +export const StartupOverlay = connect(getState)(injectIntl(_StartupOverlay)); diff --git a/lib/PrefsFeed.jsm b/lib/PrefsFeed.jsm index 8af500246..ed6d0014e 100644 --- a/lib/PrefsFeed.jsm +++ b/lib/PrefsFeed.jsm @@ -101,6 +101,10 @@ this.PrefsFeed = class PrefsFeed { values.isPrivateBrowsingEnabled = PrivateBrowsingUtils.enabled; values.platform = AppConstants.platform; + // Get the firefox accounts url for links and to send firstrun metrics to. + values.fxa_endpoint = Services.prefs.getStringPref( + "browser.newtabpage.activity-stream.fxaccounts.endpoint", "https://accounts.firefox.com"); + // Set the initial state of all prefs in redux this.store.dispatch(ac.BroadcastToContent({type: at.PREFS_INITIAL_VALUES, data: values}));