Skip to content

Commit

Permalink
bugfix: only log search url on search route (#33)
Browse files Browse the repository at this point in the history
* feat: udpate search route string

Signed-off-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>

* fix: only log search url

Signed-off-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>
  • Loading branch information
Patrick-Erichsen authored Nov 10, 2021
1 parent df7598f commit d02b250
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/content/App.tsx
Original file line number Diff line number Diff line change
@@ -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<boolean>(false);
Expand All @@ -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);
}
});

Expand Down
6 changes: 6 additions & 0 deletions src/content/utils/airbnb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d02b250

Please # to comment.