Bug 1514732 - Create a telemetry ping for search hand-off (#4662)

This commit is contained in:
ricky rosario 2019-01-16 12:50:29 -05:00 коммит произвёл GitHub
Родитель 51e8180252
Коммит 31ef3d1eca
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 38 добавлений и 7 удалений

Просмотреть файл

@ -41,8 +41,7 @@ export class _Search extends React.PureComponent {
const hiddenFocus = !isKeyboardClick;
this.props.dispatch(ac.OnlyToMain({type: at.HANDOFF_SEARCH_TO_AWESOMEBAR, data: {hiddenFocus}}));
this.props.dispatch({type: at.FOCUS_SEARCH});
// TODO: Send a telemetry ping. BUG 1514732
this.props.dispatch(ac.UserEvent({event: "SEARCH_HANDOFF"}));
}
onSearchHandoffKeyDown(event) {
@ -50,8 +49,7 @@ export class _Search extends React.PureComponent {
// We only care about key strokes that will produce a character.
const text = event.key;
this.props.dispatch(ac.OnlyToMain({type: at.HANDOFF_SEARCH_TO_AWESOMEBAR, data: {text}}));
// TODO: Send a telemetry ping. BUG 1514732
this.props.dispatch(ac.UserEvent({event: "SEARCH_HANDOFF"}));
}
}
@ -65,8 +63,7 @@ export class _Search extends React.PureComponent {
event.preventDefault();
const text = event.clipboardData.getData("Text");
this.props.dispatch(ac.OnlyToMain({type: at.HANDOFF_SEARCH_TO_AWESOMEBAR, data: {text}}));
// TODO: Send a telemetry ping. BUG 1514732
this.props.dispatch(ac.UserEvent({event: "SEARCH_HANDOFF"}));
}
componentWillMount() {

Просмотреть файл

@ -66,7 +66,7 @@ A user event ping includes some basic metadata (tab id, addon version, etc.) as
```js
{
// This indicates the type of interaction
  "event": ["CLICK", "SEARCH", "BLOCK", "DELETE", "OPEN_NEW_WINDOW", "OPEN_PRIVATE_WINDOW", "BOOKMARK_DELETE", "BOOKMARK_ADD", "OPEN_NEWTAB_PREFS", "CLOSE_NEWTAB_PREFS"],
  "event": ["CLICK", "SEARCH", "BLOCK", "DELETE", "OPEN_NEW_WINDOW", "OPEN_PRIVATE_WINDOW", "BOOKMARK_DELETE", "BOOKMARK_ADD", "OPEN_NEWTAB_PREFS", "CLOSE_NEWTAB_PREFS", "SEARCH_HANDOFF"],
// Optional field indicating the UI component type
"source": "TOP_SITES",
@ -106,6 +106,23 @@ A user event ping includes some basic metadata (tab id, addon version, etc.) as
}
```
#### Performing a search handoff
```js
{
  "event": "SEARCH_HANDOFF",
// Basic metadata
"action": "activity_stream_event",
"page": ["about:newtab" | "about:home" | "about:welcome" | "unknown"],
  "client_id": "26288a14-5cc4-d14f-ae0a-bb01ef45be9c",
"session_id": "005deed0-e3e4-4c02-a041-17405fd703f6",
  "addon_version": "20180710100040",
  "locale": "en-US",
"user_prefs": 7
}
```
#### Clicking a top site item
```js

Просмотреть файл

@ -70,6 +70,7 @@ export const UserEventAction = Joi.object().keys({
event: Joi.valid([
"CLICK",
"SEARCH",
"SEARCH_HANDOFF",
"BLOCK",
"DELETE",
"DELETE_CONFIRM",

Просмотреть файл

@ -84,33 +84,45 @@ describe("<Search>", () => {
const dispatch = sinon.spy();
const wrapper = shallowWithIntl(<Search {...DEFAULT_PROPS} handoffEnabled={true} dispatch={dispatch} />);
wrapper.find(".search-handoff-button").simulate("click", {clientX: 101, clientY: 102});
assert.calledThrice(dispatch);
assert.calledWith(dispatch, {
data: {hiddenFocus: true},
meta: {from: "ActivityStream:Content", skipLocal: true, to: "ActivityStream:Main"},
type: "HANDOFF_SEARCH_TO_AWESOMEBAR",
});
assert.calledWith(dispatch, {type: "FOCUS_SEARCH"});
const [action] = dispatch.thirdCall.args;
assert.isUserEventAction(action);
assert.propertyVal(action.data, "event", "SEARCH_HANDOFF");
});
it("should hand-off search when button is clicked with keyboard", () => {
const dispatch = sinon.spy();
const wrapper = shallowWithIntl(<Search {...DEFAULT_PROPS} handoffEnabled={true} dispatch={dispatch} />);
wrapper.find(".search-handoff-button").simulate("click", {clientX: 0, clientY: 0});
assert.calledThrice(dispatch);
assert.calledWith(dispatch, {
data: {hiddenFocus: false},
meta: {from: "ActivityStream:Content", skipLocal: true, to: "ActivityStream:Main"},
type: "HANDOFF_SEARCH_TO_AWESOMEBAR",
});
assert.calledWith(dispatch, {type: "FOCUS_SEARCH"});
const [action] = dispatch.thirdCall.args;
assert.isUserEventAction(action);
assert.propertyVal(action.data, "event", "SEARCH_HANDOFF");
});
it("should hand-off search when user types", () => {
const dispatch = sinon.spy();
const wrapper = shallowWithIntl(<Search {...DEFAULT_PROPS} handoffEnabled={true} dispatch={dispatch} />);
wrapper.find(".search-handoff-button").simulate("keydown", {key: "f"});
assert.calledTwice(dispatch);
assert.calledWith(dispatch, {
data: {text: "f"},
meta: {from: "ActivityStream:Content", skipLocal: true, to: "ActivityStream:Main"},
type: "HANDOFF_SEARCH_TO_AWESOMEBAR",
});
const [action] = dispatch.secondCall.args;
assert.isUserEventAction(action);
assert.propertyVal(action.data, "event", "SEARCH_HANDOFF");
});
it("should NOT hand-off search when user types with with ctrl pressed", () => {
const dispatch = sinon.spy();
@ -140,11 +152,15 @@ describe("<Search>", () => {
},
preventDefault: () => {},
});
assert.calledTwice(dispatch);
assert.calledWith(dispatch, {
data: {text: "some copied text"},
meta: {from: "ActivityStream:Content", skipLocal: true, to: "ActivityStream:Main"},
type: "HANDOFF_SEARCH_TO_AWESOMEBAR",
});
const [action] = dispatch.secondCall.args;
assert.isUserEventAction(action);
assert.propertyVal(action.data, "event", "SEARCH_HANDOFF");
});
});
});