Skip to content

Commit

Permalink
Fix searched territory selected tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
smdsgn committed Nov 14, 2024
1 parent ccb11a7 commit ef4497f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
9 changes: 4 additions & 5 deletions assets/scripts/components/widgets/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, ChangeEvent, useState } from 'react';
import { useLocation } from 'react-router-dom';
import styled from 'styled-components';
import { useSearchTerritoryQuery } from '@services/api';
import useDebounce from '@hooks/useDebounce';
Expand All @@ -8,6 +7,7 @@ import Loader from '@components/ui/Loader';

interface SearchBarProps {
createUrl: string;
origin?: string;
}

export interface Territory {
Expand Down Expand Up @@ -122,7 +122,7 @@ const NoResultsMessage = styled.div`
text-align: center;
`;

const SearchBar: React.FC<SearchBarProps> = ({ createUrl }) => {
const SearchBar: React.FC<SearchBarProps> = ({ createUrl, origin }) => {
const [query, setQuery] = useState<string>('');
const [isFocused, setIsFocused] = useState<boolean>(false);
const [data, setData] = useState<Territory[] | undefined>(undefined);
Expand All @@ -133,7 +133,6 @@ const SearchBar: React.FC<SearchBarProps> = ({ createUrl }) => {
const { data: queryData, isFetching } = useSearchTerritoryQuery(debouncedQuery, {
skip: shouldQueryBeSkipped,
});
const location = useLocation();

useEffect(() => {
if (shouldQueryBeSkipped || isFetching) {
Expand Down Expand Up @@ -162,13 +161,13 @@ const SearchBar: React.FC<SearchBarProps> = ({ createUrl }) => {

setIsSubmitting(true);

if (location.pathname === "/" && window.trackEvent) {
if (origin === "home" && window.trackEvent) {
window.trackEvent(
'north_star_activation_funnel',
'search_territory',
'step_1_north_star_activation_funnel'
);
} else if (location.pathname === "/rapport-local" && window.trackEvent) {
} else if (origin === "rapport-local" && window.trackEvent) {
window.trackEvent(
'local_report_download_funnel',
'search_territory',
Expand Down
3 changes: 2 additions & 1 deletion assets/scripts/react-roots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const searchBar = document.getElementById('react-search-bar')
if (searchBar)
{
const createUrl = searchBar.dataset.createUrl;
const origin = searchBar.dataset.origin;
createRoot(searchBar).render(
<Provider store={store}>
<SearchBar createUrl={createUrl}/>
<SearchBar createUrl={createUrl} origin={origin} />
</Provider>,
)
}
Expand Down
2 changes: 1 addition & 1 deletion home/templates/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h1 class="fr-mb-0">Mon Diagnostic Artificialisation vous aide à analyser et ma
</div>
</div>
</div>
<div id="react-search-bar" data-create-url="{% url 'project:create' %}"></div>
<div id="react-search-bar" data-create-url="{% url 'project:create' %}" data-origin="home"></div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion home/templates/home/home_rapport_local.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1 class="fr-mb-0">Préparer le rapport triennal local de suivi de l’artifici
</div>
</div>
</div>
<div id="react-search-bar" data-create-url="{% url 'project:create' %}"></div>
<div id="react-search-bar" data-create-url="{% url 'project:create' %}" data-origin="rapport-local"></div>
</div>
</div>
</div>
Expand Down

0 comments on commit ef4497f

Please sign in to comment.