Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

[search] adds segment tracking for queries and clicks #140

Merged
merged 6 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## Master

* Fixes z-index issue with `Search` modal and `TopbarSticker`. [#139](https://github.com/mapbox/dr-ui/pull/139)
* Fix z-index issue with `Search` modal and `TopbarSticker`. [#139](https://github.com/mapbox/dr-ui/pull/139)
* Add ability to filter `Search` results by current site or all docs. [#138](https://github.com/mapbox/dr-ui/pull/138)
* Add Segment events for tracking queries and clicks in the `Search` component. [#140](https://github.com/mapbox/dr-ui/pull/14)

## 0.14.0

Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
"react-stickynode": "^2.1.1",
"rehype-sectionize-headings": "^1.0.0-rc.1"
},
"optionalDependencies": {
"@mapbox/web-analytics": "^0.5.1"
},
"jest": {
"testRegex": ".*\\.test\\.js$"
}
Expand Down
3 changes: 3 additions & 0 deletions src/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"@mapbox/eslint-config-mapbox/promise",
"prettier"
],
"globals": {
"analytics": true
},
"rules": {
"prefer-const": "off",
"react/no-deprecated": "off",
Expand Down
13 changes: 13 additions & 0 deletions src/components/search/search-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,25 @@ class SearchBox extends React.Component {
id={this.props.inputId}
inputValue={this.props.searchTerm}
onChange={selection => {
// track click
if (window && window.analytics) {
analytics.track('Searched docs', {
query: this.props.searchTerm,
clicked: selection.url.raw
});
}
this.props.trackClickThrough(selection.id.raw); // track selection click through
window.open(selection.url.raw, '_self'); // open selection in current window
}}
onInputValueChange={newValue => {
if (props.searchTerm === newValue) return;
props.setSearchTerm(newValue, { debounce: 300 });
// track query
if (window && window.analytics) {
analytics.track('Searched docs', {
query: newValue
});
}
}}
itemToString={() => props.searchTerm}
>
Expand Down
7 changes: 7 additions & 0 deletions src/test-cases-app/test-cases-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestKitchen from '@mapbox/react-test-kitchen';
import componentIndex from './component-index'; // eslint-disable-line
import '@mapbox/web-analytics'; // eslint-disable-line

class App extends React.Component {
componentDidMount() {
if (window && window.initializeMapboxAnalytics) {
window.initializeMapboxAnalytics();
}
}

render() {
return <ReactTestKitchen componentIndex={componentIndex} />;
}
Expand Down