Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

feat(search-tracking): adding audience and mobile support #913

Merged
merged 1 commit into from
Jun 23, 2023
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
1 change: 1 addition & 0 deletions express/blocks/search-marquee/search-marquee.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function logSearch(form, url = 'https://main--express-website--adobe.hlx.page/ex
keyword: input.value,
locale: getLocale(window.location),
timestamp: Date.now(),
audience: document.body.dataset.device,
},
}),
});
Expand Down
19 changes: 19 additions & 0 deletions express/blocks/template-list/template-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,24 @@ function getRedirectUrl(tasks, topics, format, allTemplatesMetadata) {
}
}

function logSearch(form, url = 'https://main--express-website--adobe.hlx.page/express/search-terms-log') {
if (form) {
const input = form.querySelector('input');
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
data: {
keyword: input.value,
locale: getLocale(window.location),
timestamp: Date.now(),
audience: document.body.dataset.device,
},
}),
});
}
}

async function redirectSearch($searchBar, props) {
const placeholders = await fetchPlaceholders();
const taskMap = JSON.parse(placeholders['task-name-mapping']);
Expand Down Expand Up @@ -754,6 +772,7 @@ function initSearchFunction($toolBar, $stickySearchBarWrapper, generatedSearchBa

$searchForm.addEventListener('submit', async (e) => {
e.preventDefault();
logSearch(e.currentTarget);
await redirectSearch($searchBar, props);
});

Expand Down