From d02b25097e742285818fd1f98045b673124e023e Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Wed, 10 Nov 2021 10:34:22 -0600 Subject: [PATCH] bugfix: only log search url on search route (#33) * feat: udpate search route string Signed-off-by: Patrick Erichsen * fix: only log search url Signed-off-by: Patrick Erichsen --- src/content/App.tsx | 8 ++++---- src/content/utils/airbnb.ts | 6 ++++++ src/utils/analytics.ts | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/content/App.tsx b/src/content/App.tsx index 9cf4a2b..ba50aa4 100644 --- a/src/content/App.tsx +++ b/src/content/App.tsx @@ -1,9 +1,9 @@ import { useState } from 'react'; import { useUrlChangeChrome } from './hooks/useUrlChangeChrome'; import { OffiePortals } from './components/OffiePortals'; -import { isOffiePage } from './utils'; +import { isOffiePage, isSearchUrl } from './utils'; import './App.css'; -import { logUrlChange } from '../utils'; +import { logSearchUrl } from '../utils'; export const App = (): JSX.Element | null => { const [isVisible, setIsVisible] = useState(false); @@ -19,8 +19,8 @@ export const App = (): JSX.Element | null => { /** * Only log URL changes if we are on the homes search page */ - if (newIsVisible) { - logUrlChange(newUrl); + if (newIsVisible && isSearchUrl(newUrl)) { + logSearchUrl(newUrl); } }); diff --git a/src/content/utils/airbnb.ts b/src/content/utils/airbnb.ts index 46affc6..2635b7c 100644 --- a/src/content/utils/airbnb.ts +++ b/src/content/utils/airbnb.ts @@ -274,6 +274,12 @@ export const getMappedSearchFilters = ( }, {}); }; +export const isSearchUrl = (url: string): boolean => { + const { pathname } = new URL(url); + + return pathname.includes(SEARCH_ROUTE); +}; + export const isOffiePage = (url: string): boolean => { const { pathname } = new URL(url); diff --git a/src/utils/analytics.ts b/src/utils/analytics.ts index 85810e5..f287fff 100644 --- a/src/utils/analytics.ts +++ b/src/utils/analytics.ts @@ -47,7 +47,7 @@ export const tryIdentifyUserFromUrlParam = (url: string): void => { } }; -export const logUrlChange = (url: string): void => { +export const logSearchUrl = (url: string): void => { const { search, pathname } = new URL(url); const decodedPathname = decodeURIComponent(pathname);