-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Search] SearchBar Analytics tracking (#8656)
* test capture search bar events Signed-off-by: Emma Indal <emmai@spotify.com> * capture search bar events Signed-off-by: Emma Indal <emmai@spotify.com> * only run onChange method if provided, otherwise set term Signed-off-by: Emma Indal <emmai@spotify.com> * changeset Signed-off-by: Emma Indal <emmai@spotify.com> * unconditionally call analytics API Signed-off-by: Emma Indal <emmai@spotify.com> * update changeset to be less specific to GA Signed-off-by: Emma Indal <emmai@spotify.com> * move analytics tracking to SearchBarBase Signed-off-by: Emma Indal <emmai@spotify.com> * add search to key events Signed-off-by: Emma Indal <emmai@spotify.com> * capture types as analytics context attribute, only for SearchBar Signed-off-by: Emma Indal <emmai@spotify.com> * move AnalyticsContext to within SearchContextProvider Signed-off-by: Emma Indal <emmai@spotify.com> * refactor search tracking out to its own component Signed-off-by: Emma Indal <emmai@spotify.com> * captures not only google analytics Signed-off-by: Emma Indal <emmai@spotify.com>
- Loading branch information
Showing
7 changed files
with
224 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@backstage/plugin-search': patch | ||
--- | ||
|
||
Captures the search term entered in the SearchBarBase as a `search` event. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
plugins/search/src/components/SearchTracker/SearchTracker.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2021 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
import { useAnalytics } from '@backstage/core-plugin-api'; | ||
import { useSearch } from '../SearchContext'; | ||
|
||
/** | ||
* Capture search event on term change. | ||
*/ | ||
export const TrackSearch = ({ children }: { children: React.ReactChild }) => { | ||
const analytics = useAnalytics(); | ||
const { term } = useSearch(); | ||
|
||
useEffect(() => { | ||
if (term) { | ||
// Capture analytics search event with search term provided as value | ||
analytics.captureEvent('search', term); | ||
} | ||
}, [analytics, term]); | ||
|
||
return <>{children}</>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright 2021 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
export { TrackSearch } from './SearchTracker'; |